Files
Jairo Llopis 8f225d8aa3 [FIX] base_vat_optional_vies: don't block mass checks
The whole point of this module is to allow VIES failures. However, when running mass checks, if one single partner failed, the whole process had to start again.

FWIW that can be also problematic due to rate limits in VIES service. For that same reason, we now skip partners that are validated already, and those that are will inherit the status from their parent anyway.

Now, the process will just continue and report failures at the end.

It includes new tests, removes dead code, and reduces pre-existing tests verbosity.

@moduon MT-7763
2024-11-12 11:36:20 +00:00

43 lines
1.3 KiB
Python

# 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):
"""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 %(partners)d partners (%(failures)d failures)",
partners=len(partners),
failures=failures,
),
"img_url": "/web/static/img/smile.svg",
"type": "rainbow_man",
}
}