diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index c89b5a57c6b2d741493124207aed0eb38bc49c5a..263e975c5e257e990a176a3eea8a8bfa1bcbb11d 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -562,6 +562,8 @@ Please change the quantity done or the rounding precision of your unit of measur def _set_lot_ids(self): for move in self: + if move.product_id.tracking != 'serial': + continue move_lines_commands = [] if move.picking_type_id.show_reserved is False: mls = move.move_line_nosuggest_ids diff --git a/addons/stock/tests/test_robustness.py b/addons/stock/tests/test_robustness.py index 75f78d49863c0c93b21a4260b1b173d4dc64c930..bbeb4ec7dbb69d5ab78a590348efe6c543864d27 100644 --- a/addons/stock/tests/test_robustness.py +++ b/addons/stock/tests/test_robustness.py @@ -221,3 +221,42 @@ class TestRobustness(TransactionCase): 'location_id': move2.location_id.id, 'location_dest_id': move2.location_dest_id.id, })]}) + + def test_lot_quantity_remains_unchanged_after_done(self): + """ Make sure the method _set_lot_ids does not change the quantities of lots to 1 once they are done. + """ + productA = self.env['product.product'].create({ + 'name': 'ProductA', + 'type': 'product', + 'categ_id': self.env.ref('product.product_category_all').id, + 'tracking': 'lot', + }) + lotA = self.env['stock.lot'].create({ + 'name': 'lotA', + 'product_id': productA.id, + 'company_id': self.env.company.id, + + }) + self.env['stock.quant']._update_available_quantity(productA, self.stock_location, 5, lot_id=lotA) + moveA = self.env['stock.move'].create({ + 'name': 'TEST_A', + 'location_id': self.stock_location.id, + 'location_dest_id': self.customer_location.id, + 'product_id': productA.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 5.0, + }) + + moveA._action_confirm() + moveA.write({'move_line_ids': [(0, 0, { + 'product_id': productA.id, + 'product_uom_id': self.uom_unit.id, + 'qty_done': 5, + 'lot_id': lotA.id, + 'location_id': moveA.location_id.id, + 'location_dest_id': moveA.location_dest_id.id, + })]}) + moveA._action_done() + moveA._set_lot_ids() + + self.assertEqual(moveA.quantity_done, 5)