diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 7f55a0ea349..221055d5ea4 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -311,8 +311,7 @@ class StockQuant(models.Model): self = self.sudo() res = super(StockQuant, self).write(vals) if res and self.env.context.get('inventory_report_mode'): - # update context to prevent recursive write call - self.with_context({'inventory_report_mode': False}).action_apply_inventory() + self.action_apply_inventory() return res return super(StockQuant, self).write(vals) @@ -365,6 +364,8 @@ class StockQuant(models.Model): return action def action_apply_inventory(self): + # Update the context to prevent recursive call from write method + self = self.with_context({'inventory_report_mode': False}) products_tracked_without_lot = [] for quant in self: rounding = quant.product_uom_id.rounding diff --git a/addons/stock/tests/test_quant_inventory_mode.py b/addons/stock/tests/test_quant_inventory_mode.py index 602317c53ef..704624d8804 100644 --- a/addons/stock/tests/test_quant_inventory_mode.py +++ b/addons/stock/tests/test_quant_inventory_mode.py @@ -226,6 +226,20 @@ class TestEditableQuant(TransactionCase): quant.action_apply_inventory() self.assertEqual(quant.quantity, 8) + def test_edit_quant_4(self): + """ Update the quantity with the inventory report mode """ + default_wh = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1) + default_stock_location = default_wh.lot_stock_id + quant = self.Quant.create({ + 'product_id': self.product.id, + 'location_id': default_stock_location.id, + 'inventory_quantity': 100, + }) + quant.action_apply_inventory() + self.assertEqual(self.product.qty_available, 100) + quant.with_context(inventory_report_mode=True).inventory_quantity_auto_apply = 75 + self.assertEqual(self.product.qty_available, 75) + def test_sn_warning(self): """ Checks that a warning is given when reusing an existing SN in inventory mode.