summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-01 09:07:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-01 09:07:55 +0700
commitf8ba3deeab30a5eee7ccfcbe9cf8a7e664d0bde7 (patch)
tree00bd61d4abac0c87f5405db6595aa4709f7f416a
parentcb81068b8b695eaf8de5c0ba6b0951bae436626e (diff)
parentb9f1f1a02e53b1b874d8cfe5a97f8400bc4f4cbc (diff)
Merge branch 'production' into iman/switch-account
# Conflicts: # indoteknik_api/controllers/api_v1/partner.py
-rw-r--r--indoteknik_api/controllers/api_v1/partner.py19
-rw-r--r--indoteknik_api/controllers/api_v1/user.py2
-rwxr-xr-xindoteknik_custom/models/sale_order.py84
-rw-r--r--indoteknik_custom/models/sale_order_line.py2
-rwxr-xr-xindoteknik_custom/views/product_template.xml2
5 files changed, 85 insertions, 24 deletions
diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py
index 47ad2554..d1a41739 100644
--- a/indoteknik_api/controllers/api_v1/partner.py
+++ b/indoteknik_api/controllers/api_v1/partner.py
@@ -72,6 +72,7 @@ class Partner(controller.Controller):
'district_id': ['number', 'alias:kecamatan_id'],
'sub_district_id': ['number', 'alias:kelurahan_id', 'exclude_if_null'],
'zip': ['required'],
+ 'alamat_lengkap_text': []
})
if not params['valid']:
@@ -117,7 +118,7 @@ class Partner(controller.Controller):
@controller.Controller.must_authorized()
def write_partner_by_id(self, **kw):
params = self.get_request_params(kw, {
- 'id': ['required', 'number'],
+ 'id': ['', 'number'],
'name': [],
'company_type_id': ['number'],
'industry_id': ['number'],
@@ -142,7 +143,6 @@ class Partner(controller.Controller):
partner = request.env[self._name].search([('id', '=', params['value']['id'])], limit=1)
user = request.env[self._name].search([('id', '=', id_user['value']['id_user'])], limit=1)
-
if not partner:
return self.response(code=404, description='Partner not found')
@@ -158,9 +158,20 @@ class Partner(controller.Controller):
params['value']['npwp'] = "00.000.000.0-000.000"
params_user['value']['npwp'] = "00.000.000.0-000.000"
- partner.write(params['value'])
- user.write(params_user['value'])
+ # Filter parameter yang memiliki nilai saja untuk partner
+ params_filtered = {k: v for k, v in params['value'].items() if v}
+
+ # Filter parameter yang memiliki nilai saja untuk user
+ params_user_filtered = {k: v for k, v in params_user['value'].items() if v}
+
+ # Update partner dan user hanya dengan parameter yang memiliki nilai
+ if params_filtered:
+ partner.write(params_filtered)
+
+ if params_user_filtered:
+ user.write(params_user_filtered)
+ # Return response dengan ID partner yang di-update
return self.response({
'id': partner.id
})
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index a4655417..b66e0f3c 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -123,7 +123,7 @@ class User(controller.Controller):
alamat_bisnis = kw.get('alamat_bisnis', False)
nama_wajib_pajak = kw.get('nama_wajib_pajak', False)
is_pkp = kw.get('is_pkp')
- type_acc = kw.get('type_acc', False)
+ type_acc = kw.get('type_acc', 'individu') or 'individu'
if not name or not email or not password:
return self.response(code=400, description='email, name, and password are required')
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index d0a34007..8f48e898 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -137,49 +137,100 @@ class SaleOrder(models.Model):
total_weight = 0
missing_weight_products = []
- # Menghitung total berat dari Sale Order Line
for line in self.order_line:
if line.weight:
- total_weight += line.weight * line.product_uom_qty
- line.product_id.weight = line.weight
+ total_weight += line.weight
else:
missing_weight_products.append(line.product_id.name)
- # Menampilkan pesan jika ada produk tanpa berat
- if missing_weight_products:
- self.message_post(body="Warning: Beberapa produk tidak memiliki berat: %s" % ', '.join(missing_weight_products))
-
if total_weight == 0:
raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.")
- # Panggil API Raja Ongkir untuk mendapatkan estimasi ongkir
- result = self._call_rajaongkir_api(total_weight)
+ # Mendapatkan city_id berdasarkan nama kota
+ origin_city_name = self.warehouse_id.partner_id.kota_id.name
+ destination_city_name = self.real_shipping_id.kota_id.name
+
+ origin_city_id = self._get_city_id_by_name(origin_city_name)
+ destination_city_id = self._get_city_id_by_name(destination_city_name)
+
+ if not origin_city_id or not destination_city_id:
+ raise UserError("Gagal mendapatkan ID kota asal atau tujuan.")
+
+ result = self._call_rajaongkir_api(total_weight, origin_city_id, destination_city_id)
if result:
estimated_cost = result['rajaongkir']['results'][0]['costs'][0]['cost'][0]['value']
- # Memasukkan hasil estimasi ke field delivery_amt
self.delivery_amt = estimated_cost
self.message_post(body=f"Estimasi Ongkos Kirim: {estimated_cost}")
else:
raise UserError("Gagal mendapatkan estimasi ongkir.")
- def _call_rajaongkir_api(self, total_weight):
+ def _call_rajaongkir_api(self, total_weight, origin_city_id, destination_city_id):
url = 'https://pro.rajaongkir.com/api/cost'
headers = {
'key': '7ac9883688da043b50cc32f0e3070bb6',
}
courier = self.carrier_id.name.lower()
- origin = self.partner_shipping_id.city_id.state_id.code
- destination = self.partner_shipping_id.city_id.state_id.code
+
data = {
- 'origin': origin, # Contoh ID kota asal (Yogyakarta)
- 'destination': destination, # Contoh ID kota tujuan (Jakarta)
- 'weight': int(total_weight * 1000), # Menggunakan berat dalam gram
+ 'origin': int(origin_city_id),
+ 'originType': 'city',
+ 'destination': int(destination_city_id),
+ 'destinationType': 'city',
+ 'weight': int(total_weight * 1000),
'courier': courier,
}
+
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
return response.json()
return None
+
+ def _normalize_city_name(self, city_name):
+ # Ubah nama kota menjadi huruf kecil
+ city_name = city_name.lower()
+
+ # Hilangkan prefiks "kabupaten" atau "kota" jika ada
+ if city_name.startswith('kabupaten'):
+ city_name = city_name.replace('kabupaten', '').strip()
+ elif city_name.startswith('kota'):
+ city_name = city_name.replace('kota', '').strip()
+
+ # Hilangkan spasi yang berlebihan
+ city_name = " ".join(city_name.split())
+
+ return city_name
+
+ def _get_city_id_by_name(self, city_name):
+ url = 'https://pro.rajaongkir.com/api/city'
+ headers = {
+ 'key': '7ac9883688da043b50cc32f0e3070bb6',
+ }
+
+ # Normalisasi nama kota sebelum melakukan pencarian
+ normalized_city_name = self._normalize_city_name(city_name)
+
+ response = requests.get(url, headers=headers)
+ if response.status_code == 200:
+ city_data = response.json()
+ for city in city_data['rajaongkir']['results']:
+ if city['city_name'].lower() == normalized_city_name:
+ return city['city_id']
+ return None
+
+ def _get_subdistrict_id_by_name(self, city_id, subdistrict_name):
+ url = f'https://pro.rajaongkir.com/api/subdistrict?city={city_id}'
+ headers = {
+ 'key': '7ac9883688da043b50cc32f0e3070bb6',
+ }
+
+ response = requests.get(url, headers=headers)
+ if response.status_code == 200:
+ subdistrict_data = response.json()
+ for subdistrict in subdistrict_data['rajaongkir']['results']:
+ if subdistrict['subdistrict_name'].lower() == subdistrict_name.lower():
+ return subdistrict['subdistrict_id']
+ return None
+
def _compute_type_promotion(self):
for rec in self:
@@ -189,7 +240,6 @@ class SaleOrder(models.Model):
if line_program.promotion_type:
promotion_types.append(dict(line_program._fields['promotion_type'].selection).get(line_program.promotion_type))
- # Removing duplicates by converting to a set, then back to a list
rec.type_promotion = ', '.join(sorted(set(promotion_types)))
def _compute_purchase_delivery_amount(self):
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index 0ea6a2cc..d1dcd0af 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -245,7 +245,6 @@ class SaleOrderLine(models.Model):
# query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
price, taxes, vendor_id = self._get_purchase_price(line.product_id)
line.vendor_id = vendor_id
- line.weight = line.product_id.weight
line.tax_id = line.order_id.sales_tax_id
# price, taxes = line._get_valid_purchase_price(purchase_price)
line.purchase_price = price
@@ -259,6 +258,7 @@ class SaleOrderLine(models.Model):
('(' + attribute_values_str + ')' if attribute_values_str else '') + ' ' + \
(line.product_id.short_spesification if line.product_id.short_spesification else '')
line.name = line_name
+ line.weight = line.product_id.weight
def compute_delivery_amt_line(self):
for line in self:
diff --git a/indoteknik_custom/views/product_template.xml b/indoteknik_custom/views/product_template.xml
index b6155eea..a77b99de 100755
--- a/indoteknik_custom/views/product_template.xml
+++ b/indoteknik_custom/views/product_template.xml
@@ -22,7 +22,7 @@
<field name="last_update_solr" readonly="1" />
</field>
<field name="public_categ_ids" position="attributes">
- <attribute name="required">1</attribute>
+ <attribute name="required">0</attribute>
</field>
<field name="public_categ_ids" position="attributes">
<attribute name="options">{'no_create': True}</attribute>