summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/airway_bill.py14
-rw-r--r--indoteknik_custom/models/airway_bill_manifest.py10
2 files changed, 10 insertions, 14 deletions
diff --git a/indoteknik_custom/models/airway_bill.py b/indoteknik_custom/models/airway_bill.py
index 7379049f..463272b4 100644
--- a/indoteknik_custom/models/airway_bill.py
+++ b/indoteknik_custom/models/airway_bill.py
@@ -41,21 +41,19 @@ class AirwayBill(models.Model):
self.ensure_one()
return self._json_decode(self.response)
- def _generate(self):
+ def _fetch(self):
# jne, pos, tiki, wahana, jnt, rpx, sap, sicepat, jet, dse, dan first
- # 51, 53, 54, 7, 57, 55, 59, 59, 27, 60, 62, 64
- current_time = datetime.now()
- delta_time = current_time - timedelta(days=30)
+ carrier_ids = [51, 53, 54, 7, 57, 55, 59, 59, 27, 60, 62, 64]
- current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
- delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ delta_time = datetime.now() - timedelta(days=30) # Last 30 days
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
query = [
'|',
('waybill_id.delivered', '=', False),
('date_done', '>', delta_time),
('delivery_tracking_no', '!=', False),
('delivery_tracking_no', 'not ilike', '-'),
- ('carrier_id.id', 'in', [51, 53, 54, 7, 57, 55, 59, 59, 27, 60, 62, 64]),
+ ('carrier_id', 'in', carrier_ids),
]
outs = self.env['stock.picking'].search(query, order='id')
for out in outs:
@@ -77,7 +75,7 @@ class AirwayBill(models.Model):
waybill.response = json.dumps(history, indent=2, ensure_ascii=False)
waybill.manifest_ids.unlink()
- self.env['airway.bill.manifest'].generate_airway_bill_line(history, waybill.id)
+ self.env['airway.bill.manifest'].generate_airway_bill_line(waybill)
def _get_waybill_history(self, way_bill_number=0, shipper=0):
headers = {
diff --git a/indoteknik_custom/models/airway_bill_manifest.py b/indoteknik_custom/models/airway_bill_manifest.py
index cba40b3d..2e16be2c 100644
--- a/indoteknik_custom/models/airway_bill_manifest.py
+++ b/indoteknik_custom/models/airway_bill_manifest.py
@@ -15,9 +15,9 @@ class AirwayBillManifest(models.Model):
city = fields.Char('City')
- def generate_airway_bill_line(self, history, waybill_id):
+ def generate_airway_bill_line(self, waybill):
+ history = waybill.decode_response()
manifests = history['rajaongkir']['result']['manifest'] or []
- count = 0
for manifest in manifests:
code = manifest['manifest_code']
description = manifest['manifest_description']
@@ -25,11 +25,9 @@ class AirwayBillManifest(models.Model):
time = manifest['manifest_time']
city = manifest['city_name']
self.create({
- 'waybill_id': waybill_id,
+ 'waybill_id': waybill.id,
'code': code,
'description': description,
'datetime': date+' '+time,
'city': city,
- })
- count += 1
- _logger.info("Airway Bill generated %s" % count) \ No newline at end of file
+ }) \ No newline at end of file