From ee7e9198f2ef7b468b929c8dec14570e6af1afcf Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 4 Feb 2018 17:41:13 +0100 Subject: [PATCH] [FIX] stock: don't update a move line with qty=1 with serial product Use case to reproduce: - create a product A with serial number - add 2 product A in stock - create a delivery order with this 4 product - Check Availability - add 2 more product A in stock - Check Availability - in the first line the quantity is now 3 It happens because _update_reserved_quantity on stock move try to add the quantity reserved on simililar move lines. Howevever in serial case we don't want to have a move line with a reserved quantity greater than 1. --- addons/stock/models/stock_move.py | 3 ++- addons/stock/tests/test_move.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index be50495305d..3054f09ef7a 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -816,7 +816,8 @@ class StockMove(models.Model): # Find a candidate move line to update or create a new one. for reserved_quant, quantity in quants: - to_update = self.move_line_ids.filtered(lambda m: m.location_id.id == reserved_quant.location_id.id and m.lot_id.id == reserved_quant.lot_id.id and m.package_id.id == reserved_quant.package_id.id and m.owner_id.id == reserved_quant.owner_id.id) + to_update = self.move_line_ids.filtered(lambda m: m.product_id.tracking != 'serial' and + m.location_id.id == reserved_quant.location_id.id and m.lot_id.id == reserved_quant.lot_id.id and m.package_id.id == reserved_quant.package_id.id and m.owner_id.id == reserved_quant.owner_id.id) if to_update: to_update[0].with_context(bypass_reservation_update=True).product_uom_qty += self.product_id.uom_id._compute_quantity(quantity, self.product_uom, rounding_method='HALF-UP') else: diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 0e52a87d1ca..9b011f34164 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -756,6 +756,28 @@ class StockMove(TransactionCase): self.assertEqual(customer_quants.quantity, 30) self.assertEqual(customer_quants.reserved_quantity, 0) + def test_availability_5(self): + """ Check that rerun action assign only create new stock move + lines instead of adding quantity in existing one. + """ + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 2.0) + # move from shelf1 + move = self.env['stock.move'].create({ + 'name': 'test_edit_moveline_1', + 'location_id': self.stock_location.id, + 'location_dest_id': self.customer_location.id, + 'product_id': self.product2.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 4.0, + }) + move._action_confirm() + move._action_assign() + + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 4.0) + move._action_assign() + + self.assertEqual(len(move.move_line_ids), 4.0) + def test_unreserve_1(self): """ Check that unreserving a stock move sets the products reserved as available and set the state back to confirmed.