1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
from odoo import models, fields
import logging
_logger = logging.getLogger(__name__)
class AirwayBillManifest(models.Model):
_name = 'airway.bill.manifest'
_description = 'Airway Bill Line'
_order = 'waybill_id, id'
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')
def generate_airway_bill_line(self, waybill):
try:
history = waybill.decode_response()
manifests = history['rajaongkir']['result']['manifest'] or []
sorted_manifests = sorted(manifests, key=lambda x: x['manifest_date'] + ' ' + x['manifest_time'], reverse=True)
for manifest in sorted_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
|