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

Spostare menu RiBa in modo da renderlo visibile anche nella versione Enterprise #2623

Merged
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
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import account
from . import account_config
from . import bank_statement
from . import ir_ui_menu
from . import partner
from . import riba
from . import riba_config
26 changes: 26 additions & 0 deletions l10n_it_ricevute_bancarie/models/ir_ui_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2022 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


class IrUiMenu(models.Model):
_inherit = "ir.ui.menu"

def write(self, vals):
old_parent = self.parent_id
new_parent_id = vals.get("parent_id")

res = super().write(vals)

if new_parent_id:
# Move the RiBa menu if any of
# its siblings (menu having same parent before write)
# is moved (parent changes).
# This happens when account_accountant (enterprise)
# is installed or uninstalled.
root_riba_menu = self.env.ref("l10n_it_ricevute_bancarie.menu_riba")
parent_riba_menu = root_riba_menu.parent_id
if old_parent == parent_riba_menu and new_parent_id != old_parent.id:
root_riba_menu.parent_id = new_parent_id
return res
1 change: 1 addition & 0 deletions l10n_it_ricevute_bancarie/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_menu
from . import test_riba
from . import riba_common
50 changes: 50 additions & 0 deletions l10n_it_ricevute_bancarie/tests/test_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2022 Simone Rubino - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests import common


class TestRiBaCommon(common.TransactionCase):
def setUp(self):
super().setUp()
self.menu_model = self.env["ir.ui.menu"]
self.root_riba_menu = self.browse_ref("l10n_it_ricevute_bancarie.menu_riba")
self.new_parent = self.browse_ref("base.menu_custom")

def test_sibling_moved(self):
"""Check that RiBa menu is moved when a sibling changes parent."""
root_riba_parent_menu = self.root_riba_menu.parent_id
sibling_menu = self.menu_model.search(
[
("parent_id", "=", root_riba_parent_menu.id),
],
limit=1,
)
# pre-condition: menus have same parent
self.assertEqual(root_riba_parent_menu, sibling_menu.parent_id)

# Change sibling's parent
sibling_menu.parent_id = self.new_parent

# Check that RiBa menu's parent has changed according to its sibling
self.assertEqual(self.root_riba_menu.parent_id, sibling_menu.parent_id)
self.assertNotEqual(self.root_riba_menu.parent_id, root_riba_parent_menu)

def test_not_sibling_not_moved(self):
"""Check that RiBa menu is not moved when a menu
that is not a sibling changes parent."""
root_riba_parent_menu = self.root_riba_menu.parent_id
not_sibling_menu = self.menu_model.search(
[
("parent_id", "!=", root_riba_parent_menu.id),
],
limit=1,
)
# pre-condition: menus have different parent
self.assertNotEqual(root_riba_parent_menu, not_sibling_menu.parent_id)

# Change not-sibling menu's parent
not_sibling_menu.parent_id = self.new_parent

# Check RiBa menu's parent is not changed
self.assertEqual(self.root_riba_menu.parent_id, root_riba_parent_menu)