From 0f94f2acf2f3865632a891c03c13b7beaf3779f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 4 Mar 2008 11:56:55 +0100 Subject: [PATCH 1/4] New __init__ signature --- category.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/category.py b/category.py index 5767cfaeb8..facc96690f 100644 --- a/category.py +++ b/category.py @@ -1,5 +1,6 @@ from trytond.osv import fields, OSV + class Category(OSV): "Product Category" _name = "product.category" @@ -10,15 +11,18 @@ class Category(OSV): complete_name = fields.Function('complete_name', type="char", string='Name') parent = fields.Many2One('product.category','Parent Category', select=True) childs = fields.One2Many('product.category', 'parent', - string='Child Categories') + string='Child Categories') - def __init__(self, pool): + def __init__(self): super(Category, self).__init__(pool) - if pool: - self._rpc_allowed.extend([ - 'complete_name', - 'name_get', - ]) + self._rpc_allowed.extend([ + 'complete_name', + 'name_get', + ]) + self._constraints += [ + ('check_recursion', + 'Error! You can not create recursive categories.', ['parent']) + ] def complete_name(self, cursor, user, obj_id, name, value, arg, context=None): @@ -39,9 +43,4 @@ class Category(OSV): res.append((category.id, name)) return res - _constraints = [ - ('check_recursion', - 'Error! You can not create recursive categories.', ['parent']) - ] - Category() From caa369c768fb83a31505cf68a9d9748ec3c0a4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 5 Mar 2008 10:26:40 +0100 Subject: [PATCH 2/4] Fix __init__ and fix code guidelines --- category.py | 2 +- uom.py | 61 ++++++++++++++++++++++------------------------------- 2 files changed, 26 insertions(+), 37 deletions(-) diff --git a/category.py b/category.py index facc96690f..d7704eea7e 100644 --- a/category.py +++ b/category.py @@ -14,7 +14,7 @@ class Category(OSV): string='Child Categories') def __init__(self): - super(Category, self).__init__(pool) + super(Category, self).__init__() self._rpc_allowed.extend([ 'complete_name', 'name_get', diff --git a/uom.py b/uom.py index 435b6408ec..76cedb7d97 100644 --- a/uom.py +++ b/uom.py @@ -7,11 +7,9 @@ STATES = { class UomCategory(OSV): 'Product uom category' - _name = 'product.uom.category' _description = __doc__ _order = 'name' - name = fields.Char('Name', size=64, required=True) @@ -20,22 +18,35 @@ UomCategory() class Uom(OSV): 'Unit of measure' - _name = 'product.uom' _description = __doc__ _order = 'name' + name = fields.Char('Name', size=64, required=True, states=STATES) + category = fields.Many2One('product.uom.category', 'UOM Category', + required=True, ondelete='cascade', states=STATES) + rate = fields.Float('Rate', digits=(12, 6), required=True, + on_change = ['rate'],states=STATES, + help='The coefficient for the formula:\n' \ + '1 (base unit) = coef (this unit)') + factor = fields.Function("_factor", fnct_inv="_factor_inv", + digits=(12, 6),states=STATES, method=True, string='Factor', + on_change = ['factor'], help='The coefficient for the formula:\n' \ + 'coef (base unit) = 1 (this unit)') + factor_data = fields.Float('Factor', digits=(12, 6), states=STATES) + rounding = fields.Float('Rounding Precision', digits=(16, 3), + required=True, states=STATES) + active = fields.Boolean('Active') - def __init__(self, pool): - super(Uom, self).__init__(pool) - if pool: - self._rpc_allowed.extend([ - 'default_rate', - 'default_factor', - 'default_active', - 'default_rounding', - 'on_change_factor', - 'on_change_rate', - ]) + def __init__(self): + super(Uom, self).__init__() + self._rpc_allowed.extend([ + 'default_rate', + 'default_factor', + 'default_active', + 'default_rounding', + 'on_change_factor', + 'on_change_rate', + ]) def _factor(self, cursor, user, ids, name, arg, context): res = {} @@ -67,27 +78,6 @@ class Uom(OSV): 'factor_data': 0.0, }, context=ctx) - - name = fields.Char('Name', size=64, required=True, states=STATES,) - category = fields.Many2One('product.uom.category', 'UOM Category', - required=True, ondelete='cascade', - states=STATES,) - rate = fields.Float('Rate', digits=(12, 6), required=True, - on_change = ['rate'],states=STATES, - help='The coefficient for the formula:\n' \ - '1 (base unit) = coef (this unit)') - factor = fields.Function("_factor", fnct_inv="_factor_inv", - digits=(12, 6),states=STATES, - method=True, string='Factor', - on_change = ['factor'], - help='The coefficient for the formula:\n' \ - 'coef (base unit) = 1 (this unit)') - factor_data = fields.Float('Factor', digits=(12, 6), states=STATES,) - rounding = fields.Float('Rounding Precision', digits=(16, 3), - required=True,states=STATES,) - active = fields.Boolean('Active') - - def default_rate(self, cursor, user, context=None): return 1.0 @@ -100,7 +90,6 @@ class Uom(OSV): def default_rounding(self, cursor, user, context=None): return 0.01 - def on_change_factor(self, cursor, user, ids, value, context=None): if value.get('factor', 0.0) == 0.0: return {'value': {'rate': 0}} From 7cf965ab31e4d09ff8a7823c00f6c02a8eb20076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 5 Mar 2008 11:14:16 +0100 Subject: [PATCH 3/4] Fix xml coding guide lines --- __tryton__.py | 11 +- category.xml | 155 +++++++++++------------- product.xml | 173 ++++++++++++--------------- template.xml | 6 - uom.xml | 321 ++++++++++++++++++++++---------------------------- 5 files changed, 290 insertions(+), 376 deletions(-) delete mode 100644 template.xml diff --git a/__tryton__.py b/__tryton__.py index 5865043cce..dfaaf68bac 100644 --- a/__tryton__.py +++ b/__tryton__.py @@ -1,12 +1,11 @@ { - "name" : "Products", + "name" : "Product", "version" : "0.1", "author" : "B2CK", "category" : "Generic Modules", - "description": "Define products, categories of product, units" - "of measure, categories of units of measure.", - "depends" : ["ir","res"], - "xml" : ["product.xml","category.xml","template.xml","uom.xml"], - "installable": True, + "description": "Define products, categories of product, units" \ + "of measure, categories of units of measure.", + "depends" : ["ir", "res"], + "xml" : ["product.xml", "category.xml", "uom.xml"], } diff --git a/category.xml b/category.xml index a0c82b1299..b5d1410c96 100644 --- a/category.xml +++ b/category.xml @@ -1,90 +1,71 @@ - - - - product.category - tree - - - - - - - ]]> - - - - - product.category - form - - - - - - - - - Product category - ir.action.act_window - product.category - form - - - - - - - - - - - - - - - - - - - Product Category - ir.action.act_window - product.category - form - - - - - - - - - - - - - - - - - + + + product.category + tree + + + + + + + ]]> + + + + product.category + form + + + + + Product Categories + product.category + form + + + + + + + + + + + + + + Product Categories + product.category + form + + + + + + + + + + + + + diff --git a/product.xml b/product.xml index be7cc1e783..68686a6698 100644 --- a/product.xml +++ b/product.xml @@ -1,99 +1,80 @@ - - - - - - product.product - tree - - - - - - - - - - ]]> - - - - - product.product - form - - - - - - Products - ir.action.act_window - product.product - form - - - - - - - - - - - - - - - - - - - - - - Products - ir.action.act_window - product.product - form - - - - - - - - - - - - - - - - - - + + + + product.product + tree + + + + + + + + + + ]]> + + + + product.product + form + + + + + Products + product.product + form + + + + + + + + + + + + + + Products + product.product + form + + + + + + + + + + + + + diff --git a/template.xml b/template.xml deleted file mode 100644 index b13e7d7ae0..0000000000 --- a/template.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/uom.xml b/uom.xml index 588888e6e7..c5ab939649 100644 --- a/uom.xml +++ b/uom.xml @@ -1,184 +1,143 @@ - - - - product.uom - tree - - - - - - - - - - ]]> - - - - - product.uom - form - - - - - - - - Units of measure - ir.action.act_window - product.uom - form - - - - - - - - - - - - - - - - - - - Units of measure - ir.action.act_window - product.uom - form - - - - - - - - - - - - - - - - ------------uom categ--------------- - - - product.uom.category - tree - - - - - - - ]]> - - - - - product.uom.category - form - - - - - - - - Categories of Unit of Measure - ir.action.act_window - product.uom.category - form - - - - - - - - - - - - - - - - - - - Categories of Unit of measure - ir.action.act_window - product.uom.category - form - - - - - - - - - - - - - - - - - + + + product.uom + tree + + + + + + + + + + ]]> + + + + product.uom + form + + + + + Units of Measure + product.uom + form + + + + + + + + + + + + + + Units of Measure + product.uom + form + + + + + + + + + + + + + + product.uom.category + tree + + + + + + + ]]> + + + + product.uom.category + form + + + + + Categories of Unit of Measure + product.uom.category + form + + + + + + + + + + + + + + Categories of Unit of measure + product.uom.category + form + + + + + + + + + + + + + From f360ce0634d8ab203c38b58bfb2bac5f48831a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 5 Mar 2008 12:07:49 +0100 Subject: [PATCH 4/4] on_change function are automatically in _rpc_allowed --- uom.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/uom.py b/uom.py index 76cedb7d97..33c12211f8 100644 --- a/uom.py +++ b/uom.py @@ -44,8 +44,6 @@ class Uom(OSV): 'default_factor', 'default_active', 'default_rounding', - 'on_change_factor', - 'on_change_rate', ]) def _factor(self, cursor, user, ids, name, arg, context):