diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 3e26e4036a8..4e59c8a81a5 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -110,7 +110,7 @@ class StockQuant(models.Model): inventory_date = fields.Date( 'Scheduled Date', compute='_compute_inventory_date', store=True, readonly=False, help="Next date the On Hand Quantity should be counted.") - inventory_quantity_set = fields.Boolean() # Only used for UI purposes in the Inventory Adjustment page + inventory_quantity_set = fields.Boolean(store=True, compute='_compute_inventory_quantity_set', readonly=False) is_outdated = fields.Boolean('Quantity has been moved since last count', compute='_compute_is_outdated') user_id = fields.Many2one( 'res.users', 'Assigned To', help="User assigned to do product count.") @@ -130,9 +130,12 @@ class StockQuant(models.Model): @api.depends('inventory_quantity') def _compute_inventory_diff_quantity(self): for quant in self: - quant.inventory_quantity_set = True quant.inventory_diff_quantity = quant.inventory_quantity - quant.quantity + @api.depends('inventory_quantity') + def _compute_inventory_quantity_set(self): + self.inventory_quantity_set = True + @api.depends('inventory_quantity', 'quantity', 'product_id') def _compute_is_outdated(self): self.is_outdated = False diff --git a/addons/stock/tests/test_inventory.py b/addons/stock/tests/test_inventory.py index 59be98876b5..3794e4ee42e 100644 --- a/addons/stock/tests/test_inventory.py +++ b/addons/stock/tests/test_inventory.py @@ -305,13 +305,23 @@ class TestInventory(TransactionCase): 'location_id': self.stock_location.id, 'inventory_quantity': 42, }) - # Generate new inventory, its line must have a theoretical - # quantity of 42 and a counted quantity to 0. + # Applies the change, the quant must have a quantity of 42 and a inventory quantity to 0. inventory_quant.action_apply_inventory() self.assertEqual(len(inventory_quant), 1) self.assertEqual(inventory_quant.inventory_quantity, 0) self.assertEqual(inventory_quant.quantity, 42) + # Checks we can write on `inventory_quantity_set` even if we write on + # `inventory_quantity` at the same time. + self.assertEqual(inventory_quant.inventory_quantity_set, False) + inventory_quant.write({'inventory_quantity': 5}) + self.assertEqual(inventory_quant.inventory_quantity_set, True) + inventory_quant.write({ + 'inventory_quantity': 12, + 'inventory_quantity_set': False, + }) + self.assertEqual(inventory_quant.inventory_quantity_set, False) + def test_inventory_outdate_1(self): """ Checks that applying an inventory adjustment that is outdated due to its corresponding quant being modified after its inventory quantity is set