[FIX] mrp, sale_mrp: set bom_line_id on all moves for kits

Current behavior:
When using 2 steps delivery and selling a kit product, not all
moves had bom_line_id set. So if you go in the transfers you
couldn't always see the "Kit" column in the operations.

Steps to reproduce:
- Activate 2 steps delivery
- Create a Kit with 2 products
- Create a quotation with kit and confirm it
- Go in the delivery
- In WH/Pick you can't see Kit column
- In WH/Out you can see the Kit column

opw-2796974

closes odoo/odoo#89371

X-original-commit: 88c3c3f49393af08e4070c0d2f5cccbec9096c1f
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2022-04-25 11:32:03 +02:00
parent 71bc97c19b
commit a73e69b2bb
2 changed files with 58 additions and 0 deletions
+5
View File
@@ -542,3 +542,8 @@ class StockMove(models.Model):
self.move_line_ids = self._set_quantity_done_prepare_vals(quantity_done)
else:
super()._multi_line_quantity_done_set(quantity_done)
def _prepare_procurement_values(self):
res = super()._prepare_procurement_values()
res['bom_line_id'] = self.bom_line_id.id
return res
@@ -410,3 +410,56 @@ class TestSaleMrpKitBom(TransactionCase):
# Checks the delivery amount (must be 1).
self.assertEqual(so.order_line.qty_delivered, 1)
def test_sale_kit_show_kit_in_delivery(self):
"""Create a kit with 2 product and activate 2 steps
delivery and check that every stock move contains
a bom_line_id
"""
wh = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1)
wh.write({'delivery_steps': 'pick_ship'})
kitA = self._create_product('Kit Product', 'product', 0.00)
compA = self._create_product('ComponentA', 'product', 0.00)
compB = self._create_product('ComponentB', 'product', 0.00)
# Create BoM for KitB
bom_product_formA = Form(self.env['mrp.bom'])
bom_product_formA.product_id = kitA
bom_product_formA.product_tmpl_id = kitA.product_tmpl_id
bom_product_formA.product_qty = 1.0
bom_product_formA.type = 'phantom'
with bom_product_formA.bom_line_ids.new() as bom_line:
bom_line.product_id = compA
bom_line.product_qty = 1
with bom_product_formA.bom_line_ids.new() as bom_line:
bom_line.product_id = compB
bom_line.product_qty = 1
bom_product_formA.save()
customer = self.env['res.partner'].create({
'name': 'customer',
})
so = self.env['sale.order'].create({
'partner_id': customer.id,
'order_line': [
(0, 0, {
'name': kitA.name,
'product_id': kitA.id,
'product_uom_qty': 1.0,
'product_uom': kitA.uom_id.id,
'price_unit': 1,
'tax_id': False,
})]
})
so.action_confirm()
pick = so.picking_ids[0]
ship = so.picking_ids[1]
self.assertTrue(pick.move_ids_without_package[0].bom_line_id, "All component from kits should have a bom line")
self.assertTrue(pick.move_ids_without_package[1].bom_line_id, "All component from kits should have a bom line")
self.assertTrue(ship.move_ids_without_package[0].bom_line_id, "All component from kits should have a bom line")
self.assertTrue(ship.move_ids_without_package[1].bom_line_id, "All component from kits should have a bom line")