summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-08-03 11:31:33 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-08-03 11:31:33 +0700
commit4a670f1f85848ef46c605fd67ff4e3d305571522 (patch)
tree3a6cb02b6027d6b58c4c3d87e5a64949d4c6a840
parente62baea09db91741d84a2e62c5ab1db7d15cb8c2 (diff)
Fix fetch airway bill when read API response
-rw-r--r--indoteknik_custom/models/airway_bill.py10
-rw-r--r--indoteknik_custom/models/airway_bill_manifest.py33
2 files changed, 25 insertions, 18 deletions
diff --git a/indoteknik_custom/models/airway_bill.py b/indoteknik_custom/models/airway_bill.py
index 463272b4..37d2b671 100644
--- a/indoteknik_custom/models/airway_bill.py
+++ b/indoteknik_custom/models/airway_bill.py
@@ -41,11 +41,11 @@ class AirwayBill(models.Model):
self.ensure_one()
return self._json_decode(self.response)
- def _fetch(self):
+ def _fetch(self, days_before=30):
# jne, pos, tiki, wahana, jnt, rpx, sap, sicepat, jet, dse, dan first
carrier_ids = [51, 53, 54, 7, 57, 55, 59, 59, 27, 60, 62, 64]
- delta_time = datetime.now() - timedelta(days=30) # Last 30 days
+ delta_time = datetime.now() - timedelta(days=days_before) # Last 30 days
delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
query = [
'|',
@@ -61,7 +61,10 @@ class AirwayBill(models.Model):
history = self._get_waybill_history(out.delivery_tracking_no, rajaongkir.name)
if not history:
continue
- delivered = history['rajaongkir']['result']['delivered']
+ try:
+ delivered = history['rajaongkir']['result']['delivered']
+ except:
+ delivered = False
values = {
'do_id': out.id,
'so_id': out.sale_id.id,
@@ -108,6 +111,7 @@ class AirwayBill(models.Model):
elif response.get('rajaongkir', {}):
raja_ongkir = response.get('rajaongkir', {})
result = raja_ongkir.get('result', {})
+ result = result or {} # Change to empty dict when result is None
return result.get(key)
def _compute_way_bill(self, airway, key, attribute):
diff --git a/indoteknik_custom/models/airway_bill_manifest.py b/indoteknik_custom/models/airway_bill_manifest.py
index 2e16be2c..a606c2be 100644
--- a/indoteknik_custom/models/airway_bill_manifest.py
+++ b/indoteknik_custom/models/airway_bill_manifest.py
@@ -16,18 +16,21 @@ class AirwayBillManifest(models.Model):
def generate_airway_bill_line(self, waybill):
- history = waybill.decode_response()
- manifests = history['rajaongkir']['result']['manifest'] or []
- for manifest in manifests:
- code = manifest['manifest_code']
- description = manifest['manifest_description']
- date = manifest['manifest_date']
- time = manifest['manifest_time']
- city = manifest['city_name']
- self.create({
- 'waybill_id': waybill.id,
- 'code': code,
- 'description': description,
- 'datetime': date+' '+time,
- 'city': city,
- }) \ No newline at end of file
+ try:
+ history = waybill.decode_response()
+ manifests = history['rajaongkir']['result']['manifest'] or []
+ for manifest in manifests:
+ code = manifest['manifest_code']
+ description = manifest['manifest_description']
+ date = manifest['manifest_date']
+ time = manifest['manifest_time']
+ city = manifest['city_name']
+ self.create({
+ 'waybill_id': waybill.id,
+ 'code': code,
+ 'description': description,
+ 'datetime': date+' '+time,
+ 'city': city,
+ })
+ except:
+ return \ No newline at end of file