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.

34 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Antiun Ingenieria S.L. - Antonio Espinosa
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import models, api, _
  5. from openerp.exceptions import ValidationError
  6. class ResPartner(models.Model):
  7. _inherit = "res.partner"
  8. @api.multi
  9. @api.constrains('ref', 'is_company', 'company_id')
  10. def _check_ref(self):
  11. for partner in self:
  12. mode = partner.company_id.partner_ref_unique
  13. if (partner.ref and (
  14. mode == 'all' or
  15. (mode == 'companies' and partner.is_company))):
  16. domain = [
  17. ('id', '!=', partner.id),
  18. ('ref', '=', partner.ref),
  19. ('customer', '=', True),
  20. ]
  21. if mode == 'companies':
  22. domain.append(('is_company', '=', True))
  23. other = self.search(domain)
  24. # active_test is False when called from
  25. # base.partner.merge.automatic.wizard
  26. if other and self.env.context.get("active_test", True):
  27. raise ValidationError(
  28. _("This reference is equal to partner '%s'") %
  29. other[0].display_name)