[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) <whe@odoo.com>
Signed-off-by: Walravens Mathieu (wama) <wama@odoo.com>
This commit is contained in:
Mathieu Walravens
2023-06-27 10:42:52 +02:00
parent ca4ba84d98
commit 9163f98f0e
+3 -1
View File
@@ -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: