[FIX] mrp: don’t check reserved qty for consu product
Steps to reproduce the bug:
- Create a storable product “P1”:
- Tracked by: SN
- BoM:
- product qty: 1
- Component: consumable product qty:1
- Create a MO to produce 12 unit of P1
- Update the qty of the consumable product to 31
- Confirm the MO
- Click on “Mass produce”
Problem:
An user error is triggered:
“It is not possible to unreserve more products of Consu than you have in stock”
The product is a consumable, we should not update its reserved quantity.
opw-3620437
closes odoo/odoo#147571
X-original-commit: 33728387925439eaf4971dc732ff46fd19432f2c
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
@@ -245,3 +245,52 @@ class TestMrpSerialMassProduce(TestMrpCommon):
|
||||
mo.procurement_group_id.mrp_production_ids.move_raw_ids.picked = True
|
||||
mo.procurement_group_id.mrp_production_ids.button_mark_done()
|
||||
self.assertEqual(mo.procurement_group_id.mrp_production_ids.mapped('state'), ['done', 'done'])
|
||||
|
||||
def test_smp_produce_with_consumable_component(self):
|
||||
"""Create a MO for a product tracked by serial number with a consumable component.
|
||||
Open the smp wizard, You should be able to generate all serial numbers.
|
||||
BoM:
|
||||
- 1x final product (tracked by serial number)
|
||||
components:
|
||||
- 2 x (storable)
|
||||
- 4 x (consumable)
|
||||
- Create a MO with 12 final products to produce.
|
||||
- update the component quantity to 100
|
||||
"""
|
||||
self.bom_1.product_id.uom_id = self.ref('uom.product_uom_unit')
|
||||
self.bom_1.product_id.tracking = 'serial'
|
||||
self.bom_1.product_qty = 1
|
||||
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.bom_id = self.bom_1
|
||||
mo_form.product_qty = 12
|
||||
mo = mo_form.save()
|
||||
self.assertEqual(mo.move_raw_ids.mapped(lambda l: l.product_qty), [24, 48])
|
||||
self.assertEqual(mo.move_raw_ids[1].product_id.type, 'consu', 'The second component should be consumable')
|
||||
mo.move_raw_ids[1].product_uom_qty = 100
|
||||
|
||||
# Make some stock and reserve for storable component
|
||||
self.env['stock.quant'].with_context(inventory_mode=True).create({
|
||||
'product_id': mo.move_raw_ids[0].product_id.id,
|
||||
'inventory_quantity': 24,
|
||||
'location_id': mo.location_src_id.id,
|
||||
})._apply_inventory()
|
||||
|
||||
mo.action_confirm()
|
||||
self.assertEqual(mo.state, 'confirmed')
|
||||
|
||||
# Open the wizard
|
||||
action = mo.action_serial_mass_produce_wizard()
|
||||
wizard = Form(self.env['stock.assign.serial'].with_context(**action['context']))
|
||||
# Let the wizard generate all serial numbers
|
||||
wizard.next_serial_number = "sn#1"
|
||||
wizard.next_serial_count = mo.product_qty
|
||||
action = wizard.save().generate_serial_numbers_production()
|
||||
# Reload the wizard to apply generated serial numbers
|
||||
wizard = Form(self.env['stock.assign.serial'].browse(action['res_id']))
|
||||
wizard.save().apply()
|
||||
# Initial MO should have a backorder-sequenced name and be in to_close state
|
||||
self.assertTrue("-001" in mo.name)
|
||||
self.assertEqual(mo.state, "to_close")
|
||||
# Each generated serial number should have its own mo
|
||||
self.assertEqual(len(mo.procurement_group_id.mrp_production_ids), 12)
|
||||
|
||||
Reference in New Issue
Block a user