product.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. # For copyright and license notices, see __openerp__.py file in module root
  4. # directory
  5. ##############################################################################
  6. from openerp import models, api, _
  7. from openerp.exceptions import Warning
  8. class product_template(models.Model):
  9. _inherit = "product.template"
  10. @api.one
  11. @api.constrains('company_id', 'factory_reference', 'active')
  12. def check_unique_company_and_factory_reference(self):
  13. if self.active and self.factory_reference and self.company_id:
  14. filters = [('company_id', '=', self.company_id.id),
  15. ('factory_reference', '=', self.factory_reference),
  16. ('active', '=', True)]
  17. prod_ids = self.search(filters)
  18. if len(prod_ids) > 1:
  19. raise Warning(
  20. _('There can not be two active products with the same Reference in the same company.'))
  21. @api.one
  22. @api.constrains('company_id', 'ean13', 'active')
  23. def check_unique_company_and_ean13(self):
  24. if self.active and self.ean13 and self.company_id:
  25. filters = [('company_id', '=', self.company_id.id),
  26. ('ean13', '=', self.ean13), ('active', '=', True)]
  27. prod_ids = self.search(filters)
  28. if len(prod_ids) > 1:
  29. raise Warning(
  30. _('There can not be two active products with the same EAN code in the same company'))