Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stock_move_actual_date/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions stock_move_actual_date/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
17 changes: 17 additions & 0 deletions stock_move_actual_date/tests/test_stock_move_actual_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
Loading