[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) <quwo@odoo.com>
Signed-off-by: Walravens Mathieu (wama) <wama@odoo.com>
This commit is contained in:
Mathieu Walravens
2023-12-07 10:08:02 +00:00
parent f0c9377662
commit d1ba6acfcf
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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):
+1 -1
View File
@@ -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)