Skip to content

Commit

Permalink
[MIG] pos_picking_delayed: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 committed Jul 5, 2024
1 parent 32f711f commit c3fd300
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
21 changes: 13 additions & 8 deletions pos_picking_delayed/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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})
5 changes: 3 additions & 2 deletions pos_picking_delayed/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def setUp(self):
"currency_id": self.currency.id,
}
)
self.pos_config.company_id.point_of_sale_update_stock_quantities = "real"

def test_01_picking_delayed_enabled(self):
# Enable feature
Expand All @@ -46,7 +47,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",
Expand All @@ -64,7 +65,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,
Expand Down
2 changes: 1 addition & 1 deletion pos_picking_delayed/views/view_pos_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<field name="model">pos.order</field>
<field name="inherit_id" ref="point_of_sale.view_pos_pos_form" />
<field name="arch" type="xml">
<field name="picking_id" position="after">
<field name="pos_reference" position="after">
<field name="has_picking_delayed" />
</field>
</field>
Expand Down

0 comments on commit c3fd300

Please sign in to comment.