diff options
| author | Tiffany Chang (tic) <tic@odoo.com> | 2021-02-23 12:16:39 +0000 |
|---|---|---|
| committer | Tiffany Chang (tic) <tic@odoo.com> | 2021-05-17 15:54:21 +0000 |
| commit | 81ba7084aeb3899787d083a2a2568a490f9c53e5 (patch) | |
| tree | 3aabf65eeccaabca4c1b260157bad8a129d7830e /addons/mrp | |
| parent | 45845a87ab6a6260b42abacf16811684418cd775 (diff) | |
[FIX] mrp: prevent MO validation with no consumption
If a MO is validated with all of its (component)
move_raw_ids.quality_done = 0, then when trying to validate the
nonsensical "The quantity to produce must be positive" validation error
will occur. This is due to all move_raw_ids being marked as Cancelled,
which auto-updates the MO state to cancelled, which prevents the
validation from properly completing.
To avoid this error, we prevent the user from having 0 consumption for
all components.
Task: 2422698
Related (v13 fix + bug description) Task: 2463893
ENT PR (test fixes): odoo/enterprise#18355
closes odoo/odoo#70900
Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
Diffstat (limited to 'addons/mrp')
| -rw-r--r-- | addons/mrp/i18n/mrp.pot | 8 | ||||
| -rw-r--r-- | addons/mrp/models/mrp_production.py | 2 | ||||
| -rw-r--r-- | addons/mrp/tests/test_order.py | 31 |
3 files changed, 41 insertions, 0 deletions
diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index a4dc5e4ebd8..0ba8dcb5763 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -5061,6 +5061,14 @@ msgid "" msgstr "" #. module: mrp +#: code:addons/mrp/models/mrp_production.py:0 +#, python-format +msgid "" +"You must indicate a non-zero amount consumed for at least one of your " +"components" +msgstr "" + +#. module: mrp #: code:addons/mrp/models/mrp_workorder.py:0 #, python-format msgid "" diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 051913b4635..58f68142706 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1548,6 +1548,8 @@ class MrpProduction(models.Model): for production in self: if float_is_zero(production.qty_producing, precision_rounding=production.product_uom_id.rounding): raise UserError(_('The quantity to produce must be positive!')) + if not any(production.move_raw_ids.mapped('quantity_done')): + raise UserError(_("You must indicate a non-zero amount consumed for at least one of your components")) consumption_issues = self._get_consumption_issues() if consumption_issues: diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 798ffe25dc1..40bb0fd0311 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -1205,6 +1205,37 @@ class TestMrpOrder(TestMrpCommon): mo.move_finished_ids._action_done() mo.button_mark_done() + def test_product_produce_13(self): + """ Check that the production cannot be completed without any consumption.""" + product = self.env['product.product'].create({ + 'name': 'Product no BoM', + 'type': 'product', + }) + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = product + mo = mo_form.save() + move = self.env['stock.move'].create({ + 'name': 'mrp_move', + 'product_id': self.product_2.id, + 'product_uom': self.ref('uom.product_uom_unit'), + 'production_id': mo.id, + 'location_id': self.ref('stock.stock_location_stock'), + 'location_dest_id': self.ref('stock.stock_location_output'), + 'product_uom_qty': 0, + 'quantity_done': 0, + }) + mo.move_raw_ids |= move + mo.action_confirm() + + mo.qty_producing = 1 + # can't produce without any consumption (i.e. components w/ 0 consumed) + with self.assertRaises(UserError): + mo.button_mark_done() + + mo.move_raw_ids.quantity_done = 1 + mo.button_mark_done() + self.assertEqual(mo.state, 'done') + def test_product_produce_uom(self): """ Produce a finished product tracked by serial number. Set another UoM on the bom. The produce wizard should keep the UoM of the product (unit) |
