[FIX] website_event(_track): correctly delete unwanted website event menus
Previously to commit https://github.com/odoo/odoo/commit/531d641375f5cee7d3a5e629f6b1eaceee8b2739 website menus checkboxes change did remove all menu entries. They were then created again depending on checked entries. That commit changed that behavior to try to create only missing menu entries and remove only extra entries. However the extra entries removal was not correctly done. This commit now checks existing menu entries and remove menu entries that should not exist depending on checked options. Only standard menu entries are removed aka menu entries generated by the event module. This means custom menu entries added for the event should be kept to avoid loosing customization.
This commit is contained in:
@@ -57,7 +57,14 @@ class Event(models.Model):
|
||||
if self.event_type_id:
|
||||
self.website_menu = self.event_type_id.website_menu
|
||||
|
||||
def _get_standard_menu_entries_names(self):
|
||||
""" Method returning menu entries possibly generated by event modules.
|
||||
It is used to distinguish module-generated pages from custom pages. """
|
||||
return [_('Introduction'), _('Location'), _('Register')]
|
||||
|
||||
def _get_menu_entries(self):
|
||||
""" Method returning menu entries to display on the website view of the
|
||||
event, possibly depending on some options in inheriting modules. """
|
||||
self.ensure_one()
|
||||
return [
|
||||
(_('Introduction'), False, 'website_event.template_intro'),
|
||||
@@ -75,9 +82,17 @@ class Event(models.Model):
|
||||
root_menu = self.env['website.menu'].create({'name': event.name})
|
||||
event.menu_id = root_menu
|
||||
|
||||
existing_page_names = event.menu_id.child_id.mapped('name')
|
||||
required_page_names = [entry[0] for entry in self._get_menu_entries()]
|
||||
standard_page_names = self._get_standard_menu_entries_names()
|
||||
|
||||
# remove entries that should not exist anymore
|
||||
submenu_to_delete = event.menu_id.child_id.filtered(lambda menu: menu.name not in required_page_names and menu.name in standard_page_names)
|
||||
submenu_to_delete.unlink()
|
||||
|
||||
# create missing entries
|
||||
for sequence, (name, url, xml_id) in enumerate(self._get_menu_entries()):
|
||||
existing_pages = event.menu_id.child_id.mapped('name')
|
||||
if name not in existing_pages:
|
||||
if name not in existing_page_names:
|
||||
if not url:
|
||||
newpath = self.env['website'].new_page(name + ' ' + self.name, xml_id, ispage=False)
|
||||
url = "/event/" + slug(self) + "/page/" + newpath
|
||||
|
||||
@@ -80,6 +80,11 @@ class Event(models.Model):
|
||||
self.website_track = False
|
||||
self.website_track_proposal = False
|
||||
|
||||
def _get_standard_menu_entries_names(self):
|
||||
res = super(Event, self)._get_standard_menu_entries_names()
|
||||
res += [_('Talks'), _('Agenda'), _('Talk Proposals')]
|
||||
return res
|
||||
|
||||
def _get_menu_entries(self):
|
||||
self.ensure_one()
|
||||
res = super(Event, self)._get_menu_entries()
|
||||
|
||||
Reference in New Issue
Block a user