In website_event some event-specific frontend menus are not linked to ``website.event.menu`` like track or exhibitor sub-modules menus. This comes from initial implementation of ``website.event.menu`` that was available only for ``website_event_track``. Using ``website.event.menu`` eases menu management as it allows to have an object making a link between the event and the website menu. Notably when checking / unchecking in backend submenus it eases management. It also eases management when people manually edit menus from frontend as otherwise we have to manually manage ``ir.ui.view`` based on some naming manipulation. Task ID-2577079 See odoo/odoo#72411
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
|
|
|
|
class WebsiteMenu(models.Model):
|
|
_inherit = "website.menu"
|
|
|
|
def unlink(self):
|
|
""" Override to synchronize event configuration fields with menu deletion. """
|
|
event_updates = {}
|
|
website_event_menus = self.env['website.event.menu'].search([('menu_id', 'in', self.ids)])
|
|
for event_menu in website_event_menus:
|
|
to_update = event_updates.setdefault(event_menu.event_id, list())
|
|
for menu_type, fname in event_menu.event_id._get_menu_type_field_matching().items():
|
|
if event_menu.menu_type == menu_type:
|
|
to_update.append(fname)
|
|
|
|
# manually remove website_event_menus to call their ``unlink`` method. Otherwise
|
|
# super unlinks at db level and skip model-specific behavior.
|
|
website_event_menus.unlink()
|
|
res = super(WebsiteMenu, self).unlink()
|
|
|
|
# update events
|
|
for event, to_update in event_updates.items():
|
|
if to_update:
|
|
event.write(dict((fname, False) for fname in to_update))
|
|
|
|
return res
|