From 89ff021709e23d2adefd08298c49be8a7eccf21a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 30 May 2024 16:23:26 +0700 Subject: add api for complete delivery order --- fixco_api/controllers/api_v1/sale.py | 38 +++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'fixco_api') diff --git a/fixco_api/controllers/api_v1/sale.py b/fixco_api/controllers/api_v1/sale.py index e2e9bdc..7096ccb 100644 --- a/fixco_api/controllers/api_v1/sale.py +++ b/fixco_api/controllers/api_v1/sale.py @@ -60,7 +60,7 @@ class Sales(controller.Controller): @http.route(prefix + 'sale/update_shipper', auth='public', methods=['POST', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() - def cancel_sale_order(self, **kw): + def update_shipper_sale_order(self, **kw): sale_id = int(kw.get('id', '0')) ref = str(kw.get('ref', '0')) shipper = str(kw.get('shipper', '0')) @@ -148,3 +148,39 @@ class Sales(controller.Controller): return { 'status': 'success', 'message': sale_order.name } + + @http.route(prefix + 'do/confirm', auth='public', methods=['POST', 'OPTIONS'], csrf=False) + @controller.Controller.must_authorized() + def complete_delivery_order(self, **kw): + # stock_picking.action_assign + sale_id = int(kw.get('id', '0')) + ref = str(kw.get('ref', '0')) + if sale_id == 0 and ref == '0': + return self.response(code=500, description='Internal Server Error') + if sale_id > 0: + query = [('id', '=', sale_id)] + else: + query = [('client_order_ref', '=', ref)] + + sales = request.env['sale.order'].search(query) + data = [] + for sale in sales: + picking_ids = sale.picking_ids + reserved = validated = False + for picking in picking_ids: + reserved = picking.action_assign() + if reserved == True: + for line in picking.move_line_ids_without_package: + line.qty_done = line.product_uom_qty + validated = picking.button_validate() + data.append({ + 'id': sale.id, + 'name': sale.name, + 'ref': sale.client_order_ref, + 'reserved': reserved, + 'validated': str(validated) + }) + test = data + print(test) + return self.response(data) + -- cgit v1.2.3