Files
account-financial-tools/base_vat_optional_vies/models/res_partner.py
Jairo Llopis 03b380c165 [FIX] base_vat_optional_vies: change dependency
This module required `vatnumber` just to make sure upstream odoo behaved as expected.

However, upstream changed to using `stdnum` in c377e46da1, so that's what we should require here now.

Besides, tests were bringing false positives and negatives. Now they test the correct behavior.

@moduon MT-5599
2024-04-02 10:47:21 +01:00

42 lines
1.5 KiB
Python

# Copyright 2015 Tecnativa - Antonio Espinosa
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2019 FactorLibre - Rodrigo Bonilla
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
vies_passed = fields.Boolean(
string="VIES validation", readonly=True)
@api.model
def simple_vat_check(self, country_code, vat_number):
res = super(ResPartner, self).simple_vat_check(
country_code, vat_number,
)
partner = self.env.context.get('vat_partner')
if partner and self.vies_passed:
# Can not be sure that this VAT is signed up in VIES
partner.update({'vies_passed': False})
return res
@api.model
def vies_vat_check(self, country_code, vat_number):
partner = self.env.context.get('vat_partner')
if partner:
# If there's an exception checking VIES, the upstream method will
# call simple_vat_check and thus the flag will be removed
partner.update({'vies_passed': True})
res = super(ResPartner, self).vies_vat_check(country_code, vat_number)
if not res:
return self.simple_vat_check(country_code, vat_number)
return res
@api.constrains("vat", "country_id")
def check_vat(self):
for partner in self:
partner = partner.with_context(vat_partner=partner)
super(ResPartner, partner).check_vat()