From 9163f98f0ef9d2ce5800a85540a009f44f4fd312 Mon Sep 17 00:00:00 2001 From: Mathieu Walravens Date: Wed, 7 Jun 2023 15:49:10 +0000 Subject: [PATCH] [FIX] stock: prevent merging quants during import Before this commit: When importing `stock.quant` with two lines with the same product and different counted quantities, only the last line is taken. After this commit: Each line creates a `stock.quant`, even if a similar Quant exists. The records will be merged at a later time by `_merge_quants`. Steps to reproduce: 1. Create a storable product 2. Go to Inventory > Operations > Inventory Adjustments 3. Create a file with two lines with the same product, and different counted quantities 5. Favourites > Import Records & upload the file OPW-3340017 closes odoo/odoo#126480 X-original-commit: 45f7368222ead5df600992c66f0da56b3a7e959a Signed-off-by: William Henrotin (whe) Signed-off-by: Walravens Mathieu (wama) --- addons/stock/models/stock_quant.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 870c55887de..9168c1d9e55 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -263,7 +263,9 @@ class StockQuant(models.Model): lot_id = self.env['stock.lot'].browse(vals.get('lot_id')) package_id = self.env['stock.quant.package'].browse(vals.get('package_id')) owner_id = self.env['res.partner'].browse(vals.get('owner_id')) - quant = self._gather(product, location, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True) + if not self.env.context.get('import_file'): + # Merge quants later, to make sure one line = one record during batch import + quant = self._gather(product, location, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True) if lot_id: quant = quant.filtered(lambda q: q.lot_id) if quant: