From a419d1db1a99934f4f184cfdfab52124674e274c Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Fri, 17 Jul 2026 01:45:52 +0000 Subject: [PATCH] [FIX] stock_move_actual_date: inherit actual_date for moves added to an existing picking --- stock_move_actual_date/__manifest__.py | 3 ++- stock_move_actual_date/models/stock_move.py | 14 ++++++++++++-- .../tests/test_stock_move_actual_date.py | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/stock_move_actual_date/__manifest__.py b/stock_move_actual_date/__manifest__.py index bbfbe59c..565602ef 100644 --- a/stock_move_actual_date/__manifest__.py +++ b/stock_move_actual_date/__manifest__.py @@ -2,7 +2,8 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Stock Move Actual Date", - "version": "18.0.1.0.0", + "summary": "Use actual dates on stock moves for accounting and valuation", + "version": "18.0.1.0.1", "author": "Quartile, Odoo Community Association (OCA)", "website": "https://github.com/OCA/stock-logistics-workflow", "category": "Stock", diff --git a/stock_move_actual_date/models/stock_move.py b/stock_move_actual_date/models/stock_move.py index 281a57e7..45b7f5f2 100644 --- a/stock_move_actual_date/models/stock_move.py +++ b/stock_move_actual_date/models/stock_move.py @@ -25,9 +25,19 @@ def create(self, vals_list): # record. For example, in mrp_stock_actual_date, the actual_date is passed via # context when validating an unbuild order or a scrap. actual_date_source = self.env.context.get("actual_date_source") - if actual_date_source: - for vals in vals_list: + for vals in vals_list: + if vals.get("actual_date_source"): + continue + if actual_date_source: vals["actual_date_source"] = actual_date_source + continue + # A move added to a picking that already has an actual_date (e.g. a new + # PO line creating a move in an existing receipt) should inherit it. + picking_id = vals.get("picking_id") + if picking_id: + picking = self.env["stock.picking"].browse(picking_id) + if picking.actual_date: + vals["actual_date_source"] = picking.actual_date return super().create(vals_list) @api.depends("date", "actual_date_source") 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 13becb4c..7443cb59 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 @@ -103,6 +103,23 @@ def test_stock_move_actual_date(self): self.assertEqual(scrap.move_ids.actual_date, date(2024, 8, 11)) self.assertEqual(scrap.move_ids.account_move_ids.date, date(2024, 8, 11)) + def test_move_added_to_picking_inherits_actual_date(self): + receipt, move = self.create_picking(date(2026, 7, 1)) + self.assertEqual(move.actual_date, date(2026, 7, 1)) + # A move added to the existing picking (e.g. from a new PO line) should + # inherit the picking's actual_date. + new_move = self.env["stock.move"].create( + { + "name": "5 in", + "picking_id": receipt.id, + "location_id": self.supplier_location.id, + "location_dest_id": self.stock_location.id, + "product_id": self.product_2.id, + "product_uom_qty": 5.0, + } + ) + self.assertEqual(new_move.actual_date, date(2026, 7, 1)) + def test_inventory_adjustment_actual_date(self): quant = self.env["stock.quant"].create( {