From 665fcb62cfc0231125fc5d0815668b945e2a8d0d Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 8 May 2018 17:50:52 +0200 Subject: [PATCH] [FIX] website: always show menu if its a container with visible menus Before this commit: 1. If a menu was used as a container (dropdown) and had an unpublished page_id (website.page), we would never show that menu (and so its submenus) even if it has visible submenu. Some users are stuck with this since they: a) create a new page 'A' (unpublished by default) included in menu. b) create a new page 'B' (unpublished by default) included in menu. c) set 'B' as a submenu of 'A' in the menu manager d) decide to publish the website.page linked to menu 'B' Then, since menu 'A' is linked to an unpublished page, the menu 'A' and 'B' are never visible. 2. If a menu is being created with an URL that match a website.page URL, the m2o relation will automatically be set (website.menu.page_id). Still, if the user type the URL without the leading slash, the m2o won't be set. This could be misleading since on the page property in the page manager the URL is being shown without the leading slash even if it is stored in DB. Now: 1. We always show menu container if they contains visible submenu, even if the container menu is linked to an unpublished page 2. The page URL search is more clever and will match URL even if the only difference is the leading slash. This closes #24635 --- addons/website/models/website.py | 3 ++- addons/website/views/website_templates.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 35038877749..eb5483f7915 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -885,9 +885,10 @@ class Menu(models.Model): for menu in data['data']: menu_id = self.browse(menu['id']) # if the url match a website.page, set the m2o relation - page = self.env['website.page'].search([('url', '=', menu['url'])], limit=1) + page = self.env['website.page'].search(['|', ('url', '=', menu['url']), ('url', '=', '/' + menu['url'])], limit=1) if page: menu['page_id'] = page.id + menu['url'] = page.url elif menu_id.page_id: menu_id.page_id.write({'url': menu['url']}) menu_id.write(menu) diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index 16fc3e33444..3573ca8a4df 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -74,7 +74,7 @@ -