diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index 1c004048ddc..d345a0be68a 100644 --- a/addons/stock/models/stock_inventory.py +++ b/addons/stock/models/stock_inventory.py @@ -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 diff --git a/addons/stock/tests/test_inventory.py b/addons/stock/tests/test_inventory.py index f93e388f09b..d1be07924d3 100644 --- a/addons/stock/tests/test_inventory.py +++ b/addons/stock/tests/test_inventory.py @@ -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 diff --git a/addons/stock/views/stock_inventory_views.xml b/addons/stock/views/stock_inventory_views.xml index 259f1803d63..ca1ff1f1a20 100644 --- a/addons/stock/views/stock_inventory_views.xml +++ b/addons/stock/views/stock_inventory_views.xml @@ -185,7 +185,7 @@ -