mirror of
https://gitlab.com/flectra-community/partner-contact.git
synced 2024-12-25 05:41:47 +00:00
29 lines
940 B
Python
29 lines
940 B
Python
|
# Copyright 2017 Grant Thornton Spain - Ismael Calvo <ismael.calvo@es.gt.com>
|
||
|
# Copyright 2020 Manuel Calero - Tecnativa
|
||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||
|
|
||
|
from flectra import _, api, fields, models
|
||
|
from flectra.exceptions import ValidationError
|
||
|
from flectra.tools import config
|
||
|
|
||
|
|
||
|
class ResPartner(models.Model):
|
||
|
_inherit = "res.partner"
|
||
|
|
||
|
vat = fields.Char(copy=False)
|
||
|
|
||
|
@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
|
||
|
if record.same_vat_partner_id:
|
||
|
raise ValidationError(
|
||
|
_("The VAT %s already exists in another partner.") % record.vat
|
||
|
)
|