product_curve.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, fields, api
  3. class ProductCurve(models.Model):
  4. _name = 'product.curve'
  5. name = fields.Char('Nombre', required=True)
  6. description = fields.Text('Descripción', translate=True)
  7. logo = fields.Binary('Logo File')
  8. product_ids = fields.One2many(
  9. 'product.template',
  10. 'product_curve_id',
  11. string='Curva de Productos',
  12. )
  13. products_count = fields.Integer(
  14. string='Numero de productos',
  15. compute='_get_products_count',
  16. )
  17. @api.one
  18. @api.depends('product_ids')
  19. def _get_products_count(self):
  20. self.products_count = len(self.product_ids)
  21. class ProductTemplate(models.Model):
  22. _inherit = 'product.template'
  23. product_curve_id = fields.Many2one(
  24. 'product.curve',
  25. string='Curva',
  26. help='Selecionar curva para este producto'
  27. )
  28. @api.multi
  29. def name_get(self):
  30. res = super(ProductTemplate, self).name_get()
  31. res2 = []
  32. for name_tuple in res:
  33. product = self.browse(name_tuple[0])
  34. if not product.product_curve_id:
  35. res2.append(name_tuple)
  36. continue
  37. res2.append((
  38. name_tuple[0],
  39. u'{} ({})'.format(name_tuple[1], product.product_curve_id.name)
  40. ))
  41. return res2
  42. class ProductProduct(models.Model):
  43. _inherit = 'product.product'
  44. @api.multi
  45. def name_get(self):
  46. res = super(ProductProduct, self).name_get()
  47. res2 = []
  48. for name_tuple in res:
  49. product = self.browse(name_tuple[0])
  50. if not product.product_curve_id:
  51. res2.append(name_tuple)
  52. continue
  53. res2.append((
  54. name_tuple[0],
  55. u'{} ({})'.format(name_tuple[1], product.product_curve_id.name)
  56. ))
  57. return res2