diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-06 16:35:21 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-07-06 16:35:21 +0700 |
| commit | 444e0b38349a33c9bd007e262eb8cb7f4c39f61d (patch) | |
| tree | 36044bf07c06191d12586ed0808eae4ec1dc51b3 | |
| parent | 21ee3f19583c28c3df3785eda0e6ce4b4ef7e48d (diff) | |
add line to airway bill
| -rw-r--r-- | indoteknik_custom/models/airway_bill.py | 50 | ||||
| -rw-r--r-- | indoteknik_custom/models/airway_bill_manifest.py | 28 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | indoteknik_custom/views/airway_bill.xml | 20 |
4 files changed, 93 insertions, 8 deletions
diff --git a/indoteknik_custom/models/airway_bill.py b/indoteknik_custom/models/airway_bill.py index 781e7cd1..6da83af6 100644 --- a/indoteknik_custom/models/airway_bill.py +++ b/indoteknik_custom/models/airway_bill.py @@ -16,14 +16,34 @@ class AirwayBill(models.Model): do_id = fields.Many2one('stock.picking', string='DO') so_id = fields.Many2one('sale.order', string='SO') number = fields.Char(string='Resi', help='Nomor Resi') + manifest_ids = fields.One2many('airway.bill.manifest', 'waybill_id', string='Airway Bill Lines', auto_join=True) delivered = fields.Boolean(string='Delivered', help='terkirim atau belum / true or false') response = fields.Char(string='Response', help='hasil history tracking dalam format json') + way_bill_date = fields.Char(string='Way Bill Date', compute='_compute_way_bill_date') + way_bill_time = fields.Char(string='Way Bill Time') + weigth = fields.Char(string='Weigth') + origin = fields.Char(string='Origin') + destination = fields.Char(string='Destination') + shipper_name = fields.Char(string='Shipper Name') + shipper_address1 = fields.Char(string='Shipper Address 1') + shipper_address2 = fields.Char(string='Shipper Address 2') + shipper_address3 = fields.Char(string='Shipper Address 3') + shipper_city = fields.Char(string='Shipper City') + receiver_name = fields.Char(string='Receiver Name') + receiver_address1 = fields.Char(string='Receiver Address 1') + receiver_address2 = fields.Char(string='Receiver Address 2') + receiver_address3 = fields.Char(string='Receiver Address 3') + receiver_city = fields.Char(string='Receiver City') + status = fields.Char(string='Status') + pod_receiver = fields.Char(string='Pod Receiver') + pod_date = fields.Char(string='Pod Date') + pod_time = fields.Char(string='Pod Time') def decode_response(self): self.ensure_one() return self._json_decode(self.response) - def _update_data_way_bill(self): + def _update_data_way_bill(self, history): # 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() @@ -41,7 +61,7 @@ class AirwayBill(models.Model): ] 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) + rajaongkir = self.env['rajaongkir.kurir'].search([('delivery_carrier_id', '=', out.carrier_id.id)]) history = self._get_waybill_history(out.delivery_tracking_no, rajaongkir.name) if not history: continue @@ -53,7 +73,13 @@ class AirwayBill(models.Model): 'delivered': delivered, 'response': history, } - self.create(values) + waybill = out.waybill_id + if not waybill: + waybill = self.create(values) + + waybill.response = history + waybill.manifest_ids.unlink() + self.env['airway.bill.manifest'].generate_airway_bill_line(history, waybill.id) def _get_waybill_history(self, way_bill_number=0, shipper=0): headers = { @@ -74,4 +100,20 @@ class AirwayBill(models.Model): response = json.loads(content) return response except: - return False
\ No newline at end of file + return False + + def _get_history(self, key): + response = self.decode_response() + if not response: + return response + return self.decode_response()['raja_ongkir']['result'][key] + + def _compute_way_bill_date(self): + for airway in self: + details = airway._get_history('details') + if details: + airway.way_bill_date = details['waybill_date'] + else: + airway.way_bill_date = '-' + +
\ No newline at end of file diff --git a/indoteknik_custom/models/airway_bill_manifest.py b/indoteknik_custom/models/airway_bill_manifest.py index 29a76303..159f4b9a 100644 --- a/indoteknik_custom/models/airway_bill_manifest.py +++ b/indoteknik_custom/models/airway_bill_manifest.py @@ -1,11 +1,35 @@ from odoo import models, fields +import logging +_logger = logging.getLogger(__name__) class AirwayBillManifest(models.Model): _name = 'airway.bill.manifest' + _description = 'Airway B ill Line' + _order = 'waybill_id, id' - waybill_id = fields.Many2one('airway.bill') + waybill_id = fields.Many2one('airway.bill', string='Airway Ref', required=True, ondelete='cascade', index=True, copy=False) code = fields.Char('Code') description = fields.Char('Description') datetime = fields.Datetime('Datetime') - city = fields.Char('city')
\ No newline at end of file + city = fields.Char('City') + + + def generate_airway_bill_line(self, history, waybill_id): + manifests = history['rajaongkir']['result']['manifest'] + count = 0 + 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, + }) + count += 1 + _logger.info("Airway Bill generated %s" % count)
\ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 1df01563..24917d9e 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -54,4 +54,5 @@ 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 -access_airway_bill,access.airway.bill,model_airway_bill,,1,1,1,1
\ No newline at end of file +access_airway_bill,access.airway.bill,model_airway_bill,,1,1,1,1 +access_airway_bill_manifest,access.airway.bill.manifest,model_airway_bill_manifest,,1,1,1,1
\ No newline at end of file diff --git a/indoteknik_custom/views/airway_bill.xml b/indoteknik_custom/views/airway_bill.xml index 5f6e700a..99f80d7b 100644 --- a/indoteknik_custom/views/airway_bill.xml +++ b/indoteknik_custom/views/airway_bill.xml @@ -25,9 +25,27 @@ <field name="so_id" /> <field name="do_id" /> <field name="delivered" /> - <field name="response" /> </group> </group> + <notebook> + <page string="Airway Bill"> + <field name="manifest_ids" readonly='1'> + <tree> + <field name="code"/> + <field name="description"/> + <field name="datetime"/> + <field name="city"/> + </tree> + </field> + </page> + <page string="Details"> + <group> + <group> + <field name="way_bill_date"/> + </group> + </group> + </page> + </notebook> </sheet> </form> </field> |
