Skip to content

Commit

Permalink
[FIX] l10n_it_account: accounting menu not translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
primes2h committed Nov 26, 2024
1 parent aa6627f commit 463f2e4
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions l10n_it_account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from . import wizards
from . import tools
from odoo import api, SUPERUSER_ID

Expand Down
2 changes: 2 additions & 0 deletions l10n_it_account/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
from . import account_account
from . import account_group
from . import account_tax
from . import ir_ui_menu
from . import res_lang
32 changes: 32 additions & 0 deletions l10n_it_account/models/ir_ui_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 Sergio Zanchetta (PNLUG APS - Gruppo Odoo)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class IrUiMenu(models.Model):
_inherit = "ir.ui.menu"

def write(self, vals):
res = super().write(vals)

if self == self.env.ref("account.menu_finance"):
lang = self.env["res.lang"]._lang_get("it_IT")
if lang:
self.update_it_translation()

return res

def update_it_translation(self):
"""In Odoo the inheritance mechanism is not yet implemented for menus.
Changing a menu item name doesn't create a new string to be translated
but overwrites the source string of the original module to which the menu
belongs to. This is a workaround that allows the translated string to be
modified in the same way.
"""
field_name = self._fields["name"]
translations = field_name._get_stored_translations(self)

translations["it_IT"] = "Contabilità"
self.env.cache.update_raw(self, field_name, [translations], dirty=True)
self.modified(["name"])
21 changes: 21 additions & 0 deletions l10n_it_account/models/res_lang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Sergio Zanchetta (PNLUG APS - Gruppo Odoo)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class Lang(models.Model):
_inherit = "res.lang"

def toggle_active(self):
res = super().toggle_active()

if "it_IT" in [lang.code for lang in self.filtered(lambda L: L.active)]:
menu_finance_id = self.env["ir.model.data"]._xmlid_to_res_id(
"account.menu_finance"
)
menu_finance = self.env["ir.ui.menu"].browse(menu_finance_id)

menu_finance.update_it_translation()

return res
3 changes: 2 additions & 1 deletion l10n_it_account/views/account_menuitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
Copyright 2022 Alex Comba - Agile Business Group
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<!-- accounting label -->
<record id="account.menu_finance" model="ir.ui.menu">
<field name="name">Accounting</field>
</record>

<menuitem
<menuitem
id="account_italian_localization"
name="Italian Localization"
sequence="2"
Expand Down
3 changes: 3 additions & 0 deletions l10n_it_account/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import base_language_install
21 changes: 21 additions & 0 deletions l10n_it_account/wizards/base_language_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Sergio Zanchetta (PNLUG APS - Gruppo Odoo)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class BaseLanguageInstall(models.TransientModel):
_inherit = "base.language.install"

def lang_install(self):
res = super().lang_install()

if "it_IT" in self.lang_ids.mapped("code"):
menu_finance_id = self.env["ir.model.data"]._xmlid_to_res_id(
"account.menu_finance"
)
menu_finance = self.env["ir.ui.menu"].browse(menu_finance_id)

menu_finance.update_it_translation()

return res

0 comments on commit 463f2e4

Please sign in to comment.