|
|
@ -7,25 +7,28 @@ from odoo.tools import config |
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model): |
|
|
|
_inherit = 'res.partner' |
|
|
|
_inherit = "res.partner" |
|
|
|
|
|
|
|
vat = fields.Char(copy=False) |
|
|
|
|
|
|
|
@api.constrains('vat') |
|
|
|
@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')) |
|
|
|
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) |
|
|
|
]) |
|
|
|
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) |
|
|
|
raise ValidationError( |
|
|
|
_("The VAT %s already exists in another " "partner.") % record.vat |
|
|
|
) |