2017-06-23 19:53:23 +02:00
|
|
|
# Copyright 2015 Tecnativa - Antonio Espinosa
|
|
|
|
# Copyright 2017 Tecnativa - David Vidal
|
2019-01-10 12:14:00 +01:00
|
|
|
# Copyright 2019 FactorLibre - Rodrigo Bonilla
|
2020-05-09 19:29:26 +02:00
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
2017-06-23 19:53:23 +02:00
|
|
|
from odoo import api, fields, models
|
2015-10-06 11:10:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ResPartner(models.Model):
|
2020-05-09 19:29:26 +02:00
|
|
|
_inherit = "res.partner"
|
2015-10-06 11:10:40 +02:00
|
|
|
|
2020-05-09 19:29:26 +02:00
|
|
|
vies_passed = fields.Boolean(string="VIES validation", readonly=True)
|
2015-10-06 11:10:40 +02:00
|
|
|
|
2017-06-23 19:53:23 +02:00
|
|
|
@api.model
|
|
|
|
def simple_vat_check(self, country_code, vat_number):
|
2021-07-03 02:16:21 +02:00
|
|
|
res = super(ResPartner, self).simple_vat_check(
|
|
|
|
country_code,
|
|
|
|
vat_number,
|
|
|
|
)
|
2020-05-09 19:29:26 +02:00
|
|
|
partner = self.env.context.get("vat_partner")
|
2021-07-03 02:16:21 +02:00
|
|
|
if partner:
|
2020-05-09 19:29:26 +02:00
|
|
|
partner.update({"vies_passed": False})
|
2015-10-06 11:10:40 +02:00
|
|
|
return res
|
|
|
|
|
2017-06-23 19:53:23 +02:00
|
|
|
@api.model
|
|
|
|
def vies_vat_check(self, country_code, vat_number):
|
2020-05-09 19:29:26 +02:00
|
|
|
partner = self.env.context.get("vat_partner")
|
2017-06-23 19:53:23 +02:00
|
|
|
if partner:
|
|
|
|
# If there's an exception checking VIES, the upstream method will
|
|
|
|
# call simple_vat_check and thus the flag will be removed
|
2020-05-09 19:29:26 +02:00
|
|
|
partner.update({"vies_passed": True})
|
2017-06-23 19:53:23 +02:00
|
|
|
res = super(ResPartner, self).vies_vat_check(country_code, vat_number)
|
2015-10-06 11:10:40 +02:00
|
|
|
return res
|
|
|
|
|
2020-05-09 19:31:26 +02:00
|
|
|
@api.constrains("vat", "country_id")
|
2017-06-23 19:53:23 +02:00
|
|
|
def check_vat(self):
|
|
|
|
for partner in self:
|
|
|
|
partner = partner.with_context(vat_partner=partner)
|
|
|
|
super(ResPartner, partner).check_vat()
|
2021-07-03 02:16:21 +02:00
|
|
|
return True
|