[IMP] stock: prefill_counted_quantity as selection
Changes the type of `prefill_counted_quantity` from boolean to selection to have a label for each option. This change is only for a functional purpose. Task #2043851
This commit is contained in:
@@ -68,9 +68,10 @@ class Inventory(models.Model):
|
||||
help="Specify Products to focus your inventory on particular Products.")
|
||||
start_empty = fields.Boolean('Empty Inventory',
|
||||
help="Allows to start with an empty inventory.")
|
||||
prefill_counted_quantity = fields.Boolean('Pre-fill counted quantity',
|
||||
help='Pre-fill the counted quantity with on hand quantity for all the '
|
||||
'products included in the inventory adjustment.', default=True)
|
||||
prefill_counted_quantity = fields.Selection(string='Counted Quantities',
|
||||
help="Allows to start with prefill counted quantity for each lines or "
|
||||
"with all counted quantity set to zero.", default='counted',
|
||||
selection=[('counted', 'Default to stock on hand'), ('zero', 'Default to zero')])
|
||||
|
||||
def unlink(self):
|
||||
for inventory in self:
|
||||
@@ -233,7 +234,7 @@ class Inventory(models.Model):
|
||||
for void_field in [item[0] for item in product_data.items() if item[1] is None]:
|
||||
product_data[void_field] = False
|
||||
product_data['theoretical_qty'] = product_data['product_qty']
|
||||
if not self.prefill_counted_quantity:
|
||||
if self.prefill_counted_quantity == 'zero':
|
||||
product_data['product_qty'] = 0
|
||||
if product_data['product_id']:
|
||||
product_data['product_uom_id'] = Product.browse(product_data['product_id']).uom_id.id
|
||||
|
||||
@@ -323,7 +323,7 @@ class TestInventory(SavepointCase):
|
||||
'reserved_quantity': 0,
|
||||
})
|
||||
inventory_form = Form(self.env['stock.inventory'].with_context(
|
||||
default_prefill_counted_quantity=False,
|
||||
default_prefill_counted_quantity='zero',
|
||||
), view='stock.view_inventory_form')
|
||||
inventory = inventory_form.save()
|
||||
inventory.action_start()
|
||||
@@ -333,6 +333,43 @@ class TestInventory(SavepointCase):
|
||||
self.assertEqual(line.product_qty, 0)
|
||||
self.assertNotEqual(line.theoretical_qty, 0)
|
||||
|
||||
def test_inventory_prefill_counted_quantity(self):
|
||||
""" Checks that inventory lines have a `product_qty` set on zero or
|
||||
equals to quantity on hand, depending of the `prefill_counted_quantity`.
|
||||
"""
|
||||
# Set product quantity to 42.
|
||||
vals = {
|
||||
'product_id': self.product1.id,
|
||||
'location_id': self.stock_location.id,
|
||||
'quantity': 42,
|
||||
}
|
||||
self.env['stock.quant'].create(vals)
|
||||
# Generate new inventory, its line must have a theoretical
|
||||
# quantity to 42 and a counted quantity to 42.
|
||||
inventory = self.env['stock.inventory'].create({
|
||||
'name': 'Default Qty',
|
||||
'location_ids': [(4, self.stock_location.id)],
|
||||
'product_ids': [(4, self.product1.id)],
|
||||
'prefill_counted_quantity': 'counted',
|
||||
})
|
||||
inventory.action_start()
|
||||
self.assertEqual(len(inventory.line_ids), 1)
|
||||
self.assertEqual(inventory.line_ids.theoretical_qty, 42)
|
||||
self.assertEqual(inventory.line_ids.product_qty, 42)
|
||||
|
||||
# Generate new inventory, its line must have a theoretical
|
||||
# quantity to 42 and a counted quantity to 0.
|
||||
inventory = self.env['stock.inventory'].create({
|
||||
'name': 'Default Qty',
|
||||
'location_ids': [(4, self.stock_location.id)],
|
||||
'product_ids': [(4, self.product1.id)],
|
||||
'prefill_counted_quantity': 'zero',
|
||||
})
|
||||
inventory.action_start()
|
||||
self.assertEqual(len(inventory.line_ids), 1)
|
||||
self.assertEqual(inventory.line_ids.theoretical_qty, 42)
|
||||
self.assertEqual(inventory.line_ids.product_qty, 0)
|
||||
|
||||
def test_inventory_outdate_1(self):
|
||||
""" Checks that inventory adjustment line is marked as outdated after
|
||||
its corresponding quant is modify and its value was correctly updated
|
||||
|
||||
@@ -185,7 +185,7 @@
|
||||
</group>
|
||||
<group>
|
||||
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
|
||||
<field name="prefill_counted_quantity"
|
||||
<field name="prefill_counted_quantity" widget="radio"
|
||||
attrs="{'invisible': [('state', '!=', 'draft')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user