[IMP] stock: inventory_quantity_set own compute
Sets the `inventory_quantity_set` as an editable field (not readonly) and creates its own compute to avoid to override it each time the `inventory_quantity` is modify and we set the `inventory_quantity_set` aside (before this commit, this field new value was always overrided by the `inventory_diff_quantity` compute). This is useful when we want to write on the quants from the Barcode App as we can write on `inventory_quantity` and `inventory_quantity_set` at the same time. task-2632818 closes odoo/odoo#78719 X-original-commit: 489e76ade600f7983a9a1976c04529ac542fdd44 Related: odoo/enterprise#21810 Signed-off-by: Rémy Voet <ryv-odoo@users.noreply.github.com> Signed-off-by: Steve Van Essche <svs-odoo@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user