From d1ba6acfcf464fd5ccae842ec8ba78570dc2bc7b Mon Sep 17 00:00:00 2001 From: Mathieu Walravens Date: Fri, 1 Dec 2023 18:20:25 +0100 Subject: [PATCH] [FIX] stock: allow writing recordsets on move lines Before this commit: Calling `env["stock.move.line"].write({"lot_id": lot_id})` with `lot_id` as a recordset instead of an id does not work. However, this is supported by the base model `write` method. Steps to reproduce: 1. Create a product A without tracking 2. Set product A's quantity to 10 3. Create an internal transfer to move 10 quantities of product A from Stock to Production 4. Change product A's tracking method to track by lot 5. Create a BoM for A with component B 6. Set product B quantity to 10 7. Produce 10 quantities of product A by creating a manufacturing 8. A traceback prevent marking the MO as done opw-3620539 closes odoo/odoo#145346 X-original-commit: 2fa53e84fadc79a03d5d6b7134496a16b1edaf2a Signed-off-by: Quentin Wolfs (quwo) Signed-off-by: Walravens Mathieu (wama) --- addons/stock/models/stock_move_line.py | 2 +- addons/stock/tests/test_move.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index a6167161b6c..d87890838f3 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -385,7 +385,7 @@ class StockMoveLine(models.Model): updates = {} for key, model in triggers: if key in vals: - updates[key] = self.env[model].browse(vals[key]) + updates[key] = vals[key] if isinstance(vals[key], models.BaseModel) else self.env[model].browse(vals[key]) if 'result_package_id' in updates: for ml in self.filtered(lambda ml: ml.package_level_id): diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index e115757f1b1..321d16b8007 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -4161,7 +4161,7 @@ class StockMove(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1, package_id=package1), 1.0) - move1.move_line_ids.write({'lot_id': lot2.id}) + move1.move_line_ids.write({'lot_id': lot2}) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location), 1.0) self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_lot, self.stock_location, lot_id=lot1), 0.0)