summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-06-30 21:29:43 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-06-30 21:29:43 +0700
commit7df14abdd24cfaf92d92f155a51c0111e9425620 (patch)
treef7913fe51826219cc6fd4dadaf40ba879b6dda37
parentcbd20e11777185a98813141206a79d044e1f198e (diff)
get tracking history of airway bill
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/airway_bill.py63
-rw-r--r--indoteknik_custom/models/stock_picking.py1
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv3
4 files changed, 67 insertions, 1 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 3c6ce46c..2f0a230a 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -63,3 +63,4 @@ from . import procurement_monitoring_detail
from . import brand_vendor
from . import manufacturing
from . import requisition
+from . import airway_bill
diff --git a/indoteknik_custom/models/airway_bill.py b/indoteknik_custom/models/airway_bill.py
new file mode 100644
index 00000000..b81df5dd
--- /dev/null
+++ b/indoteknik_custom/models/airway_bill.py
@@ -0,0 +1,63 @@
+from odoo import models, api, fields
+from odoo.exceptions import UserError
+from datetime import datetime, timedelta
+import logging
+import requests
+import json
+
+_logger = logging.getLogger(__name__)
+
+_key = '7ac9883688da043b50cc32f0e3070bb6'
+_url = 'https://pro.rajaongkir.com/api/waybill'
+
+class AirwayBill(models.Model):
+ _name = 'airway.bill'
+ do_id = fields.Many2one('stock.picking', string='DO')
+ so_id = fields.Many2one('sale.order', string='SO')
+ number = fields.Char(string='Resi', help='Nomor Resi')
+ delivered = fields.Char(string='Delivered', help='terkirim atau belum / true or false')
+ response = fields.Char(string='Response', help='hasil history tracking dalam format json')
+
+ def _update_data_way_bill(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)
+
+ current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
+ delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S')
+ query = [
+ ('date_done', '>', delta_time),
+ ('delivery_tracking_no', '!=', False),
+ ('delivery_tracking_no', 'not ilike', '-'),
+ ('counter_way_bill', '<=', 7),
+ ('carrier_id.id', 'in', [51, 53, 54, 7, 57, 55, 59, 59, 27, 60, 62, 64]),
+ ]
+ outs = self.env['stock.picking'].search(query, order='id')
+ for out in outs:
+ rajaongkir = self.env['rajaongkir.kurir'].search([('delivery_carrier_id', '=', out.carrier_id.id)], limit=1)
+ history = self._get_waybill_history(out.delivery_tracking_no, rajaongkir.name)
+ delivered = json.loads(history)['rajaongkir']['result']['delivered']
+ values = {
+ 'do_id': out.id,
+ 'so_id': out.sale_id.id,
+ 'number': out.delivery_tracking_no,
+ 'delivered': delivered,
+ 'response': history,
+ }
+ self.create(values)
+ out.counter_way_bill = out.counter_way_bill + 1
+
+ def _get_waybill_history(self, way_bill_number=0, shipper=0):
+ headers = {
+ 'content-type': 'application/x-www-form-urlencoded',
+ 'key': _key,
+ }
+
+ data = {
+ 'waybill': way_bill_number,
+ 'courier': shipper,
+ }
+
+ response = requests.post(_url, headers=headers, data=data)
+ return response.text \ No newline at end of file
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index a14e71a3..99c41c02 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -68,6 +68,7 @@ class StockPicking(models.Model):
('hold', 'Hold by Sales'),
('not_paid', 'Customer belum bayar')
], string='Note', help='jika field ini diisi maka tidak akan dihitung ke lead time')
+ counter_way_bill = fields.Integer(string='Counter Tracking', default=0)
def action_create_invoice_from_mr(self):
"""Create the invoice associated to the PO.
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index 26e852f1..46ac157d 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -51,4 +51,5 @@ access_rajaongkir_kurir,access.rajaongkir.kurir,model_rajaongkir_kurir,,1,1,1,1
access_brand_vendor,access.brand.vendor,model_brand_vendor,,1,1,1,1
access_requisition,access.requisition,model_requisition,,1,1,1,1
access_requisition_line,access.requisition.line,model_requisition_line,,1,1,1,1
-access_requisition_purchase_match,access.requisition.purchase.match,model_requisition_purchase_match,,1,1,1,1 \ No newline at end of file
+access_requisition_purchase_match,access.requisition.purchase.match,model_requisition_purchase_match,,1,1,1,1
+access_airway_bill,access.airway.bill,model_airway_bill,,1,1,1,1 \ No newline at end of file