Merge PR #1968 into 16.0

Signed-off-by rafaelbn
This commit is contained in:
OCA-git-bot
2024-11-13 09:15:24 +00:00
11 changed files with 112 additions and 71 deletions

View File

@@ -32,7 +32,7 @@ This module extends base_vat module features allowing to know if VIES
validation was passed or not.
Then you can use "VIES validation passed" field in order to show VAT ID with
or without country preffix in invoices, for instance.
or without country prefix in invoices, for instance.
*NOTE*: Although VIES validation is set in your company, this validation
will not block VAT ID write (main difference to Odoo standard behavior) if this
@@ -97,6 +97,7 @@ Contributors
* Harald Panten <harald.panten@sygel.es>
* Eduardo de Miguel <edu@moduon.team>
* Emilio Pascual <emilio@moduon.team>
* Jairo Llopis (`Moduon <https://www.moduon.team/>`__)
Maintainers
~~~~~~~~~~~
@@ -111,6 +112,17 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
.. |maintainer-yajo| image:: https://github.com/yajo.png?size=40px
:target: https://github.com/yajo
:alt: yajo
.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px
:target: https://github.com/rafaelbn
:alt: rafaelbn
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-yajo| |maintainer-rafaelbn|
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/16.0/base_vat_optional_vies>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -17,5 +17,6 @@
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"license": "AGPL-3",
"maintainers": ["yajo", "rafaelbn"],
"installable": True,
}

View File

@@ -1,20 +1,41 @@
# Copyright 2022-2023 Moduon Team S.L. <info@moduon.team>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from logging import getLogger
from odoo import _, models
from odoo.exceptions import ValidationError
_logger = getLogger(__name__)
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
def execute_update_check_vies(self):
# Only parent partners, children are synced from parent
count_partners = self.env["res.partner"].search_count([])
self.env["res.partner"].search([]).check_vat()
"""Bulk VAT check on company partners."""
partners = self.env["res.partner"].search(
[
("is_company", "=", True),
("parent_id", "=", False),
("vat", "!=", False),
("vies_passed", "=", False),
]
)
failures = 0
for partner in partners:
try:
partner.check_vat()
except ValidationError:
_logger.warning("VAT check failed for %r", partner, exc_info=True)
failures += 1
return {
"effect": {
"fadeout": "slow",
"message": _("Vies passed calculated in %s partners") % count_partners,
"message": _(
"Vies passed calculated in %(partners)d partners (%(failures)d failures)",
partners=len(partners),
failures=failures,
),
"img_url": "/web/static/img/smile.svg",
"type": "rainbow_man",
}

View File

@@ -4,9 +4,7 @@
# Copyright 2022 Moduon - Eduardo de Miguel
# Copyright 2023 Moduon - Emilio Pascual
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.addons.base_vat.models.res_partner import _ref_vat
from odoo import api, fields, models
class ResPartner(models.Model):
@@ -61,15 +59,3 @@ class ResPartner(models.Model):
return super(
ResPartner, self.with_context(vat_partner=self)
)._onchange_check_vies()
@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)"
),
)

View File

@@ -7,3 +7,4 @@
* Harald Panten <harald.panten@sygel.es>
* Eduardo de Miguel <edu@moduon.team>
* Emilio Pascual <emilio@moduon.team>
* Jairo Llopis (`Moduon <https://www.moduon.team/>`__)

View File

@@ -2,7 +2,7 @@ This module extends base_vat module features allowing to know if VIES
validation was passed or not.
Then you can use "VIES validation passed" field in order to show VAT ID with
or without country preffix in invoices, for instance.
or without country prefix in invoices, for instance.
*NOTE*: Although VIES validation is set in your company, this validation
will not block VAT ID write (main difference to Odoo standard behavior) if this

