[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) <whe@odoo.com>
This commit is contained in:
vevi-odoo
2023-12-18 14:34:20 +00:00
parent 58d2429c48
commit 7e58f703f4
+1 -1
View File
@@ -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.