mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[FIX] Simple VAT error message, always clean vies_passed field
- Simple VAT error message when an error must be shown - Always clean vies_passed field when check_vat is called [FIX] tests [FIX] Contributor emails
This commit is contained in:
committed by
Rodrigo
parent
d488e6d74c
commit
bdc3bf61f8
@@ -2,6 +2,7 @@
|
|||||||
# 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
|
||||||
|
# Copyright 2022 Moduon - Eduardo de Miguel
|
||||||
# License AGPL-3.0 or later (https://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",
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
# 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
|
||||||
|
# Copyright 2022 Moduon - Eduardo de Miguel
|
||||||
# License AGPL-3.0 or later (https://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
|
||||||
|
|
||||||
|
from odoo.addons.base_vat.models.res_partner import _ref_vat
|
||||||
|
|
||||||
|
|
||||||
class ResPartner(models.Model):
|
class ResPartner(models.Model):
|
||||||
@@ -39,7 +42,20 @@ class ResPartner(models.Model):
|
|||||||
|
|
||||||
@api.constrains("vat", "country_id")
|
@api.constrains("vat", "country_id")
|
||||||
def check_vat(self):
|
def check_vat(self):
|
||||||
|
self.update({"vies_passed": False})
|
||||||
for partner in self:
|
for partner in self:
|
||||||
partner = partner.with_context(vat_partner=partner)
|
partner = partner.with_context(vat_partner=partner)
|
||||||
super(ResPartner, partner).check_vat()
|
super(ResPartner, partner).check_vat()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _build_vat_error_message(self, country_code, wrong_vat, record_label):
|
||||||
|
return "\n" + _(
|
||||||
|
"The VAT number [%(wrong_vat)s] for %(record_label)s does not seem to be valid. "
|
||||||
|
"\nNote: the expected format is %(expected_format)s",
|
||||||
|
wrong_vat=wrong_vat,
|
||||||
|
record_label=record_label,
|
||||||
|
expected_format=_ref_vat.get(
|
||||||
|
country_code, "'CC##' (CC=Country Code, ##=VAT Number)"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
* Rafael Blasco <rafael.blasco@tecnativa.com>
|
* Rafael Blasco <rblasco@moduon.team>
|
||||||
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
|
||||||
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
||||||
* David Vidal <david.vidal@tecnativa.com>
|
* David Vidal <david.vidal@tecnativa.com>
|
||||||
* Rodrigo Bonilla <rodrigo.bonilla@factorlibre.com>
|
* Rodrigo Bonilla <rodrigo.bonilla@factorlibre.com>
|
||||||
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
||||||
* Harald Panten <harald.panten@sygel.es>
|
* Harald Panten <harald.panten@sygel.es>
|
||||||
|
* Eduardo de Miguel <edu@moduon.team>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
# 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
|
||||||
|
# Copyright 2022 Moduon - Eduardo de Miguel
|
||||||
# License AGPL-3.0 or later (https://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.exceptions import ValidationError
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
|
|
||||||
@@ -44,3 +46,17 @@ class TestResPartner(common.TransactionCase):
|
|||||||
self.partner.vat = "MXGODE561231GR8"
|
self.partner.vat = "MXGODE561231GR8"
|
||||||
self.partner.country_id = 156
|
self.partner.country_id = 156
|
||||||
self.assertEqual(self.partner.vies_passed, False)
|
self.assertEqual(self.partner.vies_passed, False)
|
||||||
|
|
||||||
|
def test_validate_vies_passed_false_when_vat_set_to_false(self):
|
||||||
|
with mock.patch(self.vatnumber_path) as mock_vatnumber:
|
||||||
|
mock_vatnumber.check_vies.return_value = True
|
||||||
|
self.partner.vat = "ESB87530432"
|
||||||
|
self.partner.country_id = 20
|
||||||
|
self.assertEqual(self.partner.vies_passed, True)
|
||||||
|
self.partner.vat = False
|
||||||
|
self.assertEqual(self.partner.vies_passed, False)
|
||||||
|
|
||||||
|
def test_validate_wrong_vat_shows_simple_message(self):
|
||||||
|
with self.assertRaisesRegex(ValidationError, "does not seem to be valid"):
|
||||||
|
self.partner.vat = "ES11111111A"
|
||||||
|
self.partner.country_id = 20
|
||||||
|
|||||||
Reference in New Issue
Block a user