2 from openerp.osv import osv, fields
5 class characteristics(osv.Model):
6 _name = "product.characteristic"
8 def _get_float_max(self, cr, uid, ids, field_name, arg, context=None):
9 result = dict.fromkeys(ids, 0)
12 SELECT characteristic_id, MAX(value)
13 FROM product_characteristic_product
14 WHERE characteristic_id in (%s)
15 GROUP BY characteristic_id
16 """ % ",".join(map(str, ids)))
17 result.update(dict(cr.fetchall()))
20 def _get_float_min(self, cr, uid, ids, field_name, arg, context=None):
21 result = dict.fromkeys(ids, 0)
24 SELECT characteristic_id, MIN(value)
25 FROM product_characteristic_product
26 WHERE characteristic_id in (%s)
27 GROUP BY characteristic_id
28 """ % ",".join(map(str, ids)))
29 result.update(dict(cr.fetchall()))
32 def _get_min_max(self, cr, uid, ids, context=None):
34 for value in self.pool.get('product.characteristic.product').browse(cr, uid, ids, context=context):
35 if value.type == 'float':
36 result[value.characteristic_id.id] = True
40 'name': fields.char('Name', size=64, translate=True, required=True),
41 'type': fields.selection([('distinct', 'Textual Value'), ('float', 'Numeric Value')], "Type", required=True),
42 'value_ids': fields.one2many('product.characteristic.value', 'characteristic_id', 'Values'),
43 'attr_product_ids': fields.one2many('product.characteristic.product', 'characteristic_id', 'Products'),
45 'float_max': fields.function(_get_float_max, type='float', string="Max", store={
46 'product.characteristic.product': (_get_min_max, ['value','characteristic_id'], 20),
48 'float_min': fields.function(_get_float_min, type='float', string="Min", store={
49 'product.characteristic.product': (_get_min_max, ['value','characteristic_id'], 20),
51 'visible': fields.boolean('Display Filter on Website'),
58 class characteristics_value(osv.Model):
59 _name = "product.characteristic.value"
61 'name': fields.char('Value', size=64, translate=True, required=True),
62 'characteristic_id': fields.many2one('product.characteristic', 'Characteristic', required=True),
63 'atr_product_ids': fields.one2many('product.characteristic.product', 'value_id', 'Products'),
66 class characteristics_product(osv.Model):
67 _name = "product.characteristic.product"
68 _order = 'characteristic_id, value_id, value'
70 'value': fields.float('Numeric Value'),
71 'value_id': fields.many2one('product.characteristic.value', 'Textual Value'),
72 'characteristic_id': fields.many2one('product.characteristic', 'Characteristic', required=True),
73 'product_tmpl_id': fields.many2one('product.template', 'Product', required=True),
75 'type': fields.related('characteristic_id', 'type', type='selection',
76 selection=[('distinct', 'Distinct'), ('float', 'Float')], string='Type'),
79 def onchange_characteristic_id(self, cr, uid, ids, characteristic_id, context=None):
80 characteristic = self.pool.get('product.characteristic').browse(cr, uid, characteristic_id, context=context)
81 return {'value': {'type': characteristic.type, 'value_id': False, 'value': ''}}
83 class product_template(osv.Model):
84 _inherit = "product.template"
86 'website_characteristic_ids': fields.one2many('product.characteristic.product', 'product_tmpl_id', 'Product Characteristics'),