From d21ab73d794e09f4bf696883d89cd29827d0a34e Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Fri, 16 Jul 2021 11:40:17 +0000 Subject: [PATCH] [FIX] stock: prevent to copy reservation on stock.move.line Usecase: - Product A 10 units in stock - Do a planned transfer of 7 units to customer - Reserve - Do an rpc or execute code to call copy on the stock.move.line It will result with 2 sml that have 14 units reserve and 7 units reserved on stock.quant It's the same result if you create twice the stock.move.line without updating the stock.quant at the same time. However in stable we try to only use _update_reserved_quantity on stock.move or some override in create/write method for 'done' stock.move.line in unlock cases. So we never use the copy in stable and define the basic behavior as 'we don't copy the reservation' could prevent some usecase where the update on the stock.quant is forgotten after. closes odoo/odoo#74489 X-original-commit: e5041ee1d9b5036cab55f4332977aeb818a3b1e1 Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_move_line.py | 5 +++-- addons/stock/tests/test_wise_operator.py | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index a5e87d1fdb9..17a93b8c64d 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -30,9 +30,10 @@ class StockMoveLine(models.Model): product_uom_id = fields.Many2one('uom.uom', 'Unit of Measure', required=True, domain="[('category_id', '=', product_uom_category_id)]") product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id') product_qty = fields.Float( - 'Real Reserved Quantity', digits=0, + 'Real Reserved Quantity', digits=0, copy=False, compute='_compute_product_qty', inverse='_set_product_qty', store=True) - product_uom_qty = fields.Float('Reserved', default=0.0, digits='Product Unit of Measure', required=True) + product_uom_qty = fields.Float( + 'Reserved', default=0.0, digits='Product Unit of Measure', required=True, copy=False) qty_done = fields.Float('Done', default=0.0, digits='Product Unit of Measure', copy=False) package_id = fields.Many2one( 'stock.quant.package', 'Source Package', ondelete='restrict', diff --git a/addons/stock/tests/test_wise_operator.py b/addons/stock/tests/test_wise_operator.py index e2f64d699c9..75387202df7 100644 --- a/addons/stock/tests/test_wise_operator.py +++ b/addons/stock/tests/test_wise_operator.py @@ -145,8 +145,7 @@ class TestWiseOperator(TransactionCase): # put the move lines from delivery_order_wise2 into delivery_order_wise1 for pack_id2 in pack_ids2: new_pack_id1 = pack_id2.copy(default={'picking_id': delivery_order_wise1.id, 'move_id': move1.id}) - new_pack_id1.qty_done = new_pack_id1.product_qty - new_pack_id1.with_context(bypass_reservation_update=True).product_uom_qty = 0 + new_pack_id1.qty_done = pack_id2.product_qty new_move_lines = delivery_order_wise1.move_line_ids.filtered(lambda p: p.qty_done) self.assertEqual(sum(new_move_lines.mapped('product_qty')), 0) @@ -157,8 +156,7 @@ class TestWiseOperator(TransactionCase): # put the move line from delivery_order_wise1 into delivery_order_wise2 new_pack_id2 = pack_ids1.copy(default={'picking_id': delivery_order_wise2.id, 'move_id': move2.id}) - new_pack_id2.qty_done = new_pack_id2.product_qty - new_pack_id2.with_context(bypass_reservation_update=True).product_uom_qty = 0 + new_pack_id2.qty_done = pack_ids1.product_qty new_move_lines = delivery_order_wise2.move_line_ids.filtered(lambda p: p.qty_done) self.assertEqual(len(new_move_lines), 1)