Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Dj0ulo/91395b3fb11ed332dd7ce78a43e1f49f to your computer and use it in GitHub Desktop.
Save Dj0ulo/91395b3fb11ed332dd7ce78a43e1f49f to your computer and use it in GitHub Desktop.
2072a1c875ff04957296cec83ddd37c746ebf30e..b519215b7afb8ff1cf50c78c05286fe1d7e7f30d
diff --git a/addons/website/models/website_menu.py b/addons/website/models/website_menu.py
index 31cb3346ef01..f4d117724a9f 100644
--- a/addons/website/models/website_menu.py
+++ b/addons/website/models/website_menu.py
@@ -231,6 +231,9 @@ class Menu(models.Model):
menu_url = url_parse(menu_url)
if unslug_url(menu_url.path) == unslug_url(request_url.path):
+ # By default we compare the unslug version of the current URL
+ # with the menu URL but if the menu is linked to a page we don't
+ # consider it active if the paths don't match exactly.
if self.page_id and menu_url.path != request_url.path:
return False
if not (
diff --git a/addons/website/tests/test_menu.py b/addons/website/tests/test_menu.py
index 2a20ecca38d0..b34b1ce3a556 100644
--- a/addons/website/tests/test_menu.py
+++ b/addons/website/tests/test_menu.py
@@ -240,23 +240,14 @@ class TestMenu(common.TransactionCase):
test_full_case(submenu)
# Do the same test with a menu that is linked to a page
- page = self.env['website.page'].create({
- 'name': 'Page with number',
- 'url': '/sub/page-3',
- 'website_id': website_1.id,
- 'type': 'qweb',
- "arch": "<div></div>",
- })
-
- menu = Menu.create({
- 'name': 'Menu with page',
- 'website_id': website_1.id,
- })
- menu.page_id = page.id
+ result = website_1.new_page(
+ name='/sub/page-3',
+ add_menu=True,
+ )
+ menu = Menu.browse(result['menu_id'])
+ page = self.env['website.page'].browse(result['page_id'])
self.assertEqual(menu.url, page.url, "Menu url should be the same than the page url")
- test_full_case(menu.copy())
-
with MockRequest(self.env, website=website_1), \
patch('odoo.addons.website.models.website_menu.url_parse', new=url_parse_mock):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment