[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
This commit is contained in:
Romain Derie
2018-05-09 11:02:16 +02:00
parent 020906659e
commit 665fcb62cf
2 changed files with 3 additions and 2 deletions
+2 -1
View File
@@ -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)
+1 -1
View File
@@ -74,7 +74,7 @@
<span t-field="submenu.name"/>
</a>
</li>
<li t-if="submenu.is_visible and submenu.child_id.filtered(lambda menu: menu.is_visible)" t-attf-class="dropdown #{
<li t-if="submenu.child_id.filtered(lambda menu: menu.is_visible)" t-attf-class="dropdown #{
(submenu.clean_url() and submenu.clean_url() != '/' and any([request.httprequest.path == child.url for child in submenu.child_id if child.url]) or
(submenu.clean_url() and request.httprequest.path == submenu.clean_url())) and 'active'
}">