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.

48 lines
1.7 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. @api.one
  15. @api.depends('weight', 'display_unit')
  16. def get_display_weight(self):
  17. if self.display_unit:
  18. self.display_weight = self.weight / self.display_unit.factor
  19. @api.one
  20. def get_total_with_vat(self):
  21. tax_amount_sum = 0.0
  22. if hasattr(self, 'taxes_id'):
  23. for tax in self.taxes_id:
  24. tax_amount_sum = tax_amount_sum + tax.amount
  25. self.total_with_vat = self.list_price * (100.0 + tax_amount_sum) / 100
  26. @api.one
  27. def get_total_with_vat_by_unit(self):
  28. if self.display_weight > 0:
  29. self.total_with_vat_by_unit = self.total_with_vat/self.display_weight
  30. class BeesdooProductLabel(models.Model):
  31. _name = 'beesdoo.product.label'
  32. name = fields.Char()
  33. type = fields.Selection(
  34. [('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')])
  35. color_code = fields.Char()