diff --git a/l10n_it_account/__init__.py b/l10n_it_account/__init__.py index d3972593f3e9..94b5b5f94e6e 100644 --- a/l10n_it_account/__init__.py +++ b/l10n_it_account/__init__.py @@ -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 diff --git a/l10n_it_account/models/__init__.py b/l10n_it_account/models/__init__.py index da692602393b..a3f1940195e4 100644 --- a/l10n_it_account/models/__init__.py +++ b/l10n_it_account/models/__init__.py @@ -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 diff --git a/l10n_it_account/models/ir_ui_menu.py b/l10n_it_account/models/ir_ui_menu.py new file mode 100644 index 000000000000..4a82604bd205 --- /dev/null +++ b/l10n_it_account/models/ir_ui_menu.py @@ -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"]) diff --git a/l10n_it_account/models/res_lang.py b/l10n_it_account/models/res_lang.py new file mode 100644 index 000000000000..bb31a58b537a --- /dev/null +++ b/l10n_it_account/models/res_lang.py @@ -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 diff --git a/l10n_it_account/views/account_menuitem.xml b/l10n_it_account/views/account_menuitem.xml index ebbe83a870b6..4b98a4a3d4af 100644 --- a/l10n_it_account/views/account_menuitem.xml +++ b/l10n_it_account/views/account_menuitem.xml @@ -3,12 +3,13 @@ Copyright 2022 Alex Comba - Agile Business Group License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> + Accounting -