123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- # -*- encoding: utf-8 -*-
- from openerp import models, fields, api
- class ProductCurve(models.Model):
- _name = 'product.curve'
- name = fields.Char('Nombre', required=True)
- description = fields.Text('Descripción', translate=True)
- logo = fields.Binary('Logo File')
- product_ids = fields.One2many(
- 'product.template',
- 'product_curve_id',
- string='Curva de Productos',
- )
- products_count = fields.Integer(
- string='Numero de productos',
- 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='Selecionar curva para este producto'
- )
- @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
|