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