diff --git a/stock_move_actual_date/models/stock_move.py b/stock_move_actual_date/models/stock_move.py index 9f38936..281a57e 100644 --- a/stock_move_actual_date/models/stock_move.py +++ b/stock_move_actual_date/models/stock_move.py @@ -12,7 +12,8 @@ class StockMove(models.Model): store=True, ) actual_date_source = fields.Date( - help="Technical field to store the actual_date of the source document." + copy=False, + help="Technical field to store the actual_date of the source document.", ) def _get_timezone(self): @@ -74,7 +75,7 @@ def _read_group( ) def _action_done(self, cancel_backorder=False): - moves = super()._action_done(cancel_backorder) + moves = super()._action_done(cancel_backorder=cancel_backorder) # i.e. Inventory adjustments with actual date if self.env.context.get("force_period_date"): self.write({"actual_date_source": self.env.context["force_period_date"]}) diff --git a/stock_move_actual_date/models/stock_picking.py b/stock_move_actual_date/models/stock_picking.py index 95061e0..b695a7e 100644 --- a/stock_move_actual_date/models/stock_picking.py +++ b/stock_move_actual_date/models/stock_picking.py @@ -14,3 +14,8 @@ def _get_actual_date_update_triggers(self): def _get_stock_moves(self): self.ensure_one() return self.move_ids + + def _create_backorder(self, backorder_moves=None): + backorders = super()._create_backorder(backorder_moves=backorder_moves) + backorders.move_ids.filtered("actual_date_source").actual_date_source = False + return backorders diff --git a/stock_move_actual_date/tests/test_stock_move_actual_date.py b/stock_move_actual_date/tests/test_stock_move_actual_date.py index f15d877..13becb4 100644 --- a/stock_move_actual_date/tests/test_stock_move_actual_date.py +++ b/stock_move_actual_date/tests/test_stock_move_actual_date.py @@ -40,7 +40,7 @@ def setUpClass(cls): cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") cls.stock_location = cls.env.ref("stock.stock_location_stock") - def create_picking(self, actual_date=False): + def create_picking(self, actual_date=False, is_done=True): receipt = self.env["stock.picking"].create( { "location_id": self.supplier_location.id, @@ -72,8 +72,9 @@ def create_picking(self, actual_date=False): } ) receipt.move_ids._action_confirm() - receipt.move_ids.picked = True - receipt.move_ids._action_done() + if is_done: + receipt.move_ids.picked = True + receipt.move_ids._action_done() return receipt, receipt.move_ids def create_scrap(self, receipt, actual_date=False): @@ -207,3 +208,20 @@ def test_open_qty_at_actual_date(self): self.assertEqual( self.product_1.with_context(**action["context"]).qty_available, 10.0 ) + + def test_backorder_picking_actual_date(self): + picking, move = self.create_picking(date(2025, 3, 10), is_done=False) + move.move_line_ids.quantity = 5.0 + backorder_wizard_values = picking.button_validate() + backorder_wizard = ( + self.env[(backorder_wizard_values.get("res_model"))] + .browse(backorder_wizard_values.get("res_id")) + .with_context(**backorder_wizard_values["context"]) + ) + backorder_wizard.process() + backorder = self.env["stock.picking"].search( + [("backorder_id", "=", picking.id)], limit=1 + ) + self.assertTrue(backorder, "Backorder picking should be created.") + self.assertFalse(backorder.actual_date) + self.assertFalse(backorder.move_ids.actual_date_source)