From 7e58f703f449a09f27aa4a5ce6f2729aa471d7f7 Mon Sep 17 00:00:00 2001 From: vevi-odoo Date: Tue, 12 Dec 2023 14:04:34 +0530 Subject: [PATCH] [FIX] stock: calculate sum of quantity mapped with quant This traceback arises when the user tries to click on 'Lot/ serial Number' in Create Move Line To reproduce this issue: 1. Install 'stock' 2. Create a new record in Lot and Serial Number from 'products/Lot and Serial Numbers' 3. Now go to 'operations/Transfers/Deliveries' 4. Create a new record and select the above-created 'Lot and serials' product 5. Save the record and click 'Mark as Todo' 6. Click on the 'Detailed Operations' button and add a line 7. Set the quantity 8. Again add a line click on new then select Lot/serial Number ValueError: Expected singleton: stock.quant(5, 24) when the user tries to click on 'Lot/serial Number' in Create Move Line a value error occurs because getting many values excepted single value Which leads to the traceback from here https://github.com/odoo/odoo/blob/230b680bf92583c9f5e4a3739be1d8602df44331/addons/stock/models/stock_quant.py#L905-L929 After applying this commit will resolve the issue of getting a sum of quantity mapped with the quant sentry-4715604118 closes odoo/odoo#146560 X-original-commit: c7612dfc4349bc9b21a48ca5192523f180f9b5e8 Signed-off-by: William Henrotin (whe) --- addons/stock/models/stock_quant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 84e7b5596dd..ac1a814636d 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -917,7 +917,7 @@ class StockQuant(models.Model): self.product_id, self.location_id, lot_id=self.lot_id, package_id=self.package_id, owner_id=self.owner_id, strict=True) if quant: - self.quantity = quant.filtered(lambda q: q.lot_id == self.lot_id).quantity + self.quantity = sum(quant.filtered(lambda q: q.lot_id == self.lot_id).mapped('quantity')) # Special case: directly set the quantity to one for serial numbers, # it'll trigger `inventory_quantity` compute.