From 3700b9b38b310c85f400d261aeda1f34dedb6069 Mon Sep 17 00:00:00 2001 From: Nicolas Galler Date: Mon, 21 Dec 2020 14:32:55 +0000 Subject: [PATCH] [FIX] mrp: update date on move when editing date after planning WO Behavior prior to this commit: - normally when editing the Scheduled Date on a MO, the date on the related stock moves is updated. However this does not happen once the MO is planned - if the date is edited and the MO is planned, the MO is automatically unplanned, but the date on the stock moves is not automatically updated Behavior after this commit: - when the date is updated on the MO and it is planned, the dates on the stock moves will automatically update, so that the behavior is consistent with how it would work if you clicked Unplan first then updated the date. Note: - this commit is forward ported from 14.0. Only the unit test was ported, as the behavior had already been modified to match the expectation. opw-2417108 closes odoo/odoo#64006 X-original-commit: 97f79960dbb3aa371378f576cfdce9670ca8ccce Signed-off-by: Nicolas Galler --- addons/mrp/tests/test_order.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 65a4da48486..e42eb695af8 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -316,6 +316,22 @@ class TestMrpOrder(TestMrpCommon): production = mo_form.save() self.assertEqual(production.workorder_ids.duration_expected, 90) + def test_update_plan_date(self): + """Editing the scheduled date after planning the MO should unplan the MO, and adjust the date on the stock moves""" + planned_date = datetime(2023, 5, 15, 9, 0) + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = self.product_4 + mo_form.bom_id = self.bom_1 + mo_form.product_qty = 1 + mo_form.date_planned_start = planned_date + mo = mo_form.save() + self.assertEqual(mo.move_finished_ids[0].date, datetime(2023, 5, 15, 10, 0)) + mo.action_confirm() + mo.button_plan() + with Form(mo) as frm: + frm.date_planned_start = datetime(2024, 5, 15, 9, 0) + self.assertEqual(mo.move_finished_ids[0].date, datetime(2024, 5, 15, 10, 0)) + def test_rounding(self): """ Checks we round up when bringing goods to produce and round half-up when producing. This implementation allows to implement an efficiency notion (see rev 347f140fe63612ee05e).