Skip to content

Commit b30da81

Browse files
[IMP] product_category_name_translatable: add setting for language to use on compute complete name
1 parent e80a17c commit b30da81

File tree

9 files changed

+122
-7
lines changed

9 files changed

+122
-7
lines changed

product_category_name_translatable/README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Product Category Name Translatable
3030

3131
This module allows you to translate product category names.
3232

33+
The feature of translating the product category name was removed from
34+
Odoo core due to limitations on the complete name compute when the name
35+
is translatable: https://github.com/odoo/odoo/pull/36717.
36+
37+
To solve it, a setting is available to choose the language you want to
38+
use for displaying the complete name of product categories in the
39+
system.
40+
3341
**Table of contents**
3442

3543
.. contents::

product_category_name_translatable/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"website": "https://github.com/OCA/product-attribute",
1111
"license": "AGPL-3",
1212
"depends": ["product"],
13-
"data": [],
13+
"data": ["views/res_config_settings_views.xml"],
1414
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import product_category
2+
from . import res_config_settings
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
# Copyright 2025 ForgeFlow
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
33

4-
from odoo import fields, models
4+
from odoo import api, fields, models
55

66

77
class ProductCategory(models.Model):
88
_inherit = "product.category"
99

1010
name = fields.Char(translate=True)
11+
12+
@api.depends("name", "parent_id.complete_name")
13+
def _compute_complete_name(self):
14+
# Compute using main language defined in settings
15+
lang_id = (
16+
self.env["ir.config_parameter"]
17+
.sudo()
18+
.get_param("product_category_name_translatable.complete_name_lang_id")
19+
)
20+
if lang_id:
21+
lang = self.env["res.lang"].browse(int(lang_id))
22+
if lang.exists():
23+
self = self.with_context(lang=lang.code)
24+
return super()._compute_complete_name()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2025 ForgeFlow
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResConfigSettings(models.TransientModel):
8+
_inherit = "res.config.settings"
9+
10+
def _active_languages(self):
11+
return self.env["res.lang"].search([]).ids
12+
13+
def _default_language(self):
14+
lang_code = self.env["ir.default"]._get("res.partner", "lang")
15+
def_lang_id = self.env["res.lang"]._get_data(code=lang_code).id
16+
return def_lang_id or self._active_languages()[0]
17+
18+
product_category_complete_name_lang_id = fields.Many2one(
19+
"res.lang",
20+
string="Product Category Complete Name Language",
21+
default=lambda self: self._default_language(),
22+
required=True,
23+
config_parameter="product_category_name_translatable.complete_name_lang_id",
24+
)
25+
26+
def set_values(self):
27+
old_lang = self.default_get(["product_category_complete_name_lang_id"])[
28+
"product_category_complete_name_lang_id"
29+
]
30+
res = super().set_values()
31+
if self.product_category_complete_name_lang_id != old_lang:
32+
# Recompute complete names
33+
self.env["product.category"].sudo().search([])._compute_complete_name()
34+
return res
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
This module allows you to translate product category names.
2+
3+
The feature of translating the product category name was removed from Odoo core due to limitations on the complete name compute when the name is translatable: https://github.com/odoo/odoo/pull/36717.
4+
5+
To solve it, a setting is available to choose the language you want to use for
6+
displaying the complete name of product categories in the system.

product_category_name_translatable/static/description/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ <h1 class="title">Product Category Name Translatable</h1>
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-attribute/tree/18.0/product_category_name_translatable"><img alt="OCA/product-attribute" src="https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-attribute-18-0/product-attribute-18-0-product_category_name_translatable"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module allows you to translate product category names.</p>
374+
<p>The feature of translating the product category name was removed from
375+
Odoo core due to limitations on the complete name compute when the name
376+
is translatable: <a class="reference external" href="https://github.com/odoo/odoo/pull/36717">https://github.com/odoo/odoo/pull/36717</a>.</p>
377+
<p>To solve it, a setting is available to choose the language you want to
378+
use for displaying the complete name of product categories in the
379+
system.</p>
374380
<p><strong>Table of contents</strong></p>
375381
<div class="contents local topic" id="contents">
376382
<ul class="simple">

product_category_name_translatable/tests/test_product_category_name_translatable.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class TestProductCategoryNameTranslatable(BaseCommon):
99
@classmethod
1010
def setUpClass(cls):
1111
super().setUpClass()
12-
categ_obj = cls.env["product.category"]
13-
cls.parent_categ = categ_obj.create({"name": "Test Category"})
14-
lang_es = cls.env.ref("base.lang_es")
15-
if not lang_es.active:
16-
lang_es.toggle_active()
12+
cls.categ_obj = cls.env["product.category"]
13+
cls.parent_categ = cls.categ_obj.create({"name": "Test Category"})
14+
cls.lang_es = cls.env.ref("base.lang_es")
15+
if not cls.lang_es.active:
16+
cls.lang_es.toggle_active()
1717

1818
def test_product_category_name_translatable(self):
1919
# Update translated name
@@ -24,3 +24,24 @@ def test_product_category_name_translatable(self):
2424
self.parent_categ.with_context(lang="es_ES").name, "Categoria de Prueba"
2525
)
2626
self.assertEqual(self.parent_categ.name, "Test Category")
27+
28+
def test_product_category_name_translatable_complete_name(self):
29+
# Create child category
30+
categ = self.categ_obj.create(
31+
{"name": "Child Category", "parent_id": self.parent_categ.id}
32+
)
33+
# Set translations
34+
self.parent_categ.with_context(lang="es_ES").write(
35+
{"name": "Categoria de Prueba"}
36+
)
37+
categ.with_context(lang="es_ES").write({"name": "Categoria Hija"})
38+
# Check complete name
39+
self.assertEqual(self.categ.complete_name, "Test Category / Child Category")
40+
# Update language in settings and check complete name
41+
self.env["ir.config_parameter"].set_param(
42+
"product_category_name_translatable.complete_name_lang_id", self.lang_es.id
43+
)
44+
(self.categ | self.parent_categ)._compute_complete_name()
45+
self.assertEqual(
46+
self.categ.complete_name, "Categoria de Prueba / Categoria Hija"
47+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="res_config_settings_view_form" model="ir.ui.view">
4+
<field
5+
name="name"
6+
>res.config.settings.form - product_category_name_translatable</field>
7+
<field name="model">res.config.settings</field>
8+
<field name="inherit_id" ref="product.res_config_settings_view_form" />
9+
<field name="arch" type="xml">
10+
<xpath expr="//block[@id='product_general_settings']" position="after">
11+
<block
12+
title="Product Category Translations"
13+
id="product_category_name_translatable_general_settings"
14+
>
15+
<setting
16+
id="product_category_complete_name_lang"
17+
string="Product Category Complete Name Language"
18+
help="Language to use for displaying the complete name of product categories"
19+
>
20+
<field name="product_category_complete_name_lang_id" />
21+
</setting>
22+
</block>
23+
</xpath>
24+
</field>
25+
</record>
26+
</odoo>

0 commit comments

Comments
 (0)