View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
@@ -9,10 +8,11 @@
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
@@ -275,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@ span.option {
span.pre {
white-space: pre }
span.problematic {
span.problematic, pre.problematic {
color: red }
span.section-subtitle {
@@ -373,7 +373,7 @@ ul.auto-toc {
<p>This module extends base_vat module features allowing to know if VIES
validation was passed or not.</p>
<p>Then you can use “VIES validation passed” field in order to show VAT ID with
or without country preffix in invoices, for instance.</p>
or without country prefix in invoices, for instance.</p>
<p><em>NOTE</em>: Although VIES validation is set in your company, this validation
will not block VAT ID write (main difference to Odoo standard behavior) if this
VAT ID is valid in its country.</p>
@@ -441,15 +441,20 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Harald Panten &lt;<a class="reference external" href="mailto:harald.panten&#64;sygel.es">harald.panten&#64;sygel.es</a>&gt;</li>
<li>Eduardo de Miguel &lt;<a class="reference external" href="mailto:edu&#64;moduon.team">edu&#64;moduon.team</a>&gt;</li>
<li>Emilio Pascual &lt;<a class="reference external" href="mailto:emilio&#64;moduon.team">emilio&#64;moduon.team</a>&gt;</li>
<li>Jairo Llopis (<a class="reference external" href="https://www.moduon.team/">Moduon</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/yajo"><img alt="yajo" src="https://github.com/yajo.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/rafaelbn"><img alt="rafaelbn" src="https://github.com/rafaelbn.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/16.0/base_vat_optional_vies">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>

View File

@@ -1 +1,2 @@
from . import test_config_settings
from . import test_res_partner

View File

@@ -1,44 +0,0 @@
# Copyright 2022-2023 Moduon Team S.L. <info@moduon.team>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from unittest import mock
from odoo.tests import common
class TestConfigSettings(common.TransactionCase):
def setUp(self):
super(TestConfigSettings, self).setUp()
self.company = self.env.user.company_id
self.partner1_test = self.env["res.partner"].create(
{
"name": "Test partner",
"is_company": True,
"vat": "ESB87530432",
"country_id": self.env.ref("base.be").id,
}
)
self.partner2_test = self.env["res.partner"].create(
{
"name": "Test partner2",
"is_company": True,
"vat": "ESB87530432",
}
)
self.vatnumber_path = "odoo.addons.base_vat.models.res_partner.check_vies"
def test_execute_update_check_vies_validate(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
self.company.vat_check_vies = True
mock_vatnumber.check_vies.return_value = True
self.env["res.config.settings"].execute_update_check_vies()
self.assertTrue(self.partner1_test.vies_passed)
self.assertFalse(self.partner2_test.vies_passed)
def test_execute_update_check_vies_no_validate(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
self.company.vat_check_vies = False
mock_vatnumber.check_vies.return_value = False
self.env["res.config.settings"].execute_update_check_vies()
self.assertFalse(self.partner1_test.vies_passed)
self.assertFalse(self.partner2_test.vies_passed)

View File

@@ -0,0 +1,54 @@
# Copyright 2024 Moduon Team S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from unittest import mock
from odoo.tests import common
from odoo.tools import mute_logger
class TestConfigSettings(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner1, cls.partner2 = (
cls.env["res.partner"]
.with_context(no_vat_validation=True)
.create(
[
{
"name": "Test partner",
"is_company": True,
"vat": "ESB87530432",
"country_id": cls.env.ref("base.es").id,
},
{
"name": "Test partner2",
"is_company": True,
"vat": "ES00000000T",
"country_id": cls.env.ref("base.es").id,
},
]
)
)
cls.config = cls.env["res.config.settings"].create({"vat_check_vies": True})
def setUp(self):
super().setUp()
self.mock_check_vies = self.startPatcher(
mock.patch(
"odoo.addons.base_vat.models.res_partner.check_vies",
side_effect=(lambda vat: {"valid": vat == "ESB87530432"}),
)
)
@mute_logger(
"odoo.addons.base_vat_optional_vies.models.res_config_settings",
"odoo.addons.base_vat.models.res_partner",
)
def test_batch_checking(self):
self.config.execute_update_check_vies()
self.mock_check_vies.assert_any_call("ESB87530432")
self.mock_check_vies.assert_any_call("ES00000000T")
self.assertTrue(self.partner1.vies_passed)
self.assertFalse(self.partner2.vies_passed)

View File

@@ -8,6 +8,7 @@ from unittest.mock import patch
from odoo.exceptions import ValidationError
from odoo.tests import common
from odoo.tools import mute_logger
class TestResPartner(common.TransactionCase):
@@ -26,6 +27,7 @@ class TestResPartner(common.TransactionCase):
cls._vies_check_func = check_vies
@mute_logger("odoo.addons.base_vat.models.res_partner")
def test_validate_vat_vies(self):
with patch(self.vatnumber_path, type(self)._vies_check_func):
values = {"vat": "ESB87530432", "country_id": self.env.ref("base.be").id}
@@ -40,6 +42,7 @@ class TestResPartner(common.TransactionCase):
self.partner.write(values)
self.assertEqual(self.partner.vies_passed, True)
@mute_logger("odoo.addons.base_vat.models.res_partner")
def test_exception_vat_vies(self):
with patch(self.vatnumber_path, side_effect=Exception()):
values = {"vat": "87530432", "country_id": self.env.ref("base.es").id}
@@ -69,6 +72,7 @@ class TestResPartner(common.TransactionCase):
self.partner.country_id = self.env.ref("base.mx")
self.assertEqual(self.partner.vies_passed, False)
@mute_logger("odoo.addons.base_vat.models.res_partner")
def test_validate_vies_passed_false_when_vat_set_to_false(self):
with patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = True