[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#135657

X-original-commit: 5e591cf36cdc6dcbdb8a5ee3753247578a771e9f
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2023-09-19 15:21:01 +00:00
committed by Djamel Touati
parent 21ee079741
commit c8b919c0c2
2 changed files with 44 additions and 1 deletions
+3 -1
View File
@@ -2505,7 +2505,9 @@ class MrpProduction(models.Model):
self.qty_producing = self.product_qty - self.qty_produced
self._set_qty_producing()
for move in self.move_raw_ids.filtered(lambda m: m.state not in ['done', 'cancel']):
for move in self.move_raw_ids:
if move.state in ('done', 'cancel') or not move.product_uom_qty:
continue
rounding = move.product_uom.rounding
if move.manual_consumption:
if move.has_tracking in ('serial', 'lot') and float_is_zero(move.quantity_done, precision_rounding=rounding):
+41
View File
@@ -3441,3 +3441,44 @@ class TestMrpOrder(TestMrpCommon):
p03_raws = mo.move_raw_ids.filtered(lambda m: m.product_id == product03)
self.assertEqual(sum(p02_raws.mapped('quantity_done')), 1.5)
self.assertEqual(sum(p03_raws.mapped('quantity_done')), 2)
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()
# Set MO Done and create backorder
action = mo.button_mark_done()
consumption_warning = Form(self.env['mrp.consumption.warning'].with_context(**action['context'])).save()
self.assertEqual(len(consumption_warning.mrp_consumption_warning_line_ids), 1)
self.assertEqual(consumption_warning.mrp_consumption_warning_line_ids[0].product_consumed_qty_uom, 0)
self.assertEqual(consumption_warning.mrp_consumption_warning_line_ids[0].product_expected_qty_uom, 1)
# Force the warning
consumption_warning.action_confirm()
self.assertEqual(mo.state, 'done')