# -*- encoding: utf-8 -*- from openerp import models, fields, api class ProductCurve(models.Model): _name = 'product.curve' name = fields.Char('Curve Name', required=True) description = fields.Text('Description', translate=True) # partner_id = fields.Many2one( # 'res.partner', # string='Partner', # help='Select a partner for this brand if it exists', # ondelete='restrict' # ) logo = fields.Binary('Logo File') product_ids = fields.One2many( 'product.template', 'product_curve_id', string='Curve Products', ) products_count = fields.Integer( string='Number of products', compute='_get_products_count', ) @api.one @api.depends('product_ids') def _get_products_count(self): self.products_count = len(self.product_ids) class ProductTemplate(models.Model): _inherit = 'product.template' product_curve_id = fields.Many2one( 'product.curve', string='Curva', help='Select a curve for this product' ) @api.multi def name_get(self): res = super(ProductTemplate, self).name_get() res2 = [] for name_tuple in res: product = self.browse(name_tuple[0]) if not product.product_curve_id: res2.append(name_tuple) continue res2.append(( name_tuple[0], u'{} ({})'.format(name_tuple[1], product.product_curve_id.name) )) return res2 class ProductProduct(models.Model): _inherit = 'product.product' @api.multi def name_get(self): res = super(ProductProduct, self).name_get() res2 = [] for name_tuple in res: product = self.browse(name_tuple[0]) if not product.product_curve_id: res2.append(name_tuple) continue res2.append(( name_tuple[0], u'{} ({})'.format(name_tuple[1], product.product_curve_id.name) )) return res2