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 2016 Tecnativa - Sergio Teruel
# Copyright 2017 Tecnativa - David Vidal # Copyright 2017 Tecnativa - David Vidal
# Copyright 2019 FactorLibre - Rodrigo Bonilla # 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", "name": "Optional validation of VAT via VIES",
'category': 'Accounting', "category": "Accounting",
'version': '12.0.1.0.1', "version": "13.0.1.0.1",
'depends': [ "depends": ["base_vat"],
'base_vat', "external_dependencies": {"python": ["vatnumber"]},
], "data": ["views/res_partner_view.xml"],
'external_dependencies': { "author": "Tecnativa," "Odoo Community Association (OCA)",
'python': ['vatnumber'], "website": "https://github.com/OCA/account-financial-tools",
}, "license": "AGPL-3",
'data': [ "installable": True,
'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 2015 Tecnativa - Antonio Espinosa
# Copyright 2017 Tecnativa - David Vidal # Copyright 2017 Tecnativa - David Vidal
# Copyright 2019 FactorLibre - Rodrigo Bonilla # 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 from odoo import api, fields, models
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = "res.partner"
vies_passed = fields.Boolean( vies_passed = fields.Boolean(string="VIES validation", readonly=True)
string="VIES validation", readonly=True)
@api.model @api.model
def simple_vat_check(self, country_code, vat_number): def simple_vat_check(self, country_code, vat_number):
res = super(ResPartner, self).simple_vat_check( res = super(ResPartner, self).simple_vat_check(country_code, vat_number,)
country_code, vat_number, partner = self.env.context.get("vat_partner")
)
partner = self.env.context.get('vat_partner')
if partner and self.vies_passed: if partner and self.vies_passed:
# Can not be sure that this VAT is signed up in VIES # Can not be sure that this VAT is signed up in VIES
partner.update({'vies_passed': False}) partner.update({"vies_passed": False})
return res return res
@api.model @api.model
def vies_vat_check(self, country_code, vat_number): 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 partner:
# If there's an exception checking VIES, the upstream method will # If there's an exception checking VIES, the upstream method will
# call simple_vat_check and thus the flag will be removed # 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) res = super(ResPartner, self).vies_vat_check(country_code, vat_number)
if not res: if not res:
return self.simple_vat_check(country_code, vat_number) return self.simple_vat_check(country_code, vat_number)
return res return res
@api.constrains('vat') @api.constrains("vat")
def check_vat(self): def check_vat(self):
for partner in self: for partner in self:
partner = partner.with_context(vat_partner=partner) partner = partner.with_context(vat_partner=partner)

View File

@ -1,8 +1,9 @@
# Copyright 2015 Tecnativa - Antonio Espinosa # Copyright 2015 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Sergio Teruel # Copyright 2016 Tecnativa - Sergio Teruel
# Copyright 2017 Tecnativa - David Vidal # 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 import mock
from odoo.tests import common from odoo.tests import common
@ -11,27 +12,23 @@ class TestResPartner(common.TransactionCase):
super(TestResPartner, self).setUp() super(TestResPartner, self).setUp()
self.company = self.env.user.company_id self.company = self.env.user.company_id
self.company.vat_check_vies = True self.company.vat_check_vies = True
self.partner = self.env['res.partner'].create({ self.partner = self.env["res.partner"].create({"name": "Test partner"})
'name': 'Test partner', self.vatnumber_path = "odoo.addons.base_vat.models.res_partner.vatnumber"
})
self.vatnumber_path = (
'odoo.addons.base_vat.models.res_partner.vatnumber'
)
def test_validate_vat_vies(self): def test_validate_vat_vies(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber: with mock.patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = True mock_vatnumber.check_vies.return_value = True
self.partner.vat = 'ESB87530432' self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, True) self.assertEqual(self.partner.vies_passed, True)
def test_exception_vat_vies(self): def test_exception_vat_vies(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber: with mock.patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.side_effect = Exception() mock_vatnumber.check_vies.side_effect = Exception()
self.partner.vat = 'ESB87530432' self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, False) self.assertEqual(self.partner.vies_passed, False)
def test_no_validate_vat(self): def test_no_validate_vat(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber: with mock.patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = False mock_vatnumber.check_vies.return_value = False
self.partner.vat = 'ESB87530432' self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, False) self.assertEqual(self.partner.vies_passed, False)

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="view_partner_form" model="ir.ui.view"> <record id="view_partner_form" model="ir.ui.view">
<field name="name">Add VIES passed fields</field> <field name="name">Add VIES passed fields</field>
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/> <field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="vat" position="after"> <field name="vat" position="after">
<field name="vies_passed"/> <field name="vies_passed" />
</field> </field>
</field> </field>
</record> </record>