From 02359fd78b515515142eb9a2e2dd026026a3ef08 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Tue, 28 Apr 2020 14:54:31 +0200 Subject: [PATCH] [FIX] stock: quantity done compute mismatch on the move lines used by the compute. task-2241471 --- addons/stock/models/stock_move.py | 6 ++++-- addons/stock/tests/test_move.py | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index ef7a463ae21..59916f865a4 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -280,9 +280,11 @@ class StockMove(models.Model): """ This will return the move lines to consider when applying _quantity_done_compute on a stock.move. In some context, such as MRP, it is necessary to compute quantity_done on filtered sock.move.line.""" self.ensure_one() - return self.move_line_ids or self.move_line_nosuggest_ids + if self.picking_type_id.show_reserved is False: + return self.move_line_nosuggest_ids + return self.move_line_ids - @api.depends('move_line_ids.qty_done', 'move_line_ids.product_uom_id', 'move_line_nosuggest_ids.qty_done') + @api.depends('move_line_ids.qty_done', 'move_line_ids.product_uom_id', 'move_line_nosuggest_ids.qty_done', 'picking_type_id') def _quantity_done_compute(self): """ This field represents the sum of the move lines `qty_done`. It allows the user to know if there is still work to do. diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index cb0583a4101..389ca4428b5 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -4369,6 +4369,7 @@ class StockMove(SavepointCase): 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, 'picking_id': picking.id, + 'picking_type_id': self.env.ref('stock.picking_type_out').id, }) picking.action_confirm() picking.action_assign() @@ -4458,6 +4459,7 @@ class StockMove(SavepointCase): 'product_uom': self.uom_unit.id, 'product_uom_qty': 1.0, 'picking_id': picking.id, + 'picking_type_id': self.env.ref('stock.picking_type_out').id, }) move2 = self.env['stock.move'].create({ 'name': 'test_transit_2', @@ -4467,6 +4469,7 @@ class StockMove(SavepointCase): 'product_uom': self.uom_unit.id, 'product_uom_qty': 2.0, 'picking_id': picking.id, + 'picking_type_id': self.env.ref('stock.picking_type_out').id, }) picking.action_confirm() picking.action_assign()