[FIX] mrp: byproducts follow putaway rules
Before this commit, the byproduct and putaway feature do not work together. More specifically, changing the quantity to produce on a manufacturing order will create automatically a byproduct move line (or update the existing one with the new quantity) but never look for a putaway rule to apply. This commit makes use of `_set_quantity_done()` method on `stock.move` that *do* call the putaway strategy mechanism X-original-commit: d4a968412e68cc9da3ec2d9725caa90830287c48 Part-of: odoo/odoo#109669
This commit is contained in:
committed by
Adrien Widart (awt)
parent
7b4b835465
commit
0149a26c62
@@ -1069,7 +1069,7 @@ class MrpProduction(models.Model):
|
||||
new_qty = min(new_qty, move.reserved_availability)
|
||||
|
||||
move.move_line_ids.filtered(lambda ml: ml.state not in ('done', 'cancel')).qty_done = 0
|
||||
move.move_line_ids = move._set_quantity_done_prepare_vals(new_qty)
|
||||
move._set_quantity_done(new_qty)
|
||||
|
||||
def _update_raw_moves(self, factor):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -26,6 +26,14 @@ class TestMrpByProduct(common.TransactionCase):
|
||||
cls.product_a = create_product('Product A', route_ids=[(6, 0, [route_manufacture, route_mto])])
|
||||
cls.product_b = create_product('Product B', route_ids=[(6, 0, [route_manufacture, route_mto])])
|
||||
cls.product_c_id = create_product('Product C', route_ids=[]).id
|
||||
cls.bom_byproduct = cls.MrpBom.create({
|
||||
'product_tmpl_id': cls.product_a.product_tmpl_id.id,
|
||||
'product_qty': 1.0,
|
||||
'type': 'normal',
|
||||
'product_uom_id': cls.uom_unit_id,
|
||||
'bom_line_ids': [(0, 0, {'product_id': cls.product_c_id, 'product_uom_id': cls.uom_unit_id, 'product_qty': 2})],
|
||||
'byproduct_ids': [(0, 0, {'product_id': cls.product_b.id, 'product_uom_id': cls.uom_unit_id, 'product_qty': 1})]
|
||||
})
|
||||
|
||||
def test_00_mrp_byproduct(self):
|
||||
""" Test by product with production order."""
|
||||
@@ -39,22 +47,12 @@ class TestMrpByProduct(common.TransactionCase):
|
||||
'bom_line_ids': [(0, 0, {'product_id': self.product_c_id, 'product_uom_id': self.uom_unit_id, 'product_qty': 2})]
|
||||
})
|
||||
|
||||
# Create BOM for product A and set byproduct product B
|
||||
bom_product_a = self.MrpBom.create({
|
||||
'product_tmpl_id': self.product_a.product_tmpl_id.id,
|
||||
'product_qty': 1.0,
|
||||
'type': 'normal',
|
||||
'product_uom_id': self.uom_unit_id,
|
||||
'bom_line_ids': [(0, 0, {'product_id': self.product_c_id, 'product_uom_id': self.uom_unit_id, 'product_qty': 2})],
|
||||
'byproduct_ids': [(0, 0, {'product_id': self.product_b.id, 'product_uom_id': self.uom_unit_id, 'product_qty': 1})]
|
||||
})
|
||||
|
||||
# Create production order for product A
|
||||
# -------------------------------------
|
||||
|
||||
mnf_product_a_form = Form(self.env['mrp.production'])
|
||||
mnf_product_a_form.product_id = self.product_a
|
||||
mnf_product_a_form.bom_id = bom_product_a
|
||||
mnf_product_a_form.bom_id = self.bom_byproduct
|
||||
mnf_product_a_form.product_qty = 2.0
|
||||
mnf_product_a = mnf_product_a_form.save()
|
||||
mnf_product_a.action_confirm()
|
||||
@@ -271,3 +269,44 @@ class TestMrpByProduct(common.TransactionCase):
|
||||
self.assertEqual(
|
||||
mo.move_byproduct_ids.product_uom_qty, expected_byproduct_qty, "Wrong produced quantity of by-product."
|
||||
)
|
||||
|
||||
def test_byproduct_putaway(self):
|
||||
""" Test the byproducts are dispatched correctly with putaway rules"""
|
||||
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
shelf1_location = self.env['stock.location'].create({
|
||||
'name': 'shelf1',
|
||||
'usage': 'internal',
|
||||
'location_id': self.stock_location.id,
|
||||
})
|
||||
shelf2_location = self.env['stock.location'].create({
|
||||
'name': 'shelf2',
|
||||
'usage': 'internal',
|
||||
'location_id': self.stock_location.id,
|
||||
})
|
||||
self.env['stock.putaway.rule'].create({
|
||||
'product_id': self.product_b.id,
|
||||
'location_in_id': self.stock_location.id,
|
||||
'location_out_id': shelf1_location.id,
|
||||
})
|
||||
self.env['stock.putaway.rule'].create({
|
||||
'product_id': self.product_a.id,
|
||||
'location_in_id': self.stock_location.id,
|
||||
'location_out_id': shelf2_location.id,
|
||||
})
|
||||
|
||||
mo_form = Form(self.env['mrp.production'])
|
||||
mo_form.product_id = self.product_a
|
||||
mo_form.bom_id = self.bom_byproduct
|
||||
mo_form.product_qty = 2.0
|
||||
mo = mo_form.save()
|
||||
mo.action_confirm()
|
||||
mo_form = Form(mo)
|
||||
mo_form.qty_producing = 2.00
|
||||
mo = mo_form.save()
|
||||
|
||||
mo._post_inventory()
|
||||
byproduct_move_line = mo.move_byproduct_ids.move_line_ids
|
||||
finished_move_line = mo.move_finished_ids.filtered(lambda m: m.product_id == self.product_a).move_line_ids
|
||||
self.assertEqual(byproduct_move_line.location_dest_id, shelf1_location)
|
||||
self.assertEqual(finished_move_line.location_dest_id, shelf2_location)
|
||||
|
||||
Reference in New Issue
Block a user