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.

29 lines
1.0 KiB

  1. # Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
  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. from odoo.tools import config
  6. class ResPartner(models.Model):
  7. _inherit = 'res.partner'
  8. @api.constrains('vat')
  9. def _check_vat_unique(self):
  10. for record in self:
  11. if record.parent_id or not record.vat:
  12. continue
  13. test_condition = (config['test_enable'] and
  14. not self.env.context.get('test_vat'))
  15. if test_condition:
  16. continue
  17. results = self.env['res.partner'].search_count([
  18. ('parent_id', '=', False),
  19. ('vat', '=', record.vat),
  20. ('id', '!=', record.id)
  21. ])
  22. if results:
  23. raise ValidationError(_(
  24. "The VAT %s already exists in another "
  25. "partner.") % record.vat)