[ADD]base_translation_field_label

Replace non human readable field description for the field label.
pull/2689/head
GuillemCForgeFlow 2023-07-14 16:53:05 +02:00 committed by JasminSForgeFlow
parent 8bfea32fee
commit a403556d53
10 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1 @@
from . import models

View File

@ -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,
}

View File

@ -0,0 +1 @@
from . import ir_translation

View File

@ -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

View File

@ -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.

View File

@ -0,0 +1,3 @@
* `ForgeFlow S.L. <https://www.forgeflow.com>`_:
* Guillem Casassas <guillem.casassas@forgeflow.com>

View File

@ -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.

View File

@ -0,0 +1 @@
from . import test_base_transaltion_field_label

View File

@ -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.",
)

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_translation_tree" model="ir.ui.view">
<field name="name">ir.translation.tree - base_translation_field_label</field>
<field name="model">ir.translation</field>
<field name="inherit_id" ref="base.view_translation_tree" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="field_label" />
</field>
<field name="name" position="attributes">
<attribute name="optional">hide</attribute>
</field>
</field>
</record>
</odoo>