mirror of
https://gitlab.com/datalifeit/trytond-stock_product_category_location
synced 2023-12-14 04:33:11 +01:00
Reformat code
This commit is contained in:
parent
1f25066ba0
commit
1f930234f1
54
location.py
54
location.py
|
@ -11,25 +11,27 @@ __all__ = ['ProductCategoryLocation', 'Location']
|
|||
|
||||
|
||||
class ProductCategoryLocation(ModelSQL, ModelView):
|
||||
"""
|
||||
Product Category Location
|
||||
It defines the default storage location by warehouse for a product category.
|
||||
"""
|
||||
"""Product Category Location"""
|
||||
__name__ = 'stock.product.category.location'
|
||||
|
||||
category = fields.Many2One(
|
||||
'product.category', 'Category', required=True, select=True, ondelete='CASCADE')
|
||||
'product.category', 'Category', required=True,
|
||||
select=True, ondelete='CASCADE')
|
||||
warehouse = fields.Many2One('stock.location', 'Warehouse', required=True,
|
||||
domain=[('type', '=', 'warehouse')],
|
||||
states={
|
||||
'invisible': Bool(Eval('context', {}).get('current_location', None)),
|
||||
'readonly': Bool(Eval('context', {}).get('current_location', None)),
|
||||
},
|
||||
ondelete='CASCADE')
|
||||
location = fields.Many2One('stock.location', 'Storage Location', required=True, ondelete='CASCADE',
|
||||
domain=[
|
||||
('type', '=', 'storage'), ('parent', 'child_of', Eval('warehouse'))],
|
||||
depends=['warehouse'])
|
||||
domain=[('type', '=', 'warehouse')],
|
||||
states={
|
||||
'invisible': Bool(
|
||||
Eval('context', {}).get('current_location', None)),
|
||||
'readonly': Bool(
|
||||
Eval('context', {}).get('current_location', None)),
|
||||
},
|
||||
ondelete='CASCADE')
|
||||
location = fields.Many2One('stock.location', 'Storage Location',
|
||||
required=True, ondelete='CASCADE',
|
||||
domain=[
|
||||
('type', '=', 'storage'),
|
||||
('parent', 'child_of', Eval('warehouse'))
|
||||
], depends=['warehouse'])
|
||||
sequence = fields.Integer('Sequence')
|
||||
|
||||
@classmethod
|
||||
|
@ -48,7 +50,8 @@ class ProductCategoryLocation(ModelSQL, ModelView):
|
|||
cursor = Transaction().connection.cursor()
|
||||
seq_sel = table.select(
|
||||
Max(table.sequence).as_('max_sequence'))
|
||||
seq_sel.where = ProductCategoryLocation._compute_sequence_where(table, record)
|
||||
seq_sel.where = ProductCategoryLocation._compute_sequence_where(
|
||||
table, record)
|
||||
cursor.execute(*seq_sel)
|
||||
rec = cursor.fetchall()[0]
|
||||
return rec[0] + 1 if rec[0] else 1
|
||||
|
@ -100,13 +103,18 @@ class ProductCategoryLocation(ModelSQL, ModelView):
|
|||
class Location(metaclass=PoolMeta):
|
||||
__name__ = 'stock.location'
|
||||
|
||||
categories = fields.One2Many('stock.product.category.location', 'location', 'Categories',
|
||||
states={
|
||||
'invisible': Not(Equal(Eval('type'), 'storage'))},
|
||||
context={'current_location': Eval('id')})
|
||||
wh_categories = fields.One2Many('stock.product.category.location', 'warehouse',
|
||||
'Categories', states={'invisible': Not(Equal(Eval('type'), 'warehouse'))},
|
||||
context={'current_location': Eval('id')})
|
||||
categories = fields.One2Many('stock.product.category.location',
|
||||
'location', 'Categories',
|
||||
states={
|
||||
'invisible': Not(Equal(Eval('type'), 'storage'))
|
||||
},
|
||||
context={'current_location': Eval('id')})
|
||||
wh_categories = fields.One2Many('stock.product.category.location',
|
||||
'warehouse', 'Categories',
|
||||
states={
|
||||
'invisible': Not(Equal(Eval('type'), 'warehouse'))
|
||||
},
|
||||
context={'current_location': Eval('id')})
|
||||
|
||||
@classmethod
|
||||
def view_attributes(cls):
|
||||
|
|
11
product.py
11
product.py
|
@ -11,8 +11,9 @@ class Category(metaclass=PoolMeta):
|
|||
|
||||
locations = fields.One2Many(
|
||||
'stock.product.category.location', 'category', 'Default Locations')
|
||||
default_location = fields.Function(fields.Many2One('stock.location', 'Default location'),
|
||||
'get_default_location')
|
||||
default_location = fields.Function(
|
||||
fields.Many2One('stock.location', 'Default location'),
|
||||
'get_default_location')
|
||||
|
||||
def get_default_location(self, **kwargs):
|
||||
pool = Pool()
|
||||
|
@ -27,8 +28,10 @@ class Category(metaclass=PoolMeta):
|
|||
return None
|
||||
|
||||
def _get_default_location_domain(self, **kwargs):
|
||||
_domain = [('category', '=', self.id),
|
||||
('location.type', '=', kwargs.get('location_type', 'storage'))]
|
||||
_domain = [
|
||||
('category', '=', self.id),
|
||||
('location.type', '=', kwargs.get('location_type', 'storage'))
|
||||
]
|
||||
if kwargs.get('warehouse', None):
|
||||
_domain.append(('warehouse', '=', kwargs['warehouse'].id))
|
||||
return _domain
|
||||
|
|
Loading…
Reference in a new issue