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.

28 lines
931 B

  1. # Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
  2. # Copyright 2020 Manuel Calero - Tecnativa
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo import _, api, fields, models
  5. from odoo.exceptions import ValidationError
  6. from odoo.tools import config
  7. class ResPartner(models.Model):
  8. _inherit = "res.partner"
  9. vat = fields.Char(copy=False)
  10. @api.constrains("vat")
  11. def _check_vat_unique(self):
  12. for record in self:
  13. if record.parent_id or not record.vat:
  14. continue
  15. test_condition = config["test_enable"] and not self.env.context.get(
  16. "test_vat"
  17. )
  18. if test_condition:
  19. continue
  20. if record.same_vat_partner_id:
  21. raise ValidationError(
  22. _("The VAT %s already exists in another partner.") % record.vat
  23. )