diff options
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 14 | ||||
| -rw-r--r-- | indoteknik_custom/models/airway_bill_manifest.py | 11 |
2 files changed, 20 insertions, 5 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 1ad1ff51..ecc6c771 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -1,5 +1,6 @@ from .. import controller from odoo import http +from datetime import datetime, timedelta from odoo.http import request import json @@ -389,6 +390,17 @@ class SaleOrder(controller.Controller): data = airway_bill.decode_response() delivery_order = airway_bill.do_id result = data['rajaongkir']['result'] + + manifests_data = [] + for manifest in airway_bill.manifest_ids: + manifest_data = { + 'code': manifest.code, + 'description': manifest.description, + 'datetime': datetime.strftime(manifest.datetime, '%Y-%m-%d %H:%M:%S'), + 'city': manifest.city, + } + manifests_data.append(manifest_data) + airways.append({ 'delivery_order': { 'name': delivery_order.name, @@ -399,7 +411,7 @@ class SaleOrder(controller.Controller): 'delivered': result['delivered'], 'waybill_number': result['summary']['waybill_number'], 'delivery_status': result['delivery_status'], - 'manifests': result['manifest'] + 'manifests': manifests_data }) response = {'airways': airways} diff --git a/indoteknik_custom/models/airway_bill_manifest.py b/indoteknik_custom/models/airway_bill_manifest.py index a606c2be..2da60f27 100644 --- a/indoteknik_custom/models/airway_bill_manifest.py +++ b/indoteknik_custom/models/airway_bill_manifest.py @@ -5,7 +5,7 @@ _logger = logging.getLogger(__name__) class AirwayBillManifest(models.Model): _name = 'airway.bill.manifest' - _description = 'Airway B ill Line' + _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) @@ -19,7 +19,10 @@ class AirwayBillManifest(models.Model): try: history = waybill.decode_response() manifests = history['rajaongkir']['result']['manifest'] or [] - for manifest in manifests: + + 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'] @@ -29,8 +32,8 @@ class AirwayBillManifest(models.Model): 'waybill_id': waybill.id, 'code': code, 'description': description, - 'datetime': date+' '+time, + 'datetime': date + ' ' + time, 'city': city, }) except: - return
\ No newline at end of file + return |
