-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] l10n_it_ricevute_bancarie: Move menu when account_accountant is…
… installed or uninstalled
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |