diff --git a/account_chart_update/tests/__init__.py b/account_chart_update/tests/__init__.py index 0120c73b2..e7b23bdf3 100644 --- a/account_chart_update/tests/__init__.py +++ b/account_chart_update/tests/__init__.py @@ -1,3 +1,3 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - +from . import common from . import test_account_chart_update diff --git a/account_chart_update/tests/common.py b/account_chart_update/tests/common.py new file mode 100644 index 000000000..6d2b695a3 --- /dev/null +++ b/account_chart_update/tests/common.py @@ -0,0 +1,196 @@ +# Copyright 2023 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import common, tagged + + +@tagged("-at_install", "post_install") +class TestAccountChartUpdateCommon(common.TransactionCase): + @classmethod + def _create_xml_id(cls, record): + return cls.env["ir.model.data"].create( + { + "module": "account_chart_update", + "name": "{}-{}".format(record._table, record.id), + "model": record._name, + "res_id": record.id, + } + ) + + @classmethod + def _create_account_tmpl(cls, name, code, account_type, chart_template): + record = cls.env["account.account.template"].create( + { + "name": name, + "code": code, + "account_type": account_type, + "chart_template_id": chart_template and chart_template.id, + } + ) + cls._create_xml_id(record) + return record + + @classmethod + def _create_tax_tmpl(cls, name, chart_template): + record = cls.env["account.tax.template"].create( + { + "name": name, + "amount": 0, + "chart_template_id": chart_template.id, + "tax_group_id": cls.env.ref("account.tax_group_taxes").id, + "refund_repartition_line_ids": [ + (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), + (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), + (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), + ], + "invoice_repartition_line_ids": [ + (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), + (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), + (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), + ], + } + ) + cls._create_xml_id(record) + return record + + def _create_tax_template_with_account(self, name, chart_template, account): + record = self.env["account.tax.template"].create( + { + "name": name, + "amount": 0, + "chart_template_id": chart_template.id, + "tax_group_id": self.env.ref("account.tax_group_taxes").id, + "refund_repartition_line_ids": [ + (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), + ( + 0, + 0, + { + "repartition_type": "tax", + "factor_percent": 100.0, + "account_id": account.id, + }, + ), + ], + "invoice_repartition_line_ids": [ + (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), + ( + 0, + 0, + { + "repartition_type": "tax", + "factor_percent": 100.0, + "account_id": account.id, + }, + ), + ], + } + ) + self._create_xml_id(record) + return record + + @classmethod + def _create_fp_tmpl(cls, name, chart_template): + record = cls.env["account.fiscal.position.template"].create( + {"name": name, "chart_template_id": chart_template.id} + ) + cls._create_xml_id(record) + return record + + def _get_model_data(self, record): + return self.env["ir.model.data"].search( + [("model", "=", record._name), ("res_id", "=", record.id)] + ) + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env( + context=dict( + cls.env.context, + mail_create_nolog=True, + mail_create_nosubscribe=True, + mail_notrack=True, + no_reset_password=True, + tracking_disable=True, + ) + ) + cls.account_template = cls._create_account_tmpl( + "Test", "100000", "income", False + ) + cls.chart_template = cls.env["account.chart.template"].create( + { + "name": "Test account_chart_update chart", + "currency_id": cls.env.ref("base.EUR").id, + "code_digits": 6, + "cash_account_code_prefix": "570", + "bank_account_code_prefix": "572", + "transfer_account_code_prefix": "100000", + "property_account_receivable_id": cls.account_template.id, + "property_account_payable_id": cls.account_template.id, + "property_account_expense_categ_id": cls.account_template.id, + "property_account_income_categ_id": cls.account_template.id, + } + ) + cls.account_template.chart_template_id = cls.chart_template.id + cls.account_template_pl = cls._create_account_tmpl( + "Undistributed Profits/Losses", + "999999", + "equity", + cls.chart_template, + ) + cls.tax_template = cls._create_tax_tmpl("Test tax", cls.chart_template) + cls.fp_template = cls._create_fp_tmpl("Test fp", cls.chart_template) + cls.fp_template_tax = cls.env["account.fiscal.position.tax.template"].create( + {"tax_src_id": cls.tax_template.id, "position_id": cls.fp_template.id} + ) + cls._create_xml_id(cls.fp_template_tax) + cls.fp_template_account = cls.env[ + "account.fiscal.position.account.template" + ].create( + { + "account_src_id": cls.account_template.id, + "account_dest_id": cls.account_template.id, + "position_id": cls.fp_template.id, + } + ) + cls._create_xml_id(cls.fp_template_account) + cls.tax_group = cls.env["account.tax.group"].create({"name": "Test tax group"}) + cls.account_tag_1 = cls.env["account.account.tag"].create( + {"name": "Test account tag 1"} + ) + cls.account_tag_2 = cls.env["account.account.tag"].create( + {"name": "Test account tag 2"} + ) + cls.company = cls.env["res.company"].create( + { + "name": "Test account_chart_update company", + "currency_id": cls.chart_template.currency_id.id, + "country_id": cls.env.ref("base.es").id, + } + ) + chart_by_company_user = cls.chart_template.with_company(cls.company) + chart_by_company_user.try_loading() + cls.tax = cls.env["account.tax"].search( + [ + ("name", "=", cls.tax_template.name), + ("company_id", "=", cls.company.id), + ] + ) + cls.account = cls.env["account.account"].search( + [ + ("code", "=", cls.account_template.code), + ("company_id", "=", cls.company.id), + ] + ) + cls.fp = cls.env["account.fiscal.position"].search( + [("name", "=", cls.fp_template.name), ("company_id", "=", cls.company.id)] + ) + # Prepare wizard values + cls.wizard_obj = cls.env["wizard.update.charts.accounts"] + cls.wizard_vals = { + "company_id": cls.company.id, + "chart_template_id": cls.chart_template.id, + "code_digits": 6, + "lang": "en_US", + } diff --git a/account_chart_update/tests/test_account_chart_update.py b/account_chart_update/tests/test_account_chart_update.py index 53ac4376a..b3cdfe657 100644 --- a/account_chart_update/tests/test_account_chart_update.py +++ b/account_chart_update/tests/test_account_chart_update.py @@ -4,203 +4,16 @@ import logging from odoo import fields -from odoo.tests import common, tagged +from odoo.tests import tagged from odoo.tools import mute_logger +from odoo.addons.account_chart_update.tests.common import TestAccountChartUpdateCommon + _logger = logging.getLogger(__name__) @tagged("-at_install", "post_install") -class TestAccountChartUpdate(common.TransactionCase): - @classmethod - def _create_xml_id(cls, record): - return cls.env["ir.model.data"].create( - { - "module": "account_chart_update", - "name": "{}-{}".format(record._table, record.id), - "model": record._name, - "res_id": record.id, - } - ) - - @classmethod - def _create_account_tmpl(cls, name, code, account_type, chart_template): - record = cls.env["account.account.template"].create( - { - "name": name, - "code": code, - "account_type": account_type, - "chart_template_id": chart_template and chart_template.id, - } - ) - cls._create_xml_id(record) - return record - - @classmethod - def _create_tax_tmpl(cls, name, chart_template): - record = cls.env["account.tax.template"].create( - { - "name": name, - "amount": 0, - "chart_template_id": chart_template.id, - "tax_group_id": cls.env.ref("account.tax_group_taxes").id, - "refund_repartition_line_ids": [ - (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), - (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), - (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), - ], - "invoice_repartition_line_ids": [ - (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), - (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), - (0, 0, {"repartition_type": "tax", "factor_percent": 100.0}), - ], - } - ) - cls._create_xml_id(record) - return record - - def _create_tax_template_with_account(self, name, chart_template, account): - record = self.env["account.tax.template"].create( - { - "name": name, - "amount": 0, - "chart_template_id": chart_template.id, - "tax_group_id": self.env.ref("account.tax_group_taxes").id, - "refund_repartition_line_ids": [ - (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), - ( - 0, - 0, - { - "repartition_type": "tax", - "factor_percent": 100.0, - "account_id": account.id, - }, - ), - ], - "invoice_repartition_line_ids": [ - (0, 0, {"repartition_type": "base", "factor_percent": 100.0}), - ( - 0, - 0, - { - "repartition_type": "tax", - "factor_percent": 100.0, - "account_id": account.id, - }, - ), - ], - } - ) - self._create_xml_id(record) - return record - - @classmethod - def _create_fp_tmpl(cls, name, chart_template): - record = cls.env["account.fiscal.position.template"].create( - {"name": name, "chart_template_id": chart_template.id} - ) - cls._create_xml_id(record) - return record - - def _get_model_data(self, record): - return self.env["ir.model.data"].search( - [("model", "=", record._name), ("res_id", "=", record.id)] - ) - - @classmethod - def setUpClass(cls): - super().setUpClass() - cls.env = cls.env( - context=dict( - cls.env.context, - mail_create_nolog=True, - mail_create_nosubscribe=True, - mail_notrack=True, - no_reset_password=True, - tracking_disable=True, - ) - ) - cls.account_template = cls._create_account_tmpl( - "Test", "100000", "income", False - ) - cls.chart_template = cls.env["account.chart.template"].create( - { - "name": "Test account_chart_update chart", - "currency_id": cls.env.ref("base.EUR").id, - "code_digits": 6, - "cash_account_code_prefix": "570", - "bank_account_code_prefix": "572", - "transfer_account_code_prefix": "100000", - "property_account_receivable_id": cls.account_template.id, - "property_account_payable_id": cls.account_template.id, - "property_account_expense_categ_id": cls.account_template.id, - "property_account_income_categ_id": cls.account_template.id, - } - ) - cls.account_template.chart_template_id = cls.chart_template.id - cls.account_template_pl = cls._create_account_tmpl( - "Undistributed Profits/Losses", - "999999", - "equity", - cls.chart_template, - ) - cls.tax_template = cls._create_tax_tmpl("Test tax", cls.chart_template) - cls.fp_template = cls._create_fp_tmpl("Test fp", cls.chart_template) - cls.fp_template_tax = cls.env["account.fiscal.position.tax.template"].create( - {"tax_src_id": cls.tax_template.id, "position_id": cls.fp_template.id} - ) - cls._create_xml_id(cls.fp_template_tax) - cls.fp_template_account = cls.env[ - "account.fiscal.position.account.template" - ].create( - { - "account_src_id": cls.account_template.id, - "account_dest_id": cls.account_template.id, - "position_id": cls.fp_template.id, - } - ) - cls._create_xml_id(cls.fp_template_account) - cls.tax_group = cls.env["account.tax.group"].create({"name": "Test tax group"}) - cls.account_tag_1 = cls.env["account.account.tag"].create( - {"name": "Test account tag 1"} - ) - cls.account_tag_2 = cls.env["account.account.tag"].create( - {"name": "Test account tag 2"} - ) - cls.company = cls.env["res.company"].create( - { - "name": "Test account_chart_update company", - "currency_id": cls.chart_template.currency_id.id, - "country_id": cls.env.ref("base.es").id, - } - ) - chart_by_company_user = cls.chart_template.with_company(cls.company) - chart_by_company_user.try_loading() - cls.tax = cls.env["account.tax"].search( - [ - ("name", "=", cls.tax_template.name), - ("company_id", "=", cls.company.id), - ] - ) - cls.account = cls.env["account.account"].search( - [ - ("code", "=", cls.account_template.code), - ("company_id", "=", cls.company.id), - ] - ) - cls.fp = cls.env["account.fiscal.position"].search( - [("name", "=", cls.fp_template.name), ("company_id", "=", cls.company.id)] - ) - # Prepare wizard values - cls.wizard_obj = cls.env["wizard.update.charts.accounts"] - cls.wizard_vals = { - "company_id": cls.company.id, - "chart_template_id": cls.chart_template.id, - "code_digits": 6, - "lang": "en_US", - } - +class TestAccountChartUpdate(TestAccountChartUpdateCommon): @mute_logger("odoo.sql_db") def test_chart_update(self): wizard = self.wizard_obj.create(self.wizard_vals) diff --git a/account_chart_update/wizard/wizard_chart_update.py b/account_chart_update/wizard/wizard_chart_update.py index 36b92ebbb..6d3949247 100644 --- a/account_chart_update/wizard/wizard_chart_update.py +++ b/account_chart_update/wizard/wizard_chart_update.py @@ -783,6 +783,20 @@ class WizardUpdateChartsAccounts(models.TransientModel): } | specials_mapping.get(name, set()) return set(models.MAGIC_COLUMNS) | specials + 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 +811,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..2ad978299 --- /dev/null +++ b/account_chart_update_multilang/__manifest__.py @@ -0,0 +1,23 @@ +# 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", + ], + "data": [ + "wizards/wizard_chart_update_views.xml", + ], +} 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..c26ab4942 --- /dev/null +++ b/account_chart_update_multilang/wizards/wizard_chart_update.py @@ -0,0 +1,76 @@ +# Copyright 2024 Moduon Team S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +from odoo import fields, models +from odoo.tools import ormcache + + +class WizardUpdateChartsAccount(models.TransientModel): + _inherit = "wizard.update.charts.accounts" + + lang = fields.Selection(default="en_US") + + @ormcache("self.lang") + def _other_langs(self): + return self.env["res.lang"].search([("code", "!=", self.lang)]).mapped("code") + + def _get_lang_selection_options(self): + """Only can translate in base language by default.""" + en = self.env["res.lang"]._lang_get("en_US") + return [(en.code, en.name)] + + def _update_other_langs(self, templates): + for tpl_xmlid in templates.get_external_id().values(): + 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, False) + if not rec: + continue + translations = {} + for key in self._diff_translate_fields(template, rec): + for lang in self._other_langs(): + field = rec._fields[key] + old_value = field._get_stored_translations(rec).get( + rec.env.lang, "en_US" + ) + if old_value.startswith("

") and old_value.endswith("

"): + old_value = old_value[3:-4] + is_callable = callable(field.translate) + translated = template.with_context(lang=lang)[key] + translations[lang] = ( + {old_value: translated} if is_callable else translated + ) + rec.update_field_translations(key, translations) + + 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 to_include: + if not (template._fields.get(key) and template._fields[key].translate): + continue + for lang in self._other_langs(): + template_trans = template.with_context(lang=lang)[key] + real_trans = 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/account_chart_update_multilang/wizards/wizard_chart_update_views.xml b/account_chart_update_multilang/wizards/wizard_chart_update_views.xml new file mode 100644 index 000000000..5f22a2ae7 --- /dev/null +++ b/account_chart_update_multilang/wizards/wizard_chart_update_views.xml @@ -0,0 +1,14 @@ + + + + + wizard.update.charts.accounts + + + + 1 + + + + + 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, +)