[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:
parent
d488e6d74c
commit
bdc3bf61f8
@ -2,6 +2,7 @@
|
||||
# Copyright 2016 Tecnativa - Sergio Teruel
|
||||
# Copyright 2017 Tecnativa - David Vidal
|
||||
# Copyright 2019 FactorLibre - Rodrigo Bonilla
|
||||
# Copyright 2022 Moduon - Eduardo de Miguel
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
"name": "Optional validation of VAT via VIES",
|
||||
|
@ -1,8 +1,11 @@
|
||||
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||
# Copyright 2017 Tecnativa - David Vidal
|
||||
# Copyright 2019 FactorLibre - Rodrigo Bonilla
|
||||
# Copyright 2022 Moduon - Eduardo de Miguel
|
||||
# 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):
|
||||
@ -39,7 +42,20 @@ class ResPartner(models.Model):
|
||||
|
||||
@api.constrains("vat", "country_id")
|
||||
def check_vat(self):
|
||||
self.update({"vies_passed": False})
|
||||
for partner in self:
|
||||
partner = partner.with_context(vat_partner=partner)
|
||||
super(ResPartner, partner).check_vat()
|
||||
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>
|
||||
* Sergio Teruel <sergio.teruel@tecnativa.com>
|
||||
* David Vidal <david.vidal@tecnativa.com>
|
||||
* Rodrigo Bonilla <rodrigo.bonilla@factorlibre.com>
|
||||
* Alexandre Díaz <alexandre.diaz@tecnativa.com>
|
||||
* Harald Panten <harald.panten@sygel.es>
|
||||
* Eduardo de Miguel <edu@moduon.team>
|
||||
|
@ -1,10 +1,12 @@
|
||||
# Copyright 2015 Tecnativa - Antonio Espinosa
|
||||
# Copyright 2016 Tecnativa - Sergio Teruel
|
||||
# Copyright 2017 Tecnativa - David Vidal
|
||||
# Copyright 2022 Moduon - Eduardo de Miguel
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import mock
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
@ -44,3 +46,17 @@ class TestResPartner(common.TransactionCase):
|
||||
self.partner.vat = "MXGODE561231GR8"
|
||||
self.partner.country_id = 156
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user