From a403556d53795c7c9f99255daba5c50c508a222f Mon Sep 17 00:00:00 2001 From: GuillemCForgeFlow Date: Fri, 14 Jul 2023 16:53:05 +0200 Subject: [PATCH] [ADD]base_translation_field_label Replace non human readable field description for the field label. --- base_translation_field_label/__init__.py | 1 + base_translation_field_label/__manifest__.py | 18 ++++++++ .../models/__init__.py | 1 + .../models/ir_translation.py | 22 ++++++++++ .../readme/CONFIGURE.rst | 2 + .../readme/CONTRIBUTORS.rst | 3 ++ .../readme/DESCRIPTION.rst | 4 ++ .../tests/__init__.py | 1 + .../test_base_transaltion_field_label.py | 43 +++++++++++++++++++ .../views/ir_translation_views.xml | 16 +++++++ 10 files changed, 111 insertions(+) create mode 100644 base_translation_field_label/__init__.py create mode 100644 base_translation_field_label/__manifest__.py create mode 100644 base_translation_field_label/models/__init__.py create mode 100644 base_translation_field_label/models/ir_translation.py create mode 100644 base_translation_field_label/readme/CONFIGURE.rst create mode 100644 base_translation_field_label/readme/CONTRIBUTORS.rst create mode 100644 base_translation_field_label/readme/DESCRIPTION.rst create mode 100644 base_translation_field_label/tests/__init__.py create mode 100644 base_translation_field_label/tests/test_base_transaltion_field_label.py create mode 100644 base_translation_field_label/views/ir_translation_views.xml diff --git a/base_translation_field_label/__init__.py b/base_translation_field_label/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/base_translation_field_label/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_translation_field_label/__manifest__.py b/base_translation_field_label/__manifest__.py new file mode 100644 index 000000000..6769df8c5 --- /dev/null +++ b/base_translation_field_label/__manifest__.py @@ -0,0 +1,18 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Base Translation Field Label", + "summary": """ + Shows the field label and optionally hides the Translated field value. + """, + "version": "13.0.1.0.0", + "category": "Generic Modules/Base", + "license": "AGPL-3", + "website": "https://github.com/OCA/server-tools", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "depends": ["base"], + "data": ["views/ir_translation_views.xml"], + "maintainers": ["GuillemCForgeFlow"], + "installable": True, + "application": False, +} diff --git a/base_translation_field_label/models/__init__.py b/base_translation_field_label/models/__init__.py new file mode 100644 index 000000000..d51399ac5 --- /dev/null +++ b/base_translation_field_label/models/__init__.py @@ -0,0 +1 @@ +from . import ir_translation diff --git a/base_translation_field_label/models/ir_translation.py b/base_translation_field_label/models/ir_translation.py new file mode 100644 index 000000000..e6d183e8a --- /dev/null +++ b/base_translation_field_label/models/ir_translation.py @@ -0,0 +1,22 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class IrTranslation(models.Model): + _inherit = "ir.translation" + + field_label = fields.Char(string="Translated Field", compute="_compute_field_label") + + value = fields.Text(string="Translated Value") + + @api.depends("name") + def _compute_field_label(self): + for it in self: + field_label = it.name + if it.name and "," in it.name and it.name.count(",") == 1: + model_name, field_name = it.name.split(",") + model = self.env.get(model_name) + if model is not None and field_name in model._fields: + field_label = model._fields[field_name].string + it.field_label = field_label diff --git a/base_translation_field_label/readme/CONFIGURE.rst b/base_translation_field_label/readme/CONFIGURE.rst new file mode 100644 index 000000000..3e90f7a28 --- /dev/null +++ b/base_translation_field_label/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +Simply install the module, to access the Settings > Translations > Application Terms +> Translated Terms menu you need to have the Developer Mode enabled. diff --git a/base_translation_field_label/readme/CONTRIBUTORS.rst b/base_translation_field_label/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..a502d31e5 --- /dev/null +++ b/base_translation_field_label/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `ForgeFlow S.L. `_: + + * Guillem Casassas diff --git a/base_translation_field_label/readme/DESCRIPTION.rst b/base_translation_field_label/readme/DESCRIPTION.rst new file mode 100644 index 000000000..5fcfafd48 --- /dev/null +++ b/base_translation_field_label/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This addon adds the field label on translated terms. Each translated term is +referencing an Odoo field, but the name stated there is not human readable at all, +instead, the field description is shown and the Translated field is hidden at first, +but it can be showed if needed. diff --git a/base_translation_field_label/tests/__init__.py b/base_translation_field_label/tests/__init__.py new file mode 100644 index 000000000..d0ddf114b --- /dev/null +++ b/base_translation_field_label/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_transaltion_field_label diff --git a/base_translation_field_label/tests/test_base_transaltion_field_label.py b/base_translation_field_label/tests/test_base_transaltion_field_label.py new file mode 100644 index 000000000..7c6e1ea55 --- /dev/null +++ b/base_translation_field_label/tests/test_base_transaltion_field_label.py @@ -0,0 +1,43 @@ +# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.tests.common import TransactionCase + + +class TestBaseTranslationFieldLabel(TransactionCase): + def setUp(self): + super().setUp() + # Models + self.translation_model = self.env["ir.translation"] + self.partner_model = self.env["res.partner"] + + # Set up + self.translation_model._load_module_terms(["base"], ["ca_ES"]) + + # Instances + self.parent_partner = self.partner_model.create({"name": "Parent Partner"}) + self.child_partner = self.partner_model.create( + {"name": "Child Partner", "parent_id": self.parent_partner.id} + ) + self.translated_term = self.translation_model.create( + { + "type": "model", + "name": "res.partner,parent_id", + "module": "base", + "lang": "ca_ES", + "res_id": self.child_partner.id, + "value": "Companyia Relacionada", + "state": "translated", + } + ) + + def test_01_check_field_label(self): + """ + Check that the field label of the translated term matches the string set on the + Odoo field. + """ + self.assertEqual( + self.translated_term.field_label, + "Related Company", + "Field Label on the translated term should match the string value on the " + "Odoo field.", + ) diff --git a/base_translation_field_label/views/ir_translation_views.xml b/base_translation_field_label/views/ir_translation_views.xml new file mode 100644 index 000000000..876dd5c3f --- /dev/null +++ b/base_translation_field_label/views/ir_translation_views.xml @@ -0,0 +1,16 @@ + + + + ir.translation.tree - base_translation_field_label + ir.translation + + + + + + + hide + + + +