2 from openerp.osv import osv, fields
5 class attributes(osv.Model):
6 _name = "product.attribute"
8 def _get_float_max(self, cr, uid, ids, field_name, arg, context=None):
9 result = dict.fromkeys(ids, 0)
12 SELECT attribute_id, MAX(value)
13 FROM product_attribute_product
14 WHERE attribute_id in (%s)
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 attribute_id, MIN(value)
25 FROM product_attribute_product
26 WHERE attribute_id in (%s)
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.attribute.product').browse(cr, uid, ids, context=context):
35 if value.type == 'float':
36 result[value.attribute_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.attribute.value', 'attribute_id', 'Values'),
43 'product_ids': fields.one2many('product.attribute.product', 'attribute_id', 'Products'),
44 'float_max': fields.function(_get_float_max, type='float', string="Max", store={
45 'product.attribute.product': (_get_min_max, ['value','attribute_id'], 20),
47 'float_min': fields.function(_get_float_min, type='float', string="Min", store={
48 'product.attribute.product': (_get_min_max, ['value','attribute_id'], 20),
50 'visible': fields.boolean('Display Filter on Website'),
57 class attributes_value(osv.Model):
58 _name = "product.attribute.value"
60 'name': fields.char('Value', size=64, translate=True, required=True),
61 'attribute_id': fields.many2one('product.attribute', 'Attribute', required=True),
62 'product_ids': fields.one2many('product.attribute.product', 'value_id', 'Products'),
65 class attributes_product(osv.Model):
66 _name = "product.attribute.product"
67 _order = 'attribute_id, value_id, value'
69 'value': fields.float('Numeric Value'),
70 'value_id': fields.many2one('product.attribute.value', 'Textual Value'),
71 'attribute_id': fields.many2one('product.attribute', 'Attribute', required=True),
72 'product_id': fields.many2one('product.template', 'Product', required=True),
74 'type': fields.related('attribute_id', 'type', type='selection',
75 selection=[('distinct', 'Distinct'), ('float', 'Float')], string='Type'),
78 def onchange_attribute_id(self, cr, uid, ids, attribute_id, context=None):
79 attribute = self.pool.get('product.attribute').browse(cr, uid, attribute_id, context=context)
80 return {'value': {'type': attribute.type, 'value_id': False, 'value': ''}}
82 class product_template(osv.Model):
83 _inherit = "product.template"
85 'website_attribute_ids': fields.one2many('product.attribute.product', 'product_id', 'Product Attributes'),