-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] l10n_it_account: accounting menu not translatable
- Loading branch information
Showing
7 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |