-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
4 changed files
with
59 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 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() | ||
|
||
lang_code = self.first_lang_id.code | ||
|
||
if lang_code == "it_IT": | ||
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
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) | ||
|
||
lang = self.env["res.lang"].search([("code", "=", "it_IT")], limit=1) | ||
|
||
if lang and self == self.env.ref("account.menu_finance"): | ||
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