summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-07-01 17:32:02 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-07-01 17:32:02 +0700
commit84a038cff26c28bd714fd6744f48c2b0e91cf347 (patch)
tree16c2788b39a3ad2426cb7c12f53146e67fed073e
parent9677d61248b4399239c6e0eccac57a6f945ec58c (diff)
(andri) fix API destination
-rwxr-xr-xindoteknik_custom/models/sale_order.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index bc830e2b..4b4e06cd 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -847,8 +847,9 @@ class SaleOrder(models.Model):
kecamatan_name = self.real_shipping_id.kecamatan_id.name
kota_name = self.real_shipping_id.kota_id.name
+ kelurahan_name = self.real_shipping_id.kelurahan_id.name
- destination_subsdistrict_id = self._get_subdistrict_id_from_komerce(kecamatan_name, kota_name)
+ destination_subsdistrict_id = self._get_subdistrict_id_from_komerce(kecamatan_name, kota_name, kelurahan_name)
# destination_subsdistrict_id = self.real_shipping_id.kecamatan_id.rajaongkir_id
if not destination_subsdistrict_id:
@@ -1264,15 +1265,20 @@ class SaleOrder(models.Model):
# return subdistrict['subdistrict_id']
# return None
- def _get_subdistrict_id_from_komerce(self, kecamatan_name, kota_name):
+ def _get_subdistrict_id_from_komerce(self, kecamatan_name, kota_name, kelurahan_name=None):
url = 'https://rajaongkir.komerce.id/api/v1/destination/domestic-destination'
headers = {
'key': '9b1310f644056d84d60b0af6bb21611a',
}
- search = f"{kecamatan_name} {kota_name}"
+
+ if kelurahan_name:
+ search = f"{kelurahan_name} {kecamatan_name} {kota_name}"
+ else:
+ search = f"{kecamatan_name} {kota_name}"
+
params = {
'search': search,
- 'limit': 5
+ 'limit': 10
}
try:
@@ -1283,14 +1289,20 @@ class SaleOrder(models.Model):
_logger.info(f"[Komerce] Response: {data}")
normalized_kota = self._normalize_city_name(kota_name)
+
for item in data:
+ match_kelurahan = (
+ not kelurahan_name or
+ item.get('subdistrict_name', '').lower() == kelurahan_name.lower()
+ )
if (
- item.get('subdistrict_name', '').lower() == kecamatan_name.lower() and
+ match_kelurahan and
+ item.get('district_name', '').lower() == kecamatan_name.lower() and
item.get('city_name', '').lower() == normalized_kota
):
return item.get('id')
- _logger.warning(f"[Komerce] No match for '{kecamatan_name}' in city '{kota_name}'")
+ _logger.warning(f"[Komerce] No match for '{kecamatan_name}' in city '{kota_name}' with kelurahan '{kelurahan_name}'")
else:
_logger.error(f"[Komerce] HTTP Error {response.status_code}: {response.text}")
except Exception as e: