[FIX] stock: update byproduct qty in SM to the qty set on MO

Steps to reproduce the bug:
- Enable the “byproduct” option in the settings
- Enable 3 steps for manufacturing operation
- Create a storable product “P1”:
    - Component: C1, qty: 1 unit
    - By-product: C2, qty: 0 unit

- Create a MO:
    - Confirm it
    - Update the qty produced of C2 to 1

- Mark as done the MO
- Go to the picking

Problem:
The quantity of the byproduct (C2) is not updated to 1.

When the MO is marked as done, the "_action_done" for finished moves is
called:

https://github.com/odoo/odoo/blob/34c192761fa375b56d617fec78fb63d8008f6451/addons/mrp/models/mrp_production.py#L1465

Then, we will check, if we should create an extra move:

https://github.com/odoo/odoo/blob/6a114cc97e0ee0648751194c1ffe3e70d900062c/addons/stock/models/stock_move.py#L1507

However, since we ignore moves with a product_uom_qty of 0, we do not
check if this move has a different done quantity and thus do not create
an extra move:

https://github.com/odoo/odoo/blob/eb4f5fc929217dea7d97a66b6aeeaa8b0bd1e3f1/addons/stock/models/stock_move.py#L1779-L1780

opw-3815481

closes odoo/odoo#161127

Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
This commit is contained in:
Djamel Touati
2024-04-12 15:27:48 +00:00
parent cb0b444359
commit 70d292afd8
2 changed files with 20 additions and 2 deletions
+20
View File
@@ -473,3 +473,23 @@ class TestMrpByProduct(common.TransactionCase):
mo.button_mark_done()
self.assertEqual(len(mo.move_byproduct_ids.move_line_ids), 2)
self.assertEqual(mo.move_byproduct_ids.product_id, mo.move_byproduct_ids.move_line_ids.product_id)
def test_byproduct_qty_update(self):
"""
Test that byproduct quantity is updated to the quantity set on the Mo when the Mo is marked as done.ee
"""
self.bom_byproduct.byproduct_ids.product_qty = 0.0
self.warehouse.manufacture_steps = 'pbm_sam'
mo = self.env["mrp.production"].create({
'product_id': self.product_a.id,
'product_qty': 1.0,
'bom_id': self.bom_byproduct.id,
})
mo.action_confirm()
mo.move_byproduct_ids.quantity = 1.0
mo.button_mark_done()
self.assertEqual(mo.state, 'done')
picking = mo.picking_ids.filtered(lambda p: p.location_dest_id == self.warehouse.lot_stock_id)
self.assertEqual(picking.state, 'assigned')
byproduct_move = picking.move_ids.filtered(lambda m: m.product_id == self.bom_byproduct.byproduct_ids.product_id)
self.assertEqual(byproduct_move.product_qty, 1.0)
-2
View File
@@ -1776,8 +1776,6 @@ Please change the quantity done or the rounding precision of your unit of measur
"""
extra_move = self
rounding = self.product_uom.rounding
if float_is_zero(self.product_uom_qty, precision_rounding=rounding):
return self
# moves created after the picking is assigned do not have `product_uom_qty`, but we shouldn't create extra moves for them
if float_compare(self.quantity, self.product_uom_qty, precision_rounding=rounding) > 0:
# create the extra moves