From 70d292afd8a8388f6abdf51052cd558639651fcf Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Tue, 9 Apr 2024 16:01:48 +0200 Subject: [PATCH] [FIX] stock: update byproduct qty in SM to the qty set on MO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/mrp/tests/test_byproduct.py | 20 ++++++++++++++++++++ addons/stock/models/stock_move.py | 2 -- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/mrp/tests/test_byproduct.py b/addons/mrp/tests/test_byproduct.py index 5ff4354952c..3e79e2f88c9 100644 --- a/addons/mrp/tests/test_byproduct.py +++ b/addons/mrp/tests/test_byproduct.py @@ -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) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index e44b8a35a7e..2ae144dacfe 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -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