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.
 
 

30 lines
1.0 KiB

# -*- coding: utf-8 -*-
# Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models, _
from odoo.exceptions import ValidationError
from odoo.tools import config
class ResPartner(models.Model):
_inherit = 'res.partner'
@api.constrains('vat')
def _check_vat_unique(self):
for record in self:
if record.parent_id or not record.vat:
continue
test_condition = (config['test_enable'] and
not self.env.context.get('test_vat'))
if test_condition:
continue
results = self.env['res.partner'].search_count([
('parent_id', '=', False),
('vat', '=', record.vat),
('id', '!=', record.id)
])
if results:
raise ValidationError(_(
"The VAT %s already exists in another "
"partner.") % record.vat)