From 4eca1a5e21c703cfc2142db33512e36a00863bfe Mon Sep 17 00:00:00 2001 From: Sergio Morillo Date: Mon, 25 Jan 2021 11:10:10 +0100 Subject: [PATCH] Reformat code --- location.py | 54 ++++++++++++++++++++++++++++++----------------------- product.py | 11 +++++++---- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/location.py b/location.py index 329a687..f2e4a96 100644 --- a/location.py +++ b/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): diff --git a/product.py b/product.py index 36321c5..e4f3ca1 100644 --- a/product.py +++ b/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