diff options
| author | Debauche Stéphane <std@odoo.com> | 2019-12-17 13:55:31 +0000 |
|---|---|---|
| committer | Debauche Stéphane <std@odoo.com> | 2019-12-20 10:11:50 +0000 |
| commit | 8944674d6da8a64b1fbc1dff034e82f7052be1b2 (patch) | |
| tree | 8c6219510fb75e92d99d4b48a9ceb85bcf6220cc /addons/mrp/tests/test_procurement.py | |
| parent | 23a5e9945343fe8fe0a2f423243973038bd03e53 (diff) | |
[REF] mrp: date_planned_start and date_planned_finished
Before this patch, writing on the `date_expected` field on the raw moves did not
update the `date_planned_start` (but writing on `date_planned_start` did write on
the raw AND finished moves `date_expected`).
This proved to be wrong: having the same `date_expected` on both raw and finished
moves did not make sense (the manufacturing order is not instantaneous). It also
makes difficult to make the rescheduling work: the rescheduling is done on the stock
moves and thus updates `date_expected` on the raw moves. If this information is not
transmitted to the manufacturing order, we won't be able to continue the rescheduling
on the finished moves (the idea is to update the raw moves which will update the
date_planned_start which will update the date_planned_finished which will update the
finished moves)
To have a more sane system, the `date_planned_start` and `date_planned_finished` are
computed (with an inverse) on the raw and finished moves `date_expected` (similar to
what's done on the picking model). There's a tweak though: as `run_manufacture`
creates first the order with a `date_planned_finished` and then confirm it (which will only
create the finished move at this moment), there's no place to write `date_planned_finished`.
The compute thus defaults on `date_deadline` which is stored and the finished moves
will be created later on with this value.
We implement the same logic `_onchange_date_planned_start` in `write` so that it doesn't
only rely on the onchange mechanism and the rescheduling can work when changing the
`date_expected` on a child mo for example.
task-1970595
Diffstat (limited to 'addons/mrp/tests/test_procurement.py')
| -rw-r--r-- | addons/mrp/tests/test_procurement.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/addons/mrp/tests/test_procurement.py b/addons/mrp/tests/test_procurement.py index 7ff4bdf9a45..0fb99e5570c 100644 --- a/addons/mrp/tests/test_procurement.py +++ b/addons/mrp/tests/test_procurement.py @@ -2,10 +2,12 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from datetime import timedelta +from odoo import fields from odoo.tests import Form from odoo.addons.mrp.tests.common import TestMrpCommon from odoo.exceptions import UserError + class TestProcurement(TestMrpCommon): def test_procurement(self): @@ -177,6 +179,9 @@ class TestProcurement(TestMrpCommon): ('product_id', '=', product_1.id), ('state', '=', 'confirmed') ]) + + self.assertAlmostEqual(mo.move_finished_ids.date_expected, mo.move_raw_ids.date_expected + timedelta(hours=1)) + self.assertEqual(len(mo), 1, 'the manufacture order is not created') mo_form = Form(mo) @@ -193,10 +198,12 @@ class TestProcurement(TestMrpCommon): self.assertEqual(move_orig.product_qty, 10, 'the quantity to produce is not good relative to the move') move_dest_scheduled_date = move_dest.date_expected - mo.date_planned_start += timedelta(days=5) - # Adding 5 days to the date planned start makes the next move's date 4 days and 23 hours - # later since the date planned start was set one hour before the date_planned_end. - self.assertAlmostEqual(move_dest.date_expected, move_dest_scheduled_date + timedelta(days=4, hours=23), delta=timedelta(seconds=1), msg='date is not propagated') + + mo_form = Form(mo) + mo_form.date_planned_start = fields.Datetime.to_datetime(mo_form.date_planned_start) + timedelta(days=5) + mo_form.save() + + self.assertAlmostEqual(move_dest.date_expected, move_dest_scheduled_date + timedelta(days=5), delta=timedelta(seconds=1), msg='date is not propagated') def test_finished_move_cancellation(self): """Check state of finished move on cancellation of raw moves. """ |
