From 4254e0aba9fc9aa660e6433656e53d4f99ec88b8 Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Mon, 15 Jan 2024 09:00:59 +0000 Subject: [PATCH] [FIX] mrp: update stock move date on mark done production Issue: ===== The stock move date is the scheduled date of the production and not the date the production is done. Steps to reproduce the issue: ============================= - Create a manufacturing order with any product (large desk) - Assign a date in the past for scheduled date (5 days before) - Confirm the order. - Added quantity produced and mark as done - Go to traceability , you will see the date here is the scheduled date and not the production date. - You can see also the inventory at date in inventory/reporting/locations will have the product they after the scheduled date. Solution: ========= Use the value of `date_finished` if it's set when calculating the `date` for `move_finished_ids` opw-3640708 closes odoo/odoo#154811 X-original-commit: ac94a429ed5ab0ffe7ac8fbc55243adaed3ce60f Signed-off-by: William Henrotin (whe) Signed-off-by: Mahdi Cheikh Rouhou (macr) --- addons/mrp/tests/test_traceability.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/addons/mrp/tests/test_traceability.py b/addons/mrp/tests/test_traceability.py index b913905c486..2bd7ba68be7 100644 --- a/addons/mrp/tests/test_traceability.py +++ b/addons/mrp/tests/test_traceability.py @@ -7,6 +7,7 @@ from odoo.exceptions import UserError from datetime import datetime import logging +from freezegun import freeze_time _logger = logging.getLogger(__name__) @@ -665,3 +666,19 @@ class TestTraceability(TestMrpCommon): # generate serial lot_3 from the MO (next from sequence) mo.action_generate_serial() self.assertIn(datetime.now().strftime('%j'), mo.lot_producing_id.name) + + def test_assign_stock_move_date_on_mark_done(self): + product_final = self.env['product.product'].create({ + 'name': 'Finished Product', + 'type': 'product', + }) + with freeze_time('2024-01-15'): + production = self.env['mrp.production'].create({ + 'product_id': product_final.id, + 'product_qty': 1, + 'date_start': datetime(2024, 1, 10) + }) + production.action_confirm() + production.qty_producing = 1 + production.button_mark_done() + self.assertEqual(production.move_finished_ids.date, datetime(2024, 1, 15), "Stock move should be availbale after the production is done.")