diff --git a/CHANGELOG b/CHANGELOG
index 0fc533228a..81ab759040 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add empty quantity and complete lines options
+
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
diff --git a/inventory.py b/inventory.py
index 4eecfbcec8..76e6ce8f16 100644
--- a/inventory.py
+++ b/inventory.py
@@ -12,13 +12,43 @@ class CreateInventoriesStart(ModelView):
date = fields.Date('Date', required=True)
company = fields.Many2One('company.company', 'Company', required=True,
select=True)
+ empty_quantity = fields.Selection(
+ 'get_empty_quantities', "Empty Quantity",
+ help="How lines without a quantity are handled.")
+ complete_lines = fields.Boolean(
+ "Complete",
+ help="Add an inventory line for each missing product.")
locations = fields.Many2Many('stock.location', None, None,
'Locations', required=True, domain=[('type', '=', 'storage')])
+ @classmethod
+ def default_date(cls):
+ return Pool().get('ir.date').today()
+
@staticmethod
def default_company():
return Transaction().context.get('company')
+ @classmethod
+ def get_empty_quantities(cls):
+ pool = Pool()
+ Inventory = pool.get('stock.inventory')
+ return Inventory.fields_get(
+ ['empty_quantity'])['empty_quantity']['selection']
+
+ @classmethod
+ def default_empty_quantity(cls):
+ pool = Pool()
+ Inventory = pool.get('stock.inventory')
+ try:
+ return Inventory.default_empty_quantity()
+ except AttributeError:
+ return
+
+ @classmethod
+ def default_complete_lines(cls):
+ return True
+
class CreateInventories(Wizard):
'Create Inventories'
@@ -30,20 +60,24 @@ class CreateInventories(Wizard):
])
create_ = StateAction('stock.act_inventory_form')
+ def get_inventory(self, location, Inventory):
+ return Inventory(
+ location=location,
+ date=self.start.date,
+ company=self.start.company,
+ empty_quantity=self.start.empty_quantity)
+
def do_create_(self, action):
- Inventory = Pool().get('stock.inventory')
+ pool = Pool()
+ Inventory = pool.get('stock.inventory')
- to_create = []
- for location in self.start.locations:
- to_create.append({
- 'location': location.id,
- 'date': self.start.date,
- 'company': self.start.company.id,
- })
- if to_create:
- inventories = Inventory.create(to_create)
+ inventories = [
+ self.get_inventory(location, Inventory)
+ for location in self.start.locations]
+ Inventory.save(inventories)
- Inventory.complete_lines(inventories)
+ if self.start.complete_lines:
+ Inventory.complete_lines(inventories)
data = {'res_id': [i.id for i in inventories]}
return action, data
diff --git a/tests/scenario_stock_inventories.rst b/tests/scenario_stock_inventories.rst
index 89e8b7f24d..a8a133d171 100644
--- a/tests/scenario_stock_inventories.rst
+++ b/tests/scenario_stock_inventories.rst
@@ -4,12 +4,9 @@ Stock Inventories Scenario
Imports::
- >>> import datetime as dt
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
- >>> from trytond.modules.company.tests.tools import create_company, \
- ... get_company
- >>> today = dt.date.today()
+ >>> from trytond.modules.company.tests.tools import create_company
Activate modules::
@@ -29,7 +26,7 @@ Get stock locations::
Create inventories::
>>> create = Wizard('stock.inventory.create')
- >>> create.form.date = today
+ >>> create.form.empty_quantity = 'keep'
>>> create.form.locations.extend(Location.find([('code', '=', 'STO')]))
>>> create.execute('create_')
@@ -38,3 +35,5 @@ Create inventories::
2
>>> {i.location for i in inventories} == {storage_loc, storage_loc2}
True
+ >>> inventories[0].empty_quantity
+ 'keep'
diff --git a/view/inventory_create_start_form.xml b/view/inventory_create_start_form.xml
index 39ef3c7d27..5ac5b5b8c7 100644
--- a/view/inventory_create_start_form.xml
+++ b/view/inventory_create_start_form.xml
@@ -7,5 +7,10 @@ this repository contains the full copyright notices and license terms. -->
+
+
+
+
+