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.

64 lines
2.3 KiB

8 years ago
8 years ago
8 years ago
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. from openerp.tools.translate import _
  4. import datetime
  5. class BeesdooProduct(models.Model):
  6. _inherit = "product.template"
  7. eco_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'eco')])
  8. local_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'local')])
  9. fair_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'fair')])
  10. origin_label = fields.Many2one('beesdoo.product.label', domain = [('type', '=', 'delivery')])
  11. main_seller_id = fields.Many2one('res.partner', compute='_compute_main_seller_id', store=True)
  12. label_to_be_printed = fields.Boolean('Print label?')
  13. label_last_printed = fields.Datetime('Label last printed on')
  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.weight
  30. @api.one
  31. @api.depends('seller_ids', 'seller_ids.date_start')
  32. def _compute_main_seller_id(self):
  33. # Calcule le vendeur associé qui a la date de début la plus récente et plus petite qu’aujourd’hui
  34. sellers_ids = self.seller_ids.sorted(key=lambda seller: seller.date_start, reverse=True)
  35. self.main_seller_id = sellers_ids and sellers_ids[0].name or False
  36. @api.one
  37. def _request_label_printing(self):
  38. print("request_printing")
  39. self.label_to_be_printed = True
  40. @api.one
  41. def _set_label_as_printed(self):
  42. self.label_to_be_printed = False
  43. self.label_last_printed = datetime.datetime.now()
  44. class BeesdooProductLabel(models.Model):
  45. _name = "beesdoo.product.label"
  46. name = fields.Char()
  47. type = fields.Selection([('eco', 'Écologique'), ('local', 'Local'), ('fair', 'Équitable'), ('delivery', 'Distribution')])
  48. color_code = fields.Char()