2
0

[IMP] base_vat_optional_vies: black, isort, prettier

This commit is contained in:
Harald Panten 2020-05-09 19:29:26 +02:00 committed by Rodrigo
parent d85536049f
commit a2c0fc4701
4 changed files with 30 additions and 43 deletions

View File

@ -2,23 +2,16 @@
# Copyright 2016 Tecnativa - Sergio Teruel
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2019 FactorLibre - Rodrigo Bonilla
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': "Optional validation of VAT via VIES",
'category': 'Accounting',
'version': '12.0.1.0.1',
'depends': [
'base_vat',
],
'external_dependencies': {
'python': ['vatnumber'],
},
'data': [
'views/res_partner_view.xml',
],
'author': 'Tecnativa,'
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/account-financial-tools',
'license': 'AGPL-3',
'installable': True,
"name": "Optional validation of VAT via VIES",
"category": "Accounting",
"version": "13.0.1.0.1",
"depends": ["base_vat"],
"external_dependencies": {"python": ["vatnumber"]},
"data": ["views/res_partner_view.xml"],
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"license": "AGPL-3",
"installable": True,
}

View File

@ -1,40 +1,37 @@
# 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).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"
vies_passed = fields.Boolean(
string="VIES validation", readonly=True)
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')
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})
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')
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})
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')
@api.constrains("vat")
def check_vat(self):
for partner in self:
partner = partner.with_context(vat_partner=partner)

View File

@ -1,8 +1,9 @@
# Copyright 2015 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Sergio Teruel
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import mock
from odoo.tests import common
@ -11,27 +12,23 @@ class TestResPartner(common.TransactionCase):
super(TestResPartner, self).setUp()
self.company = self.env.user.company_id
self.company.vat_check_vies = True
self.partner = self.env['res.partner'].create({
'name': 'Test partner',
})
self.vatnumber_path = (
'odoo.addons.base_vat.models.res_partner.vatnumber'
)
self.partner = self.env["res.partner"].create({"name": "Test partner"})
self.vatnumber_path = "odoo.addons.base_vat.models.res_partner.vatnumber"
def test_validate_vat_vies(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = True
self.partner.vat = 'ESB87530432'
self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, True)
def test_exception_vat_vies(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.side_effect = Exception()
self.partner.vat = 'ESB87530432'
self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, False)
def test_no_validate_vat(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = False
self.partner.vat = 'ESB87530432'
self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, False)