From 3d5d5cc04169ef15279969d1c90f0636e772e9c6 Mon Sep 17 00:00:00 2001 From: Walid Date: Thu, 7 Mar 2024 16:47:48 +0100 Subject: [PATCH] [FIX] stock: multistep reciept update quantity Steps to reproduce: - Enable 2 step reciept in warehaouse settings Bug1: - Create and confirm a PO qty = 1 - Open reciept update qty to 4 and validate - The internal transfer qty is updated to 3 (the difference) Bug2: - In inventory overview create a new reciept and mark it as todo - Update quantity and validate - Internal transfer is not updated Root cause: Initially in version 17 product_uom_qty was changed to indicate the demand before the move is done and it indicates the acutual done qty when the move is done. After https://github.com/odoo/odoo/pull/130342 product_uom_qty will always indicate the demand qty, and qty_done will always indicate actually done quantity. Fix: updating the quantity will create a new move for the difference that is used to trigger new push rule and then merged back in the original when merging product_uom_qty is not updated to keep track of the intial demand but pending linked moves should be updated to reflect the new quantity opw-3708740 closes odoo/odoo#156331 Signed-off-by: William Henrotin (whe) --- addons/stock/models/stock_move.py | 3 ++- addons/stock/tests/test_move.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index b5b0ec37176..63455f1fcb7 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1020,7 +1020,8 @@ Please change the quantity done or the rounding precision of your unit of measur # link all move lines to record 0 (the one we will keep). moves.mapped('move_line_ids').write({'move_id': moves[0].id}) # merge move data - moves[0].write(moves._merge_moves_fields()) + merge_extra = self.env.context.get('merge_extra') and bool(merge_into) + moves[0].write(moves.with_context(merge_extra=merge_extra)._merge_moves_fields()) # update merged moves dicts moves_to_unlink |= moves[1:] merged_moves |= moves[0] diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index bab7a8ca090..bef76702e97 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -649,6 +649,29 @@ class StockMove(TransactionCase): quants = self.gather_relevant(self.product_serial, self.stock_location) self.assertEqual(len(quants), 0) + def test_multi_step_update(self): + """ + multi step reciept update done quantity + """ + warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + warehouse.reception_steps = 'two_steps' + + move_input = self.env['stock.move'].create({ + 'name': self.product.name, + 'location_id': self.supplier_location.id, + 'location_dest_id': warehouse.wh_input_stock_loc_id.id, + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1.0, + 'warehouse_id': warehouse.id, + }) + move_input._action_confirm() + move_input.move_line_ids.quantity = 9 + move_input.picked = True + move_input._action_done() + + self.assertEqual(move_input.move_dest_ids.product_uom_qty, 9) + def test_mixed_tracking_reservation_8(self): """ Send one product tracked by lot to a customer. In your stock, there are one tracked and one untracked quant. Reserve the move, then edit the lot to one not present in stock. The