Skip to content
Snippets Groups Projects
Commit 35ca0d94 authored by Touati Djamel (otd)'s avatar Touati Djamel (otd)
Browse files

[FIX] mrp: ignore verification for tracked product with 0 to consume qty


Steps to reproduce the bug:
- Create a storable product “P1” with BoM:
    - Add a tracked component
    - Add another component (no tracked)
- Create a MO to produce 1 unit of the product "P1":
    - Confirm
    - Unlock the MO
    - Set the "to consume" quantity of the tracked component to 0.

- Try to validate the MO

Problem:
A user error is triggered: “You need to supply Lot/Serial Number for
products:”

Solution:
If the quantity to consume is 0, ignore the serial number verification
for this move.

opw-3471256

closes odoo/odoo#134567

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent 3857462d
No related branches found
No related tags found
No related merge requests found
......@@ -3298,3 +3298,50 @@ class TestMrpOrder(TestMrpCommon):
consumption.action_set_qty()
self.assertEqual(mo.move_raw_ids[0].product_uom_qty, 30)
self.assertEqual(mo.move_raw_ids[0].quantity_done, 30)
def test_validation_mo_with_tracked_component(self):
"""
check that the verification of SN for tracked component is ignored when the quantity to consume is 0.
"""
self.product_2.tracking = 'serial'
bom = self.env["mrp.bom"].create({
'product_tmpl_id': self.product_4.product_tmpl_id.id,
'product_qty': 1.0,
'bom_line_ids': [(0, 0, {
'product_id': self.product_2.id,
'product_qty': 1.0,
}), (0, 0, {
'product_id': self.product_3.id,
'product_qty': 1.0,
})]
})
# create the MO and confirm it
mo = self.env['mrp.production'].create({
'product_id': self.product_4.id,
'bom_id': bom.id,
'product_qty': 1.0,
})
mo.action_confirm()
self.assertEqual(mo.state, 'confirmed')
# set the qty to consume of the tracked product to 0
mo.move_raw_ids[0].write({
'product_uom_qty': 0,
'quantity_done': 0,
})
mo.action_assign()
res_dict = mo.button_mark_done()
self.assertEqual(res_dict.get('res_model'), 'mrp.immediate.production')
wizard = Form(self.env[res_dict['res_model']].with_context(res_dict['context'])).save()
wizard.process()
self.assertEqual(mo.state, 'to_close')
consumption_issues = mo._get_consumption_issues()
action = mo._action_generate_consumption_wizard(consumption_issues)
warning = Form(self.env['mrp.consumption.warning'].with_context(**action['context']))
warning = warning.save()
self.assertEqual(len(warning.mrp_consumption_warning_line_ids), 1)
self.assertEqual(warning.mrp_consumption_warning_line_ids[0].product_consumed_qty_uom, 0)
self.assertEqual(warning.mrp_consumption_warning_line_ids[0].product_expected_qty_uom, 1)
# Force the warning
warning.action_confirm()
self.assertEqual(mo.state, 'done')
......@@ -58,7 +58,9 @@ class MrpImmediateProduction(models.TransientModel):
else:
production.qty_producing = production.product_qty - production.qty_produced
production._set_qty_producing()
for move in production.move_raw_ids.filtered(lambda m: m.state not in ['done', 'cancel']):
for move in production.move_raw_ids:
if move.state in ('done', 'cancel') or not move.product_uom_qty:
continue
rounding = move.product_uom.rounding
if move.has_tracking in ('serial', 'lot') and float_is_zero(move.quantity_done, precision_rounding=rounding):
error_msg += "\n - %s" % move.product_id.display_name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment