Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] accounting menu not translatable #4298

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions l10n_it_account/__init__.py
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()

Check warning on line 15 in l10n_it_account/__init__.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/__init__.py#L15

Added line #L15 was not covered by tests
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 res_lang
35 changes: 35 additions & 0 deletions l10n_it_account/models/res_lang.py
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()

Check warning on line 11 in l10n_it_account/models/res_lang.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L11

Added line #L11 was not covered by tests

if "it_IT" in [lang.code for lang in self.filtered(lambda L: L.active)]:
self.update_menu_finance_it_translation()

Check warning on line 14 in l10n_it_account/models/res_lang.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L14

Added line #L14 was not covered by tests

return res

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

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L16

Added line #L16 was not covered by tests

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(

Check warning on line 25 in l10n_it_account/models/res_lang.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L25

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

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

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L28

Added line #L28 was not covered by tests

field_name = menu_finance._fields["name"]
translations = field_name._get_stored_translations(menu_finance)

Check warning on line 31 in l10n_it_account/models/res_lang.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L30-L31

Added lines #L30 - L31 were not covered by tests

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

Check warning on line 35 in l10n_it_account/models/res_lang.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_account/models/res_lang.py#L33-L35

Added lines #L33 - L35 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.modified(["name"])

Questo serviva quando self era un menu, giusto? Se è così ora si dovrebbe poter rimuovere.

3 changes: 2 additions & 1 deletion l10n_it_account/views/account_menuitem.xml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le modifiche a questo file si possono rimuovere? Sono solo di formattazione e non servono allo scopo del commit.
Se le vuoi mantenere, sarebbero da spostare in un commit di refactoring.

Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
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
18 changes: 18 additions & 0 deletions l10n_it_account/wizards/base_language_install.py
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()

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 = self.env["res.lang"]

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 "it_IT" in self.lang_ids.mapped("code"):
lang.update_menu_finance_it_translation()

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

return res

Check warning on line 18 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#L18

Added line #L18 was not covered by tests
Loading