From b8e027c3b52a2e117083c032b99bc497d48a86f8 Mon Sep 17 00:00:00 2001 From: Eugene Molotov Date: Mon, 1 Jul 2024 12:53:05 +0500 Subject: [PATCH] [MIG] pos_picking_delayed: Migration to 14.0 --- pos_picking_delayed/models/pos_order.py | 21 ++++++++++++-------- pos_picking_delayed/tests/test_module.py | 4 ++-- pos_picking_delayed/views/view_pos_order.xml | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pos_picking_delayed/models/pos_order.py b/pos_picking_delayed/models/pos_order.py index fdb0fc3db1..c8c6129625 100644 --- a/pos_picking_delayed/models/pos_order.py +++ b/pos_picking_delayed/models/pos_order.py @@ -20,23 +20,28 @@ def create_from_ui(self, orders, draft=False): for order_data in orders: session_id = order_data.get("data").get("pos_session_id") session = PosSession.browse(session_id) - order_data["data"][ - "has_picking_delayed" - ] = session.config_id.picking_creation_delayed + order_data["data"]["has_picking_delayed"] = ( + session.config_id.picking_creation_delayed + and not session.update_stock_at_closing + ) return super(PosOrder, self.with_context(create_from_ui=True)).create_from_ui( orders, draft=draft ) - def create_picking(self): + def _create_order_picking(self): if self.env.context.get("create_from_ui", False): orders = self.filtered(lambda x: not x.has_picking_delayed) delayed_orders = self.filtered(lambda x: x.has_picking_delayed) - delayed_orders.with_delay()._create_delayed_picking() + if delayed_orders: + delayed_orders.with_delay()._create_delayed_picking() else: orders = self - res = super(PosOrder, orders).create_picking() + + if not orders: + return + + super(PosOrder, orders)._create_order_picking() orders.write({"has_picking_delayed": False}) - return res @api.model def _order_fields(self, ui_order): @@ -48,5 +53,5 @@ def _order_fields(self, ui_order): def _create_delayed_picking(self): # make the function idempotent orders = self.filtered(lambda x: x.has_picking_delayed) - super(PosOrder, orders).create_picking() + super(PosOrder, orders)._create_order_picking() orders.write({"has_picking_delayed": False}) diff --git a/pos_picking_delayed/tests/test_module.py b/pos_picking_delayed/tests/test_module.py index 7cf8157a04..a736bf513f 100644 --- a/pos_picking_delayed/tests/test_module.py +++ b/pos_picking_delayed/tests/test_module.py @@ -46,7 +46,7 @@ def test_01_picking_delayed_enabled(self): order = self._create_order() self.assertEqual( - order.picking_id.id, + order.picking_ids.id, False, "Creating order via UI should not generate a picking if" " feature is enabled", @@ -64,7 +64,7 @@ def test_02_picking_delayed_disabled(self): order = self._create_order() - picking_id = order.picking_id.id + picking_id = order.picking_ids.id self.assertNotEqual( picking_id, False, diff --git a/pos_picking_delayed/views/view_pos_order.xml b/pos_picking_delayed/views/view_pos_order.xml index 8917373dbd..63b7858e8d 100644 --- a/pos_picking_delayed/views/view_pos_order.xml +++ b/pos_picking_delayed/views/view_pos_order.xml @@ -22,7 +22,7 @@ pos.order - +