diff --git a/account_chart_update/wizard/wizard_chart_update.py b/account_chart_update/wizard/wizard_chart_update.py index 36b92ebbb..f17a2c5f0 100644 --- a/account_chart_update/wizard/wizard_chart_update.py +++ b/account_chart_update/wizard/wizard_chart_update.py @@ -783,6 +783,22 @@ class WizardUpdateChartsAccounts(models.TransientModel): } | specials_mapping.get(name, set()) return set(models.MAGIC_COLUMNS) | specials + @api.model + @tools.ormcache("name") + def fields_to_include(self, name): + """Get fields that will be used when checking differences. + + :param str name: The name of the template model. + :return set: Fields to include in diff. + """ + template_field_mapping = { + "account.tax.template": self.tax_field_ids, + "account.account.template": self.account_field_ids, + "account.fiscal.position.template": self.fp_field_ids, + "account.group.template": self.account_group_field_ids, + } + return template_field_mapping[name].mapped("name") + @api.model def diff_fields(self, template, real): # noqa: C901 """Get fields that are different in template and real records. @@ -797,13 +813,7 @@ class WizardUpdateChartsAccounts(models.TransientModel): """ result = dict() ignore = self.fields_to_ignore(template._name) - template_field_mapping = { - "account.tax.template": self.tax_field_ids, - "account.account.template": self.account_field_ids, - "account.fiscal.position.template": self.fp_field_ids, - "account.group.template": self.account_group_field_ids, - } - to_include = template_field_mapping[template._name].mapped("name") + to_include = self.fields_to_include(template._name) for key, field in template._fields.items(): if key in ignore or key not in to_include or not hasattr(real, key): continue diff --git a/account_chart_update_multilang/README.rst b/account_chart_update_multilang/README.rst new file mode 100644 index 000000000..f026e4cae --- /dev/null +++ b/account_chart_update_multilang/README.rst @@ -0,0 +1,115 @@ +============================== +Account Chart Update Multilang +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:2700ef0a3814ff75e5fffe9265dcdfc52cdabd5b8215815038888e121ad5aad7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/16.0/account_chart_update_multilang + :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-16-0/account-financial-tools-16-0-account_chart_update_multilang + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of ``account_chart_update`` so +that if taxes or fiscal position templates have translated fields, they +are passed to the final taxes or fiscal positions when applying the +chart of accounts. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +It is not necessary to apply any previous configuration to use this +module, but you may want to load some translation to taxes or fiscal +positions beforehand. + +You can do this by installing account_usability to be able to view the +templates and edit their translations. Or you can include translations +in a custom module inside the i18n_extra folder. + +Usage +===== + +To use this module simply follow the steps in the USAGE section of the +``account_chart_update`` module. + +You can find the documentation here: +https://github.com/OCA/account-financial-tools/blob/16.0/account_chart_update/readme/USAGE.rst + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Moduon + +Contributors +------------ + +- Eduardo López (https://www.moduon.team/) + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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-edlopen| image:: https://github.com/edlopen.png?size=40px + :target: https://github.com/edlopen + :alt: edlopen +.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px + :target: https://github.com/rafaelbn + :alt: rafaelbn + +Current `maintainers `__: + +|maintainer-edlopen| |maintainer-rafaelbn| + +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_multilang/__init__.py b/account_chart_update_multilang/__init__.py new file mode 100644 index 000000000..5cb1c4914 --- /dev/null +++ b/account_chart_update_multilang/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/account_chart_update_multilang/__manifest__.py b/account_chart_update_multilang/__manifest__.py new file mode 100644 index 000000000..fa43ac9f5 --- /dev/null +++ b/account_chart_update_multilang/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2024 Moduon Team S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "Account Chart Update Multilang", + "summary": "Update tax and fiscal position templates with multilang", + "version": "16.0.1.0.0", + "development_status": "Alpha", + "category": "Accounting", + "website": "https://github.com/OCA/account-financial-tools", + "author": "Moduon, Odoo Community Association (OCA)", + "maintainers": ["edlopen", "rafaelbn"], + "license": "AGPL-3", + "auto_install": True, + "installable": True, + "depends": [ + "account_chart_update", + "l10n_multilang", + ], +} diff --git a/account_chart_update_multilang/readme/CONFIGURE.md b/account_chart_update_multilang/readme/CONFIGURE.md new file mode 100644 index 000000000..de5986725 --- /dev/null +++ b/account_chart_update_multilang/readme/CONFIGURE.md @@ -0,0 +1,3 @@ +It is not necessary to apply any previous configuration to use this module, but you may want to load some translation to taxes or fiscal positions beforehand. + +You can do this by installing account_usability to be able to view the templates and edit their translations. Or you can include translations in a custom module inside the i18n_extra folder. diff --git a/account_chart_update_multilang/readme/CONTRIBUTORS.md b/account_chart_update_multilang/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..8d73b120e --- /dev/null +++ b/account_chart_update_multilang/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +* Eduardo López (https://www.moduon.team/) diff --git a/account_chart_update_multilang/readme/DESCRIPTION.md b/account_chart_update_multilang/readme/DESCRIPTION.md new file mode 100644 index 000000000..9ecd13891 --- /dev/null +++ b/account_chart_update_multilang/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module extends the functionality of `account_chart_update` so that if taxes or fiscal position templates have translated fields, they are passed to the final taxes or fiscal positions when applying the chart of accounts. diff --git a/account_chart_update_multilang/readme/USAGE.md b/account_chart_update_multilang/readme/USAGE.md new file mode 100644 index 000000000..d4568a553 --- /dev/null +++ b/account_chart_update_multilang/readme/USAGE.md @@ -0,0 +1,3 @@ +To use this module simply follow the steps in the USAGE section of the `account_chart_update` module. + +You can find the documentation here: https://github.com/OCA/account-financial-tools/blob/16.0/account_chart_update/readme/USAGE.rst diff --git a/account_chart_update_multilang/static/description/icon.png b/account_chart_update_multilang/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/account_chart_update_multilang/static/description/icon.png differ diff --git a/account_chart_update_multilang/static/description/index.html b/account_chart_update_multilang/static/description/index.html new file mode 100644 index 000000000..d3bcbe7b8 --- /dev/null +++ b/account_chart_update_multilang/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +Account Chart Update Multilang + + + +
+

