From fe7e10794ff3f9282694a46c34a21ec4d6e0b6a9 Mon Sep 17 00:00:00 2001 From: Emilio Pascual Date: Sat, 12 Aug 2023 12:45:34 +0200 Subject: [PATCH 1/2] [15.0][IMP] base_vat_optional_vies: vies sync in children contact - Wizard in settings to update vies_passed field after activate check vies. --- base_vat_optional_vies/__manifest__.py | 6 ++- base_vat_optional_vies/models/__init__.py | 1 + .../models/res_config_settings.py | 23 ++++++++++ base_vat_optional_vies/models/res_partner.py | 1 + .../readme/CONTRIBUTORS.rst | 1 + .../tests/tes_config_settings.py | 44 +++++++++++++++++++ .../views/res_config_settings_view.xml | 27 ++++++++++++ 7 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 base_vat_optional_vies/models/res_config_settings.py create mode 100644 base_vat_optional_vies/tests/tes_config_settings.py create mode 100644 base_vat_optional_vies/views/res_config_settings_view.xml diff --git a/base_vat_optional_vies/__manifest__.py b/base_vat_optional_vies/__manifest__.py index ce19365f..5084bce7 100644 --- a/base_vat_optional_vies/__manifest__.py +++ b/base_vat_optional_vies/__manifest__.py @@ -3,13 +3,17 @@ # Copyright 2017 Tecnativa - David Vidal # Copyright 2019 FactorLibre - Rodrigo Bonilla # Copyright 2022 Moduon - Eduardo de Miguel +# Copyright 2023 Moduon - Emilio Pascual # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Optional validation of VAT via VIES", "category": "Accounting", "version": "16.0.1.0.1", "depends": ["base_vat"], - "data": ["views/res_partner_view.xml"], + "data": [ + "views/res_partner_view.xml", + "views/res_config_settings_view.xml", + ], "author": "Tecnativa," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "license": "AGPL-3", diff --git a/base_vat_optional_vies/models/__init__.py b/base_vat_optional_vies/models/__init__.py index 91fed54d..0d7a048a 100644 --- a/base_vat_optional_vies/models/__init__.py +++ b/base_vat_optional_vies/models/__init__.py @@ -1 +1,2 @@ from . import res_partner +from . import res_config_settings diff --git a/base_vat_optional_vies/models/res_config_settings.py b/base_vat_optional_vies/models/res_config_settings.py new file mode 100644 index 00000000..4208eb71 --- /dev/null +++ b/base_vat_optional_vies/models/res_config_settings.py @@ -0,0 +1,23 @@ +# Copyright 2022-2023 Moduon Team S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import _, models + + +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( + [("parent_id", "=", False)] + ) + self.env["res.partner"].search([("parent_id", "=", False)]).check_vat() + return { + "effect": { + "fadeout": "slow", + "message": _("Vies passed calculated in %s partners") % count_partners, + "img_url": "/web/static/src/img/smile.svg", + "type": "rainbow_man", + } + } diff --git a/base_vat_optional_vies/models/res_partner.py b/base_vat_optional_vies/models/res_partner.py index a629c199..b76b6c5f 100644 --- a/base_vat_optional_vies/models/res_partner.py +++ b/base_vat_optional_vies/models/res_partner.py @@ -2,6 +2,7 @@ # Copyright 2017 Tecnativa - David Vidal # Copyright 2019 FactorLibre - Rodrigo Bonilla # 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 diff --git a/base_vat_optional_vies/readme/CONTRIBUTORS.rst b/base_vat_optional_vies/readme/CONTRIBUTORS.rst index d86e534d..c24f5cdc 100644 --- a/base_vat_optional_vies/readme/CONTRIBUTORS.rst +++ b/base_vat_optional_vies/readme/CONTRIBUTORS.rst @@ -6,3 +6,4 @@ * Alexandre Díaz * Harald Panten * Eduardo de Miguel +* Emilio Pascual diff --git a/base_vat_optional_vies/tests/tes_config_settings.py b/base_vat_optional_vies/tests/tes_config_settings.py new file mode 100644 index 00000000..93cd3687 --- /dev/null +++ b/base_vat_optional_vies/tests/tes_config_settings.py @@ -0,0 +1,44 @@ +# Copyright 2022-2023 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 + + +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) diff --git a/base_vat_optional_vies/views/res_config_settings_view.xml b/base_vat_optional_vies/views/res_config_settings_view.xml new file mode 100644 index 00000000..bba75d86 --- /dev/null +++ b/base_vat_optional_vies/views/res_config_settings_view.xml @@ -0,0 +1,27 @@ + + + + + res.config.settings.view.form.inherit.account + res.config.settings + + + +