Add empty quantity and complete lines options
issue9563 review290881002
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+45
-11
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -7,5 +7,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user