From e9add31a6d0b042f1cde5f562163fdad6637f2cc Mon Sep 17 00:00:00 2001 From: "Mattis Megevand (mmeg)" Date: Tue, 19 Mar 2024 15:08:34 +0000 Subject: [PATCH] [FIX] mrp,stock: compute correct quantity for stock move Steps to reproduce: - Install MRP - Enable packages and multi-step routes - Enable two steps manufacturing - Create a component and a product - Create a BOM for the product and add the component - Make an MO for 100 units of the product - Go to the picking and make a move of 20 units of the component with a destination package - Put in pack - Create the backorder and validate the transfer of the remaining components - Go back to the MO Issues: Units reserved is wrong. The problem is when we are unpacking, we were using result package inside the key. But what we want is to remove quantity from the package the quantity originate from. opw-3759006 closes odoo/odoo#160091 X-original-commit: 1cc04382f7ebaaa68ebe9313f1cd6b1284e13665 Signed-off-by: William Henrotin (whe) Signed-off-by: Mattis Megevand (mmeg) --- addons/mrp/tests/test_stock.py | 34 +++++++++++++++++++++++++++++++ addons/stock/models/stock_move.py | 4 ++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/addons/mrp/tests/test_stock.py b/addons/mrp/tests/test_stock.py index 0086ed9cb58..d5750305ff1 100644 --- a/addons/mrp/tests/test_stock.py +++ b/addons/mrp/tests/test_stock.py @@ -227,6 +227,40 @@ class TestWarehouseMrp(common.TestMrpCommon): self.assertEqual(location_dest.id, self.depot_location.id) self.assertNotEqual(location_dest.id, self.stock_location.id) + def test_backorder_unpacking(self): + """ Test that movement of pack in backorder is correctly handled. """ + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + warehouse.write({'manufacture_steps': 'pbm'}) + + self.product_1.type = 'product' + self.env['stock.quant']._update_available_quantity(self.product_1, self.stock_location, 100) + + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = self.bom_4 + mo_form.product_qty = 100 + mo = mo_form.save() + mo.action_confirm() + + package = self.env['stock.quant.package'].create({}) + + picking = mo.picking_ids + picking.move_line_ids.write({ + 'quantity': 20, + 'result_package_id': package.id, + }) + + res_dict = picking.button_validate() + wizard = Form(self.env[res_dict['res_model']].with_context(res_dict['context'])).save() + wizard.process() + + backorder = picking.backorder_ids + backorder.move_line_ids.quantity = 80 + backorder.button_validate() + + self.assertEqual(picking.state, 'done') + self.assertEqual(backorder.state, 'done') + self.assertEqual(mo.move_raw_ids.move_line_ids.mapped('quantity_product_uom'), [20, 80]) + class TestKitPicking(common.TestMrpCommon): @classmethod def setUpClass(cls): diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index d362ae254d1..63fbdafc06e 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1688,8 +1688,8 @@ Please change the quantity done or the rounding precision of your unit of measur if not available_move_lines: continue for move_line in move.move_line_ids.filtered(lambda m: m.quantity_product_uom): - if available_move_lines.get((move_line.location_id, move_line.lot_id, move_line.result_package_id, move_line.owner_id)): - available_move_lines[(move_line.location_id, move_line.lot_id, move_line.result_package_id, move_line.owner_id)] -= move_line.quantity_product_uom + if available_move_lines.get((move_line.location_id, move_line.lot_id, move_line.package_id, move_line.owner_id)): + available_move_lines[(move_line.location_id, move_line.lot_id, move_line.package_id, move_line.owner_id)] -= move_line.quantity_product_uom for (location_id, lot_id, package_id, owner_id), quantity in available_move_lines.items(): need = move.product_qty - sum(move.move_line_ids.mapped('quantity_product_uom')) # `quantity` is what is brought by chained done move lines. We double check