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.

58 lines
2.2 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. class BeesdooProduct(models.Model):
  4. _inherit = 'product.template'
  5. eco_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'eco')])
  6. local_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'local')])
  7. fair_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'fair')])
  8. origin_label = fields.Many2one('beesdoo.product.label', domain=[('type', '=', 'delivery')])
  9. display_unit = fields.Many2one('product.uom', required=True)
  10. default_reference_unit = fields.Many2one('product.uom', required=True)
  11. display_weight = fields.Float(compute='get_display_weight')
  12. total_with_vat = fields.Float(compute='get_total_with_vat')
  13. total_with_vat_by_unit = fields.Float(compute='get_total_with_vat_by_unit')
  14. main_seller_id = fields.Many2one('res.partner', compute='_compute_main_seller_id', store=True)
  15. @api.one
  16. @api.depends('weight', 'display_unit')
  17. def get_display_weight(self):
  18. if self.display_unit:
  19. self.display_weight = self.weight * self.display_unit.factor
  20. @api.one
  21. def get_total_with_vat(self):
  22. tax_amount_sum = 0.0
  23. if hasattr(self, 'taxes_id'):
  24. for tax in self.taxes_id:
  25. tax_amount_sum = tax_amount_sum + tax.amount
  26. self.total_with_vat = self.list_price * (100.0 + tax_amount_sum) / 100
  27. @api.one
  28. def get_total_with_vat_by_unit(self):
  29. if self.display_weight > 0:
  30. self.total_with_vat_by_unit = self.total_with_vat / self.weight
  31. @api.one
  32. @api.depends('seller_ids', 'seller_ids.date_start')
  33. def _compute_main_seller_id(self):
  34. # Calcule le vendeur associé qui a la date de début la plus récente et plus petite qu’aujourd’hui
  35. sellers_ids = self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
  36. self.main_seller_id = sellers_ids and sellers_ids[0].name or False
  37. class BeesdooProductLabel(models.Model):
  38. _name = 'beesdoo.product.label'
  39. name = fields.Char()
  40. type = fields.Selection(
  41. [('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')])
  42. color_code = fields.Char()