Implement business process module.

This commit refs #829
This commit is contained in:
Sergio Morillo 2015-09-21 12:13:12 +02:00
parent 163e43fe05
commit c1086ae4b6
9 changed files with 51 additions and 23 deletions

View file

@ -62,10 +62,6 @@ msgctxt "model:stock.product.category.location,name:"
msgid "Product Category Location"
msgstr "Ubicación de categoría de producto"
msgctxt "selection:stock.product.category.location,process:"
msgid "All"
msgstr "Todos"
msgctxt "view:product.category:"
msgid "Locations"
msgstr "Ubicaciones"

View file

@ -30,16 +30,15 @@ class ProductCategoryLocation(ModelSQL, ModelView):
domain=[
('type', '=', 'storage'), ('parent', 'child_of', Eval('warehouse'))],
depends=['warehouse'])
process = fields.Selection(
[('all', 'All')], 'Process', required=True, select=True, translate=True)
process = fields.Many2One('business.process', 'Process',
ondelete='RESTRICT', select=True)
sequence = fields.Integer('Sequence')
@classmethod
def __setup__(cls):
super(ProductCategoryLocation, cls).__setup__()
cls._sql_constraints = [('_uk1',
'UNIQUE(category, location, process)',
'Category, location and process must be unique.')]
cls._error_messages.update({
'unique_key': 'Category, location and process must be unique.'})
@staticmethod
def _compute_sequence(table, record):
@ -78,7 +77,33 @@ class ProductCategoryLocation(ModelSQL, ModelView):
@staticmethod
def default_process():
return "all"
return None
@staticmethod
def order_process(tables):
table, _ = tables[None]
return [table.process != None, table.process]
def _get_unique_key(self):
return (self.category.id, self.location.id,
self.process.id if self.process else None)
@classmethod
def validate(cls, records):
values = {}
for record in records:
_uq = record._get_unique_key()
if values.get(_uq):
cls.raise_user_error('unique_key')
values.setdefault(_uq, 1)
others = cls.search([('id', 'not in', map(int, records))])
for other in others:
_uq = other._get_unique_key()
if values.get(_uq):
cls.raise_user_error('unique_key')
super(ProductCategoryLocation, cls).validate(records)
class Location:

View file

@ -16,18 +16,24 @@ class Category:
default_location = fields.Function(fields.Many2One('stock.location', 'Default location'),
'get_default_location')
def get_default_location(self, warehouse=None, process='all'):
def get_default_location(self, warehouse=None,
process=None,
location_type='storage'):
pool = Pool()
Location = pool.get('stock.product.category.location')
process_ids = [None]
if process:
process_ids.append(process.id)
_domain = [('category', '=', self.id),
('process', 'in', [process, 'all'])]
('location.type', '=', location_type),
('process', 'in', process_ids)]
if warehouse:
_domain.append(('warehouse', '=', warehouse.id))
locations = Location.search(_domain, order=[('sequence', 'ASC')])
locations = Location.search(_domain,
order=[('process', 'DESC'),
('sequence', 'ASC')],
limit=2)
if locations:
for location in locations:
if location.process == process:
return location.location.id
return locations[0].location.id
return None

View file

@ -54,4 +54,4 @@ Check sequence compute in locations form::
>>> test_storage.save()
>>> test_storage.reload()
>>> test_storage.categories[0].sequence
2
2

View file

@ -19,6 +19,7 @@ class StockProductCategoryLocationTestCase(ModuleTestCase):
self.location = POOL.get('stock.location')
self.category = POOL.get('product.category')
self.cat_loc = POOL.get('stock.product.category.location')
self.process = POOL.get('business.process')
def test0010_add_category_default_location(self):
"""Add the category default location for a warehouse"""
@ -30,7 +31,7 @@ class StockProductCategoryLocationTestCase(ModuleTestCase):
'category': new_cat.id,
'warehouse': storage.parent.id,
'location': storage.id,
'process': 'all'
'process': None
}
self.cat_loc.create([cat_loc_rec])
transaction.cursor.commit()
@ -45,13 +46,12 @@ class StockProductCategoryLocationTestCase(ModuleTestCase):
'category': new_cat.id,
'warehouse': storage.parent.id,
'location': storage.id,
'process': 'all'
'process': None
}
with self.assertRaises(UserError) as cm:
self.cat_loc.create([cat_loc_rec])
self.assertEqual(
cm.exception.message, 'Category, location and process must be unique.')
transaction.cursor.commit()
def suite():

View file

@ -1,6 +1,7 @@
[tryton]
version=3.6.1
depends:
business_process
ir
res
stock_location_notebook

View file

@ -9,5 +9,5 @@
<label name="location"/>
<field name="location"/>
<label name="process"/>
<field name="process"/>
<field name="process" widget="selection"/>
</form>

View file

@ -4,5 +4,5 @@
<tree string="Category Locations" editable="bottom">
<field name="category"/>
<field name="location"/>
<field name="process"/>
<field name="process" widget="selection"/>
</tree>

View file

@ -5,6 +5,6 @@
<field name="category"/>
<field name="warehouse"/>
<field name="location"/>
<field name="process"/>
<field name="process" widget="selection"/>
<field name="sequence" tree_invisible="1"/>
</tree>