Skip to content

Commit

Permalink
[IMP] l10n_it_ricevute_bancarie: Move menu when account_accountant is…
Browse files Browse the repository at this point in the history
… installed or uninstalled
  • Loading branch information
SimoRubi committed Jan 28, 2022
1 parent ebdaaa2 commit 1b803f7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
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
46 changes: 46 additions & 0 deletions l10n_it_ricevute_bancarie/tests/test_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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."""
sibling_menu = self.menu_model.search(
[
("parent_id", "=", self.root_riba_menu.parent_id.id),
],
limit=1,
)
# pre-condition: menus have same parent
self.assertEqual(self.root_riba_menu.parent_id, sibling_menu.parent_id)

# Changing sibling's parent changes also RiBa menu's parent
sibling_menu.parent_id = self.new_parent
self.assertEqual(self.root_riba_menu.parent_id, sibling_menu.parent_id)

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)

# Changing the menu's parent does not change RiBa menu's parent,
# and it remains unchanged
not_sibling_menu.parent_id = self.new_parent
self.assertNotEqual(root_riba_parent_menu, not_sibling_menu.parent_id)
self.assertEqual(self.root_riba_menu.parent_id, root_riba_parent_menu)

0 comments on commit 1b803f7

Please sign in to comment.