From 8a6ff86324cd70f3d4bdbbf06621af14ea44ef26 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Thu, 17 Feb 2022 09:17:31 +0000 Subject: [PATCH] [FIX] stock: prevent useless SML creation in inventory mode Some useless SMLs are generated when editing the on hand quantity in inventory mode To reproduce the issue: 1. Create a storable product P 2. Update its on hand quantity to 100 3. Inventory > Reporting > Inventory Report 4. On the line for P, update to quantity to 75 5. Inventory > Reporting > Product Moves, search for P Error: There are two SMLs with a quantity equal to zero Calling `action_apply_inventory` from the `write` is useless since the method is already called in the inversed method of `inventory_quantity_auto_apply` OPW-2739833 closes odoo/odoo#85152 X-original-commit: c2164fba4a9049115a6a46de28a90fc779fb9eee Signed-off-by: Arnold Moyaux --- addons/stock/models/stock_quant.py | 4 ---- addons/stock/tests/test_quant_inventory_mode.py | 8 ++++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index c09204b2892..e00242fe675 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -309,10 +309,6 @@ class StockQuant(models.Model): if any(field for field in vals.keys() if field not in allowed_fields): raise UserError(_("Quant's editing is restricted, you can't do this operation.")) self = self.sudo() - res = super(StockQuant, self).write(vals) - if res and self.env.context.get('inventory_report_mode'): - self.action_apply_inventory() - return res return super(StockQuant, self).write(vals) def action_view_stock_moves(self): diff --git a/addons/stock/tests/test_quant_inventory_mode.py b/addons/stock/tests/test_quant_inventory_mode.py index 704624d8804..3886ce6ca38 100644 --- a/addons/stock/tests/test_quant_inventory_mode.py +++ b/addons/stock/tests/test_quant_inventory_mode.py @@ -239,6 +239,14 @@ class TestEditableQuant(TransactionCase): 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) + quant.with_context(inventory_report_mode=True).inventory_quantity_auto_apply = 75 + self.assertEqual(self.product.qty_available, 75) + smls = self.env['stock.move.line'].search([('product_id', '=', self.product.id)]) + self.assertRecordValues(smls, [ + {'qty_done': 100}, + {'qty_done': 25}, + {'qty_done': 0}, + ]) def test_sn_warning(self): """ Checks that a warning is given when reusing an existing SN