changeset 3ac82644ead6 in modules/stock_inventory_location:default
details:
https://hg.tryton.org/modules/stock_inventory_location?cmd=changeset;node=3ac82644ead6
description:
Add empty quantity and complete lines options
issue9563
review290881002
diffstat:
CHANGELOG | 2 +
inventory.py | 58 ++++++++++++++++++++++++++++-------
tests/scenario_stock_inventories.rst | 9 ++---
view/inventory_create_start_form.xml | 5 +++
4 files changed, 57 insertions(+), 17 deletions(-)
diffs (139 lines):
diff -r 278d87a40a0f -r 3ac82644ead6 CHANGELOG
--- a/CHANGELOG Sat Oct 03 23:49:35 2020 +0200
+++ b/CHANGELOG Sat Oct 03 23:49:59 2020 +0200
@@ -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 -r 278d87a40a0f -r 3ac82644ead6 inventory.py
--- a/inventory.py Sat Oct 03 23:49:35 2020 +0200
+++ b/inventory.py Sat Oct 03 23:49:59 2020 +0200
@@ -12,13 +12,43 @@
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 @@
])
create_ = StateAction('stock.act_inventory_form')
- def do_create_(self, action):
- Inventory = Pool().get('stock.inventory')
+ def get_inventory(self, location, Inventory):
+ return Inventory(
+ location=location,
+ date=self.start.date,
+ company=self.start.company,
+ empty_quantity=self.start.empty_quantity)
- 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)
+ def do_create_(self, action):
+ pool = Pool()
+ Inventory = pool.get('stock.inventory')
- Inventory.complete_lines(inventories)
+ inventories = [
+ self.get_inventory(location, Inventory)
+ for location in self.start.locations]
+ Inventory.save(inventories)
+
+ if self.start.complete_lines:
+ Inventory.complete_lines(inventories)
data = {'res_id': [i.id for i in inventories]}
return action, data
diff -r 278d87a40a0f -r 3ac82644ead6 tests/scenario_stock_inventories.rst
--- a/tests/scenario_stock_inventories.rst Sat Oct 03 23:49:35 2020 +0200
+++ b/tests/scenario_stock_inventories.rst Sat Oct 03 23:49:59 2020 +0200
@@ -4,12 +4,9 @@
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 @@
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 @@
2
>>> {i.location for i in inventories} == {storage_loc, storage_loc2}
True
+ >>> inventories[0].empty_quantity
+ 'keep'
diff -r 278d87a40a0f -r 3ac82644ead6 view/inventory_create_start_form.xml
--- a/view/inventory_create_start_form.xml Sat Oct 03 23:49:35 2020 +0200
+++ b/view/inventory_create_start_form.xml Sat Oct 03 23:49:59 2020 +0200
@@ -7,5 +7,10 @@
<label name="company"/>
<field name="company"/>
+ <label name="empty_quantity"/>
+ <field name="empty_quantity"/>
+ <label name="complete_lines"/>
+ <field name="complete_lines"/>
+
<field name="locations" colspan="4" view_ids="stock.location_view_list"/>
</form>