You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.3 KiB

9 years ago
9 years ago
9 years ago
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from openerp.tools.translate import _
  4. class BeesdooProduct(models.Model):
  5. _inherit = "product.template"
  6. eco_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'eco')])
  7. local_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'local')])
  8. fair_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'fair')])
  9. origin_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'delivery')])
  10. main_seller_id = fields.Many2one('res.partner', compute='_compute_main_seller_id', store=True)
  11. @api.one
  12. @api.depends('seller_ids', 'seller_ids.date_start')
  13. def _compute_main_seller_id(self):
  14. # Calcule le vendeur associé qui a la date de début la plus récente et plus petite qu’aujourd’hui
  15. sellers_ids = self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
  16. self.main_seller_id = sellers_ids and sellers_ids[0].name or False
  17. class BeesdooProductLabel(models.Model):
  18. _name = "beesdoo.product.label"
  19. name = fields.Char()
  20. type = fields.Selection([('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')])
  21. color_code = fields.Char()