summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-07-06 13:22:18 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-07-06 13:22:18 +0700
commit5914d2028dd148d3b83bbd2d27d8580772742762 (patch)
tree8b71de9f287c22ba4c960028154b6aad34997103
parent3a008e900f7684843f7bc07109d484f77939e4c7 (diff)
Update airway bill function
-rw-r--r--indoteknik_custom/models/airway_bill.py28
-rw-r--r--indoteknik_custom/models/stock_picking.py2
2 files changed, 22 insertions, 8 deletions
diff --git a/indoteknik_custom/models/airway_bill.py b/indoteknik_custom/models/airway_bill.py
index b81df5dd..781e7cd1 100644
--- a/indoteknik_custom/models/airway_bill.py
+++ b/indoteknik_custom/models/airway_bill.py
@@ -1,5 +1,4 @@
-from odoo import models, api, fields
-from odoo.exceptions import UserError
+from odoo import models, fields
from datetime import datetime, timedelta
import logging
import requests
@@ -12,12 +11,18 @@ _url = 'https://pro.rajaongkir.com/api/waybill'
class AirwayBill(models.Model):
_name = 'airway.bill'
+ _rec_name = 'number'
+
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')
+ delivered = fields.Boolean(string='Delivered', help='terkirim atau belum / true or false')
response = fields.Char(string='Response', help='hasil history tracking dalam format json')
+ def decode_response(self):
+ self.ensure_one()
+ return self._json_decode(self.response)
+
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
@@ -27,17 +32,20 @@ class AirwayBill(models.Model):
current_time = current_time.strftime('%Y-%m-%d %H:%M:%S')
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', '-'),
- ('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']
+ if not history:
+ continue
+ delivered = history['rajaongkir']['result']['delivered']
values = {
'do_id': out.id,
'so_id': out.sale_id.id,
@@ -46,7 +54,6 @@ class AirwayBill(models.Model):
'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 = {
@@ -60,4 +67,11 @@ class AirwayBill(models.Model):
}
response = requests.post(_url, headers=headers, data=data)
- return response.text \ No newline at end of file
+ return self._json_decode(response.text)
+
+ def _json_decode(self, content):
+ try:
+ response = json.loads(content)
+ return response
+ except:
+ return False \ No newline at end of file
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 99c41c02..724b483b 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -68,7 +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)
+ waybill_id = fields.One2many(comodel_name='airway.bill', inverse_name='do_id', string='Airway Bill')
def action_create_invoice_from_mr(self):
"""Create the invoice associated to the PO.