[IMP] mrp: select BoM based on rule
Add test for use case fixed by d43e9cb9ad8d1c0c020209de0e8f6ffdcbc960a1 closes odoo/odoo#89237 X-original-commit: 21be0d8e96b9fb6e9fd6476a664ce89b017a7767 Signed-off-by: Arnold Moyaux <arm@odoo.com> Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
@@ -676,3 +676,78 @@ class TestProcurement(TestMrpCommon):
|
||||
self.assertEqual(len(mo3), 1)
|
||||
self.assertEqual(mo1.product_qty, 20)
|
||||
self.assertEqual(mo3.product_qty, 50)
|
||||
|
||||
def test_several_boms_same_finished_product(self):
|
||||
"""
|
||||
Suppose a product with two BoMs, each one based on a different operation type
|
||||
This test ensures that, when running the scheduler, the generated MOs are based
|
||||
on the correct BoMs
|
||||
"""
|
||||
warehouse = self.env.ref('stock.warehouse0')
|
||||
|
||||
stock_location01 = warehouse.lot_stock_id
|
||||
stock_location02 = stock_location01.copy()
|
||||
|
||||
manu_operation01 = warehouse.manu_type_id
|
||||
manu_operation02 = manu_operation01.copy()
|
||||
with Form(manu_operation02) as form:
|
||||
form.name = 'Manufacturing 02'
|
||||
form.sequence_code = 'MO2'
|
||||
form.default_location_dest_id = stock_location02
|
||||
|
||||
manu_rule01 = warehouse.manufacture_pull_id
|
||||
manu_route = manu_rule01.route_id
|
||||
manu_rule02 = manu_rule01.copy()
|
||||
with Form(manu_rule02) as form:
|
||||
form.picking_type_id = manu_operation02
|
||||
manu_route.rule_ids = [(6, 0, (manu_rule01 + manu_rule02).ids)]
|
||||
|
||||
compo01, compo02, finished = self.env['product.product'].create([{
|
||||
'name': 'compo 01',
|
||||
'type': 'consu',
|
||||
}, {
|
||||
'name': 'compo 02',
|
||||
'type': 'consu',
|
||||
}, {
|
||||
'name': 'finished',
|
||||
'type': 'product',
|
||||
'route_ids': [(6, 0, manu_route.ids)],
|
||||
}])
|
||||
|
||||
bom01_form = Form(self.env['mrp.bom'])
|
||||
bom01_form.product_tmpl_id = finished.product_tmpl_id
|
||||
bom01_form.code = '01'
|
||||
bom01_form.picking_type_id = manu_operation01
|
||||
with bom01_form.bom_line_ids.new() as line:
|
||||
line.product_id = compo01
|
||||
bom01 = bom01_form.save()
|
||||
|
||||
bom02_form = Form(self.env['mrp.bom'])
|
||||
bom02_form.product_tmpl_id = finished.product_tmpl_id
|
||||
bom02_form.code = '02'
|
||||
bom02_form.picking_type_id = manu_operation02
|
||||
with bom02_form.bom_line_ids.new() as line:
|
||||
line.product_id = compo02
|
||||
bom02 = bom02_form.save()
|
||||
|
||||
self.env['stock.warehouse.orderpoint'].create([{
|
||||
'warehouse_id': warehouse.id,
|
||||
'location_id': stock_location01.id,
|
||||
'product_id': finished.id,
|
||||
'product_min_qty': 1,
|
||||
'product_max_qty': 1,
|
||||
}, {
|
||||
'warehouse_id': warehouse.id,
|
||||
'location_id': stock_location02.id,
|
||||
'product_id': finished.id,
|
||||
'product_min_qty': 2,
|
||||
'product_max_qty': 2,
|
||||
}])
|
||||
|
||||
self.env['procurement.group'].run_scheduler()
|
||||
|
||||
mos = self.env['mrp.production'].search([('product_id', '=', finished.id)], order='origin')
|
||||
self.assertRecordValues(mos, [
|
||||
{'product_qty': 1, 'bom_id': bom01.id, 'picking_type_id': manu_operation01.id, 'location_dest_id': stock_location01.id},
|
||||
{'product_qty': 2, 'bom_id': bom02.id, 'picking_type_id': manu_operation02.id, 'location_dest_id': stock_location02.id},
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user