From e574d251478fa06c9836b04a91bc93f2f931c375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 28 May 2008 12:59:40 +0200 Subject: [PATCH 1/2] Move product template into product.py --- __init__.py | 1 - product.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ template.py | 65 ----------------------------------------------------- 3 files changed, 64 insertions(+), 66 deletions(-) delete mode 100644 template.py diff --git a/__init__.py b/__init__.py index abe62ae2c7..8e58995d0c 100644 --- a/__init__.py +++ b/__init__.py @@ -26,5 +26,4 @@ ############################################################################## from uom import * from category import * -from template import * from product import * diff --git a/product.py b/product.py index 944fd4e885..ad6552c2ff 100644 --- a/product.py +++ b/product.py @@ -1,5 +1,69 @@ from trytond.osv import fields, OSV +STATES = { + 'readonly': "active == False", +} + + +class Template(OSV): + "Product Template" + _name = "product.template" + _description = __doc__ + + name = fields.Char('Name', size=None, required=True, translate=True, + select=1, states=STATES) + type = fields.Selection([ + ('stockable', 'Stockable'), + ('consumable', 'Consumable'), + ('service', 'Service') + ], 'Type', required=True, states=STATES) + category = fields.Many2One('product.category','Category', required=True, + states=STATES) + list_price = fields.Property(type='numeric', string='List Price', + states=STATES, digits=(16, 4)) + list_price_uom = fields.Function('get_price_uom', string='List Price', + type="numeric", digits=(16, 4)) + cost_price = fields.Property(type='numeric', string='Cost Price', + states=STATES, digits=(16, 4)) + cost_price_uom = fields.Function('get_price_uom', string='Cost Price', + type="numeric", digits=(16, 4)) + cost_price_method = fields.Selection([ + ("fixed", "Fixed"), + ("average", "Average") + ], "Cost Method", required=True) + default_uom = fields.Many2One('product.uom', 'Default UOM', required=True, + states=STATES) + active = fields.Boolean('Active') + + def default_active(self, cursor, user, context=None): + return True + + def default_type(self, cursor, user, context=None): + return 'stockable' + + def default_cost_price_method(self, cursor, user, context=None): + return 'fixed' + + def get_price_uom(self, cursor, user, ids, name, arg, context=None): + product_uom_obj = self.pool.get('product.uom') + res = {} + if context is None: + context = {} + field = name[:-4] + if context.get('uom'): + to_uom = self.pool.get('product.uom').browse( + cursor, user, context['uom'], context=context) + for product in self.browse(cursor, user, ids, context=context): + res[product.id] = product_uom_obj.compute_price( + cursor, user, product.default_uom, product[field], + to_uom) + else: + for product in self.browse(cursor, user, ids, context=context): + res[product.id] = product[field] + return res + +Template() + class Product(OSV): "Product" diff --git a/template.py b/template.py deleted file mode 100644 index 152a4469c0..0000000000 --- a/template.py +++ /dev/null @@ -1,65 +0,0 @@ -from trytond.osv import fields, OSV - -STATES = { - 'readonly': "active == False", -} - - -class Template(OSV): - "Product Template" - _name = "product.template" - _description = __doc__ - - name = fields.Char('Name', size=None, required=True, translate=True, - select=1, states=STATES) - type = fields.Selection([ - ('stockable', 'Stockable'), - ('consumable', 'Consumable'), - ('service', 'Service') - ], 'Type', required=True, states=STATES) - category = fields.Many2One('product.category','Category', required=True, - states=STATES) - list_price = fields.Property(type='numeric', string='List Price', - states=STATES, digits=(16, 4)) - list_price_uom = fields.Function('get_price_uom', string='List Price', - type="numeric", digits=(16, 4)) - cost_price = fields.Property(type='numeric', string='Cost Price', - states=STATES, digits=(16, 4)) - cost_price_uom = fields.Function('get_price_uom', string='Cost Price', - type="numeric", digits=(16, 4)) - cost_price_method = fields.Selection([ - ("fixed", "Fixed"), - ("average", "Average") - ], "Cost Method", required=True) - default_uom = fields.Many2One('product.uom', 'Default UOM', required=True, - states=STATES) - active = fields.Boolean('Active') - - def default_active(self, cursor, user, context=None): - return True - - def default_type(self, cursor, user, context=None): - return 'stockable' - - def default_cost_price_method(self, cursor, user, context=None): - return 'fixed' - - def get_price_uom(self, cursor, user, ids, name, arg, context=None): - product_uom_obj = self.pool.get('product.uom') - res = {} - if context is None: - context = {} - field = name[:-4] - if context.get('uom'): - to_uom = self.pool.get('product.uom').browse( - cursor, user, context['uom'], context=context) - for product in self.browse(cursor, user, ids, context=context): - res[product.id] = product_uom_obj.compute_price( - cursor, user, product.default_uom, product[field], - to_uom) - else: - for product in self.browse(cursor, user, ids, context=context): - res[product.id] = product[field] - return res - -Template() From c457764d4b3c7d343cd3a1fa35ae2d44ba6d9230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 28 May 2008 13:42:15 +0200 Subject: [PATCH 2/2] Better naming for column template on product --- product.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/product.py b/product.py index ad6552c2ff..e6511839f7 100644 --- a/product.py +++ b/product.py @@ -69,9 +69,9 @@ class Product(OSV): "Product" _name = "product.product" _description = __doc__ - _inherits = {'product.template': 'product_template'} + _inherits = {'product.template': 'template'} - product_template = fields.Many2One('product.template', 'Product Template', + template = fields.Many2One('product.template', 'Product Template', required=True) code = fields.Char("Code", size=None) description = fields.Text("Description", translate=True)