[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 <arm@odoo.com>
This commit is contained in:
Adrien Widart
2022-02-22 17:11:09 +00:00
parent 56719fc380
commit 8a6ff86324
2 changed files with 8 additions and 4 deletions
-4
View File
@@ -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):
@@ -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