-
-
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
6 changed files
with
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# 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 | ||
|
||
|
||
def _l10n_it_account_post_init(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
env["account.account"].set_account_types_negative_sign() | ||
|
||
lang = env["res.lang"] | ||
if lang._lang_get("it_IT"): | ||
lang.update_menu_finance_it_translation() |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from . import account_account | ||
from . import account_group | ||
from . import account_tax | ||
from . import res_lang |
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,35 @@ | ||
# 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)]: | ||
self.update_menu_finance_it_translation() | ||
|
||
return res | ||
|
||
def update_menu_finance_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. | ||
""" | ||
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) | ||
|
||
field_name = menu_finance._fields["name"] | ||
translations = field_name._get_stored_translations(menu_finance) | ||
|
||
translations["it_IT"] = "Contabilità" | ||
self.env.cache.update_raw(menu_finance, 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
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,18 @@ | ||
# 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 = self.env["res.lang"] | ||
|
||
if "it_IT" in self.lang_ids.mapped("code"): | ||
lang.update_menu_finance_it_translation() | ||
|
||
return res |