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.

32 lines
1.2 KiB

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