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 23, 2024
1 parent aa6627f commit 1a7078f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
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
1 change: 1 addition & 0 deletions l10n_it_account/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from . import account_account
from . import account_group
from . import account_tax
from . import ir_ui_menu
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()

Check warning on line 16 in l10n_it_account/models/ir_ui_menu.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/ir_ui_menu.py#L16

Added line #L16 was not covered by tests

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)

Check warning on line 28 in l10n_it_account/models/ir_ui_menu.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/ir_ui_menu.py#L27-L28

Added lines #L27 - L28 were not covered by tests

translations["it_IT"] = "Contabilità"
self.env.cache.update_raw(self, field_name, [translations], dirty=True)
self.modified(["name"])

Check warning on line 32 in l10n_it_account/models/ir_ui_menu.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/ir_ui_menu.py#L30-L32

Added lines #L30 - L32 were not covered by tests
4 changes: 2 additions & 2 deletions l10n_it_account/views/account_menuitem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
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
23 changes: 23 additions & 0 deletions l10n_it_account/wizards/base_language_install.py
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()

Check warning on line 11 in l10n_it_account/wizards/base_language_install.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/wizards/base_language_install.py#L11

Added line #L11 was not covered by tests

lang_code = self.first_lang_id.code

Check warning on line 13 in l10n_it_account/wizards/base_language_install.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/wizards/base_language_install.py#L13

Added line #L13 was not covered by tests

if lang_code == "it_IT":
menu_finance_id = self.env["ir.model.data"]._xmlid_to_res_id(

Check warning on line 16 in l10n_it_account/wizards/base_language_install.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/wizards/base_language_install.py#L16

Added line #L16 was not covered by tests
"account.menu_finance"
)
menu_finance = self.env["ir.ui.menu"].browse(menu_finance_id)

Check warning on line 19 in l10n_it_account/wizards/base_language_install.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/wizards/base_language_install.py#L19

Added line #L19 was not covered by tests

menu_finance.update_it_translation()

Check warning on line 21 in l10n_it_account/wizards/base_language_install.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/wizards/base_language_install.py#L21

Added line #L21 was not covered by tests

return res

Check warning on line 23 in l10n_it_account/wizards/base_language_install.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/wizards/base_language_install.py#L23

Added line #L23 was not covered by tests

0 comments on commit 1a7078f

Please sign in to comment.