From df75d9b70f8eb834b005865a334774fc1a26ea65 Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Tue, 14 Feb 2023 08:48:23 +0100 Subject: [PATCH] fixup! fixup! Fix stock_release_channel_auto_release backward port to 14 --- .../models/stock_picking.py | 14 ++++++-------- .../tests/test_reservation.py | 18 +++++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/stock_available_to_promise_release/models/stock_picking.py b/stock_available_to_promise_release/models/stock_picking.py index 5c36deb1f48..e2d9bd53b56 100644 --- a/stock_available_to_promise_release/models/stock_picking.py +++ b/stock_available_to_promise_release/models/stock_picking.py @@ -33,14 +33,14 @@ class StockPicking(models.Model): set_printed_at_release = fields.Boolean(compute="_compute_set_printed_at_release") - @api.depends("move_ids") + @api.depends("move_lines") def _compute_set_printed_at_release(self): for picking in self: picking.set_printed_at_release = not ( - any(picking.move_ids.mapped("rule_id.no_backorder_at_release")) + any(picking.move_lines.mapped("rule_id.no_backorder_at_release")) ) - @api.depends("move_ids.need_release") + @api.depends("move_lines.need_release") def _compute_need_release(self): data = self.env["stock.move"].read_group( [("need_release", "=", True), ("picking_id", "in", self.ids)], @@ -161,17 +161,15 @@ def _after_release_update_chain(self): self._after_release_set_last_release_date() self._after_release_set_expected_date() - def _after_release_set_printed(self): - self.filtered( - lambda p: not p.printed and p.set_printed_at_release - ).printed = True + def _after_release_set_last_release_date(self): + self.last_release_date = fields.Datetime.now() def _after_release_set_expected_date(self): prep_time = self.env.company.stock_release_max_prep_time new_expected_date = fields.Datetime.add( fields.Datetime.now(), minutes=prep_time ) - move_to_update = self.move_ids.filtered(lambda m: m.state == "assigned") + move_to_update = self.move_lines.filtered(lambda m: m.state == "assigned") move_to_update_ids = move_to_update.ids for origin_moves in move_to_update._get_chained_moves_iterator("move_dest_ids"): move_to_update_ids += origin_moves.ids diff --git a/stock_available_to_promise_release/tests/test_reservation.py b/stock_available_to_promise_release/tests/test_reservation.py index 786324a0844..4ad9b39450c 100644 --- a/stock_available_to_promise_release/tests/test_reservation.py +++ b/stock_available_to_promise_release/tests/test_reservation.py @@ -722,7 +722,7 @@ def test_defer_creation_no_backorder_partial_available(self): self.assertEqual(len(pickings), 1, "expect only the last out->customer") cust_picking = pickings - move_state = cust_picking.mapped("move_ids").mapped("state") + move_state = cust_picking.mapped("move_lines").mapped("state") self.assertTrue(len(move_state) == 1 and move_state[0] == "waiting") self.assertEqual(cust_picking.state, "waiting") self.assertRecordValues( @@ -757,11 +757,11 @@ def test_defer_creation_no_backorder_partial_available(self): # the released customer picking is not set to "printed" self.assertRecordValues(cust_picking, [{"printed": False}]) - self.assertRecordValues(out_picking.move_ids, [{"product_qty": 7.0}]) + self.assertRecordValues(out_picking.move_lines, [{"product_qty": 7.0}]) # the splite moves remains into the customer picking self.assertRecordValues( - cust_picking.move_ids, + cust_picking.move_lines, [ {"product_qty": 7.0, "state": "waiting"}, {"product_qty": 13.0, "state": "waiting"}, @@ -773,7 +773,7 @@ def test_defer_creation_no_backorder_partial_available(self): self.assertRecordValues(out_picking, [{"state": "done"}]) self.assertRecordValues(cust_picking, [{"state": "assigned"}]) self.assertRecordValues( - cust_picking.move_ids, + cust_picking.move_lines, [ { "state": "assigned", @@ -798,7 +798,7 @@ def test_defer_creation_no_backorder_partial_available(self): ) self.assertEqual(len(cust_backorder), 1) - self.env["stock.move"].invalidate_model( + self.env["stock.move"].invalidate_cache( fnames=[ "previous_promised_qty", "ordered_available_to_promise_uom_qty", @@ -810,7 +810,7 @@ def test_defer_creation_no_backorder_partial_available(self): cust_backorder.release_available_to_promise() self.assertEqual(len(self._pickings_in_group(cust_picking.group_id)), 3) - self.env["stock.move"].invalidate_model( + self.env["stock.move"].invalidate_cache( fnames=[ "previous_promised_qty", "ordered_available_to_promise_uom_qty", @@ -828,7 +828,7 @@ def test_defer_creation_no_backorder_partial_available(self): - out_picking ) self.assertRecordValues( - out_backorder.move_ids, + out_backorder.move_lines, [ { "state": "assigned", @@ -876,7 +876,7 @@ def test_defer_creation_no_backorder_not_available(self): backorder = cust_picking.backorder_ids self.assertFalse(backorder) self.assertRecordValues( - cust_picking.move_ids.sorted("id"), + cust_picking.move_lines.sorted("id"), [ # product 1 is partially available -> split { @@ -922,7 +922,7 @@ def test_defer_creation_no_backorder_not_available(self): ], ) self.assertRecordValues( - out_picking.move_ids, + out_picking.move_lines, [ {"product_qty": 10.0, "product_id": self.product1.id}, {"product_qty": 10.0, "product_id": self.product2.id},