From e5151026a5836e0c3d88aafd3628394ada8394c5 Mon Sep 17 00:00:00 2001 From: "Luis J. Salvatierra" Date: Wed, 18 Jan 2023 11:56:15 +0100 Subject: [PATCH] [MIG] account_chart_update: Migration to 16.0 --- account_chart_update/README.rst | 13 +++-- account_chart_update/__manifest__.py | 2 +- account_chart_update/readme/CONTRIBUTORS.rst | 3 ++ .../tests/test_account_chart_update.py | 43 +++++++--------- .../wizard/wizard_chart_update.py | 23 +++++++-- .../wizard/wizard_chart_update_view.xml | 49 ++++++++++--------- 6 files changed, 74 insertions(+), 59 deletions(-) diff --git a/account_chart_update/README.rst b/account_chart_update/README.rst index 2fcfb412..c1dcc9b6 100644 --- a/account_chart_update/README.rst +++ b/account_chart_update/README.rst @@ -14,16 +14,16 @@ Detect changes and update the Account Chart from a template :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github - :target: https://github.com/OCA/account-financial-tools/tree/15.0/account_chart_update + :target: https://github.com/OCA/account-financial-tools/tree/16.0/account_chart_update :alt: OCA/account-financial-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png :target: https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_chart_update :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/92/15.0 + :target: https://runbot.odoo-community.org/runbot/92/16.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| This is a pretty useful tool to update Odoo installations after tax reforms on the official charts of accounts, or to apply fixes performed on the chart @@ -69,7 +69,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -97,6 +97,9 @@ Contributors * Alberto Martín - Guadaltech * Fernando La Chica - GreenIce * Jairo Llopis (https://www.moduon.team/) +* `Factor Libre `_: + + * Luis J. Salvatierra Maintainers ~~~~~~~~~~~ @@ -111,6 +114,6 @@ 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. -This module is part of the `OCA/account-financial-tools `_ project on GitHub. +This module is part of the `OCA/account-financial-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_chart_update/__manifest__.py b/account_chart_update/__manifest__.py index af561657..0fc9460e 100644 --- a/account_chart_update/__manifest__.py +++ b/account_chart_update/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Detect changes and update the Account Chart from a template", "summary": "Wizard to update a company's account chart from a template", - "version": "15.0.1.2.0", + "version": "16.0.1.0.0", "author": "Tecnativa, BCIM, Okia, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "depends": ["account", "l10n_generic_coa"], diff --git a/account_chart_update/readme/CONTRIBUTORS.rst b/account_chart_update/readme/CONTRIBUTORS.rst index 7308e634..6ba92f4e 100644 --- a/account_chart_update/readme/CONTRIBUTORS.rst +++ b/account_chart_update/readme/CONTRIBUTORS.rst @@ -9,3 +9,6 @@ * Alberto Martín - Guadaltech * Fernando La Chica - GreenIce * Jairo Llopis (https://www.moduon.team/) +* `Factor Libre `_: + + * Luis J. Salvatierra diff --git a/account_chart_update/tests/test_account_chart_update.py b/account_chart_update/tests/test_account_chart_update.py index 4c8a98c7..567761d0 100644 --- a/account_chart_update/tests/test_account_chart_update.py +++ b/account_chart_update/tests/test_account_chart_update.py @@ -23,12 +23,12 @@ class TestAccountChartUpdate(common.HttpCase): } ) - def _create_account_tmpl(self, name, code, user_type, chart_template): + def _create_account_tmpl(self, name, code, account_type, chart_template): record = self.env["account.account.template"].create( { "name": name, "code": code, - "user_type_id": user_type.id, + "account_type": account_type, "chart_template_id": chart_template and chart_template.id, } ) @@ -118,26 +118,19 @@ class TestAccountChartUpdate(common.HttpCase): ] } ) - self.account_type = self.env["account.account.type"].create( - { - "name": "Test account_chart_update account type", - "internal_group": "income", - } - ) self.account_template = self._create_account_tmpl( - "Test", "100000", self.account_type, False + "Test", "100000", "income", False ) self.chart_template = self.env.ref( "l10n_generic_coa.configurable_chart_template" ) # Avoid re-creating taxes. # If false, the taxes that are created will be overwrited. - self.chart_template.complete_tax_set = True self.account_template.chart_template_id = self.chart_template.id self.account_template_pl = self._create_account_tmpl( "Undistributed Profits/Losses", "999999", - self.env.ref("account.data_unaffected_earnings"), + "equity", self.chart_template, ) self.tax_template = self._create_tax_tmpl("Test tax", self.chart_template) @@ -236,7 +229,7 @@ class TestAccountChartUpdate(common.HttpCase): {"tag_ids": [(6, 0, self.account_tag_1.ids)]} ) new_account_tmpl = self._create_account_tmpl( - "Test account 2", "333333", self.account_type, self.chart_template + "Test account 2", "333333", "income", self.chart_template ) new_fp = self._create_fp_tmpl("Test fp 2", self.chart_template) fp_template_tax = self.env["account.fiscal.position.tax.template"].create( @@ -450,7 +443,7 @@ class TestAccountChartUpdate(common.HttpCase): # Errors on account_creation self.account_template.currency_id = False new_account_tmpl_2 = self._create_account_tmpl( - "Test account 3", "444444", self.account_type, self.chart_template + "Test account 3", "444444", "income", self.chart_template ) wizard = self.wizard_obj.create(self.wizard_vals) wizard.action_find_records() @@ -543,9 +536,9 @@ class TestAccountChartUpdate(common.HttpCase): wizard.fiscal_position_ids.fiscal_position_id, self.fp_template ) # There is no XML-ID - self.assertFalse(list(self.tax.get_xml_id().values())[0]) - self.assertFalse(list(self.account.get_xml_id().values())[0]) - self.assertFalse(list(self.fp.get_xml_id().values())[0]) + self.assertFalse(list(self.tax.get_external_id().values())[0]) + self.assertFalse(list(self.account.get_external_id().values())[0]) + self.assertFalse(list(self.fp.get_external_id().values())[0]) # Update for recreating XML-ID wizard.action_update_records() self.assertEqual(wizard.updated_taxes, 1) @@ -555,9 +548,9 @@ class TestAccountChartUpdate(common.HttpCase): self.assertEqual(self.account.name, self.account_template.name) self.assertEqual(self.fp.note, self.fp_template.note) # There is XML-ID now - self.assertTrue(list(self.tax.get_xml_id().values())[0]) - self.assertTrue(list(self.account.get_xml_id().values())[0]) - self.assertTrue(list(self.fp.get_xml_id().values())[0]) + self.assertTrue(list(self.tax.get_external_id().values())[0]) + self.assertTrue(list(self.account.get_external_id().values())[0]) + self.assertTrue(list(self.fp.get_external_id().values())[0]) wizard.unlink() # Test 2 recreate XML-ID @@ -575,16 +568,16 @@ class TestAccountChartUpdate(common.HttpCase): wizard.fiscal_position_ids.fiscal_position_id, self.fp_template ) # There is no XML-ID - self.assertFalse(list(self.tax.get_xml_id().values())[0]) - self.assertFalse(list(self.account.get_xml_id().values())[0]) - self.assertFalse(list(self.fp.get_xml_id().values())[0]) + self.assertFalse(list(self.tax.get_external_id().values())[0]) + self.assertFalse(list(self.account.get_external_id().values())[0]) + self.assertFalse(list(self.fp.get_external_id().values())[0]) # Update for recreating XML-ID wizard.action_update_records() self.assertEqual(wizard.updated_taxes, 1) self.assertEqual(wizard.updated_accounts, 1) self.assertEqual(wizard.updated_fps, 1) # There is XML-ID now - self.assertTrue(list(self.tax.get_xml_id().values())[0]) - self.assertTrue(list(self.account.get_xml_id().values())[0]) - self.assertTrue(list(self.fp.get_xml_id().values())[0]) + self.assertTrue(list(self.tax.get_external_id().values())[0]) + self.assertTrue(list(self.account.get_external_id().values())[0]) + self.assertTrue(list(self.fp.get_external_id().values())[0]) wizard.unlink() diff --git a/account_chart_update/wizard/wizard_chart_update.py b/account_chart_update/wizard/wizard_chart_update.py index 714888e1..587f3430 100644 --- a/account_chart_update/wizard/wizard_chart_update.py +++ b/account_chart_update/wizard/wizard_chart_update.py @@ -448,12 +448,24 @@ class WizardUpdateChartsAccounts(models.TransientModel): repartition_type = tpl.repartition_type account_id = self.find_account_by_templates(tpl.account_id) tags = self.env["account.account.tag"] - tags += tpl.plus_report_line_ids.mapped("tag_ids").filtered( - lambda x: not x.tax_negate + plus_expressions = tpl.plus_report_expression_ids.filtered( + lambda x: x.engine == "tax_tags" ) - tags += tpl.minus_report_line_ids.mapped("tag_ids").filtered( - lambda x: x.tax_negate + for expression in plus_expressions: + country = expression.report_line_id.report_id.country_id + existing_tags = self.env["account.account.tag"]._get_tax_tags( + expression.formula, country.id + ) + tags |= existing_tags.filtered(lambda x: not x.tax_negate) + minus_expressions = tpl.minus_report_expression_ids.filtered( + lambda x: x.engine == "tax_tags" ) + for expression in minus_expressions: + country = expression.report_line_id.report_id.country_id + existing_tags = self.env["account.account.tag"]._get_tax_tags( + expression.formula, country.id + ) + tags |= existing_tags.filtered(lambda x: x.tax_negate) tags += tpl.tag_ids existing = self.env["account.tax.repartition.line"] existing_candidates = current_repartition.filtered( @@ -719,7 +731,8 @@ class WizardUpdateChartsAccounts(models.TransientModel): if expected != [] and ( key in ["invoice_repartition_line_ids", "refund_repartition_line_ids"] - or expected != real[key] + or (isinstance(expected, models.Model) and expected != real[key]) + or (not isinstance(expected, models.Model)) ): result[key] = expected else: diff --git a/account_chart_update/wizard/wizard_chart_update_view.xml b/account_chart_update/wizard/wizard_chart_update_view.xml index 96773635..7640fb61 100644 --- a/account_chart_update/wizard/wizard_chart_update_view.xml +++ b/account_chart_update/wizard/wizard_chart_update_view.xml @@ -16,7 +16,7 @@ statusbar_colors='{"ready":"blue","done":"blue"}' /> - +

@@ -26,7 +26,7 @@

- +
- +

If you leave these options set, the wizard will @@ -70,7 +70,7 @@ Note: Only the changed fields are updated.

- +