Account Chart Update Multilang

+ + +

Alpha License: AGPL-3 OCA/account-financial-tools Translate me on Weblate Try me on Runboat

+

This module extends the functionality of account_chart_update so +that if taxes or fiscal position templates have translated fields, they +are passed to the final taxes or fiscal positions when applying the +chart of accounts.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Configuration

+

It is not necessary to apply any previous configuration to use this +module, but you may want to load some translation to taxes or fiscal +positions beforehand.

+

You can do this by installing account_usability to be able to view the +templates and edit their translations. Or you can include translations +in a custom module inside the i18n_extra folder.

+
+
+

Usage

+

To use this module simply follow the steps in the USAGE section of the +account_chart_update module.

+

You can find the documentation here: +https://github.com/OCA/account-financial-tools/blob/16.0/account_chart_update/readme/USAGE.rst

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Moduon
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainers:

+

edlopen rafaelbn

+

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_multilang/tests/__init__.py b/account_chart_update_multilang/tests/__init__.py new file mode 100644 index 000000000..01df1888b --- /dev/null +++ b/account_chart_update_multilang/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_chart_update_multilang diff --git a/account_chart_update_multilang/tests/test_account_chart_update_multilang.py b/account_chart_update_multilang/tests/test_account_chart_update_multilang.py new file mode 100644 index 000000000..494395400 --- /dev/null +++ b/account_chart_update_multilang/tests/test_account_chart_update_multilang.py @@ -0,0 +1,44 @@ +# Copyright 2024 Moduon Team S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from odoo.tests import tagged + +from odoo.addons.account_chart_update.tests.common import TestAccountChartUpdateCommon + + +@tagged("-at_install", "post_install") +class TestAccountChartUpdate(TestAccountChartUpdateCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + lang_model = cls.env["res.lang"] + lang_model._activate_lang("en_US") + lang_model._activate_lang("es_ES") + lang_model._activate_lang("fr_FR") + cls.tax_template.with_context(lang="en_US").description = "tax description eng" + cls.tax_template.with_context(lang="es_ES").name = "tax name es" + cls.tax_template.with_context(lang="es_ES").description = "tax description es" + cls.tax_template.with_context(lang="fr_FR").name = "tax name fr" + cls.tax_template.with_context(lang="fr_FR").description = "tax description fr" + + def test_update_taxes(self): + wizard = self.wizard_obj.create(self.wizard_vals) + wizard.action_find_records() + wizard.action_update_records() + new_tax = self.env["account.tax"].search( + [ + ("name", "=", self.tax_template.name), + ("company_id", "=", self.company.id), + ] + ) + self.assertEqual( + new_tax.with_context(lang="en_EN").description, "tax description eng" + ) + self.assertEqual(new_tax.with_context(lang="es_ES").name, "tax name es") + self.assertEqual( + new_tax.with_context(lang="es_ES").description, "tax description es" + ) + self.assertEqual(new_tax.with_context(lang="fr_FR").name, "tax name fr") + self.assertEqual( + new_tax.with_context(lang="fr_FR").description, "tax description fr" + ) diff --git a/account_chart_update_multilang/wizards/__init__.py b/account_chart_update_multilang/wizards/__init__.py new file mode 100644 index 000000000..fbd95d57b --- /dev/null +++ b/account_chart_update_multilang/wizards/__init__.py @@ -0,0 +1 @@ +from . import wizard_chart_update diff --git a/account_chart_update_multilang/wizards/wizard_chart_update.py b/account_chart_update_multilang/wizards/wizard_chart_update.py new file mode 100644 index 000000000..3c39f05ba --- /dev/null +++ b/account_chart_update_multilang/wizards/wizard_chart_update.py @@ -0,0 +1,57 @@ +# Copyright 2024 Moduon Team S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from odoo import models +from odoo.tools import ormcache + + +class WizardUpdateChartsAccount(models.TransientModel): + _inherit = "wizard.update.charts.accounts" + + @ormcache("self.lang") + def _other_langs(self): + return self.env["res.lang"].search([("code", "!=", self.lang)]).mapped("code") + + def _update_other_langs(self, templates): + for _, tpl_xmlid in templates.get_external_id().items(): + template = self.env.ref(tpl_xmlid) + module, xmlid = tpl_xmlid.split(".", 1) + rec_xmlid = f"{module}.{self.company_id.id}_{xmlid}" + rec = self.env.ref(rec_xmlid) + for lang in self._other_langs(): + lang_tpl = template.with_context(lang=lang) + for key in self._diff_translate_fields(template, rec): + lang_rec = rec.with_context(lang=lang) + lang_rec[key] = lang_tpl[key] + + def _diff_translate_fields(self, template, real): + """Find differences by comparing the translations of the fields.""" + res = {} + to_include = self.fields_to_include(template._name) + for key in template._fields: + if not template._fields[key].translate or key not in to_include: + continue + for lang in self._other_langs(): + template_trans = getattr(template.with_context(lang=lang), key) + real_trans = getattr(real.with_context(lang=lang), key) + if template_trans != real_trans: + res[key] = template[key] + return res + + def diff_fields(self, template, real): + """Compare template and real translations too.""" + res = super().diff_fields(template, real) + res.update(self._diff_translate_fields(template, real)) + return res + + def _update_taxes(self): + """Update the taxes with their template translations.""" + res = super()._update_taxes() + self._update_other_langs(self.tax_ids.tax_id) + return res + + def _update_fiscal_positions(self): + """Update the fiscal positions with their template translations.""" + res = super()._update_fiscal_positions() + self._update_other_langs(self.fiscal_position_ids.fiscal_position_id) + return res diff --git a/setup/account_chart_update_multilang/odoo/addons/account_chart_update_multilang b/setup/account_chart_update_multilang/odoo/addons/account_chart_update_multilang new file mode 120000 index 000000000..c6d227615 --- /dev/null +++ b/setup/account_chart_update_multilang/odoo/addons/account_chart_update_multilang @@ -0,0 +1 @@ +../../../../account_chart_update_multilang \ No newline at end of file diff --git a/setup/account_chart_update_multilang/setup.py b/setup/account_chart_update_multilang/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_chart_update_multilang/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)