[IMP] stock: allow to start inv. adj. with 0 qty

Add an Inventory Adjustment field `prefill_counted_quantity`.
True by default, when it's disabled, the inventory will generate when
inventory lines with 0 as value for `product_qty` field when started.

The purpose is to make simpler the use of barcode scanner to do the
inventory adjustment.

Task #2026952
This commit is contained in:
svs-odoo
2019-06-26 08:58:31 +00:00
parent e719824271
commit 68e96fbe13
3 changed files with 23 additions and 1 deletions
+5
View File
@@ -69,6 +69,9 @@ 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)
def unlink(self):
for inventory in self:
@@ -231,6 +234,8 @@ 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:
product_data['product_qty'] = 0
if product_data['product_id']:
product_data['product_uom_id'] = Product.browse(product_data['product_id']).uom_id.id
quant_products |= Product.browse(product_data['product_id'])
+16 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase
from odoo.tests.common import Form, SavepointCase
class TestInventory(SavepointCase):
@@ -311,6 +311,21 @@ class TestInventory(SavepointCase):
self.assertEqual(len(inventory.line_ids), 1)
self.assertEqual(inventory.line_ids.theoretical_qty, 2)
def test_inventory_8(self):
""" Check inventory lines product quantity is 0 when inventory is
started with `prefill_counted_quantity` disable.
"""
inventory_form = Form(self.env['stock.inventory'].with_context(
default_prefill_counted_quantity=False,
), view='stock.view_inventory_form')
inventory = inventory_form.save()
inventory.action_start()
self.assertNotEqual(len(inventory.line_ids), 0)
# Checks all inventory lines quantities are correctly set.
for line in inventory.line_ids:
self.assertEqual(line.product_qty, 0)
self.assertNotEqual(line.theoretical_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
@@ -181,6 +181,8 @@
</group>
<group>
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="prefill_counted_quantity"
attrs="{'invisible': [('state', '!=', 'draft')]}"/>
</group>
</group>
<div attrs="{'invisible': [('state', '=', 'done')]}">