[MOV] website_event(_track): move website event menu into website event

PURPOSE

Clean organization and models linked to Event Online feature introduced in
semi stable saas-13.3 at odoo/odoo@981f95bbf4 and odoo/enterprise@14722028ae

Also clean website event menu not being available in website event but only
in website event track, which implies some extra-code to manage it.

In short: merge website_event_online in website_event, website_event_track
_(online/session) in website_event_track.

RATIONALE

_online modules have been added to extend content of website_event and
website_event_track without having any impact on those module. First step
of cleaning is to move this content directly in base module.

track_session module is mainly a rewrite of track module. Second step of
cleaning is to move its content directly in website_event_track.

SPECIFICATIONS

Move website event menu model directly into website event. Website event menu
model has been introduced to help dealing with event-specific menus and
website menus. This is some kind of glue to synchronize both of them as people
could either

  * update an event (website_menu, website_track) that updates website menus
    availability;
  * update menus through website that should update event field value and menu
    computation;

Having a model introduced in website event track forces to have override and
code split across website_event, website_event_track, and now also in both
_online version of those two as menu management was improved.

In this commit we simplify all this code by moving most of menu management
code in website_event, leaving only business-specific code (fields and their
menus) to sub modules.

SPECIFICATIONS: WEBSITE EVENT MENU

Make type required as we don't support entries without type. Indeed this model
is used to automate menus generation / destruction, and not for hand-made
menus. We therefore set type as required and add a cascade ondelete for
selection.

SPECIFCIATIONS: COMMUNITY MENU

Doing this change allows to define community menu in website_event and re-use
it in website_event_meet and website_event_track_quiz, removing some
unnecessary dependencies. This menu is void in website_event, and displays
either meeting rooms (in meet) or quiz points leaderboard (in quiz), or a
mix of both if the two features are installed.

LINKS

Task ID-2319779
COM odoo/odoo#56067
ENT odoo/enterprise#12520
UPG odoo/upgrade#165
This commit is contained in:
Thibault Delavallée
2020-08-21 17:30:13 +00:00
parent 8da7288453
commit 77d7a3cf6a
37 changed files with 208 additions and 266 deletions
+2
View File
@@ -28,6 +28,8 @@
'views/website_templates.xml',
'views/event_event_views.xml',
'views/event_type_views.xml',
'views/website_event_menu_views.xml',
'views/event_menus.xml',
'security/ir.model.access.csv',
'security/event_security.xml',
],
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from . import main
from . import community
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.website_event.controllers.main import WebsiteEventController
from odoo import fields, http, modules, tools
from odoo import http
from odoo.http import request
class WebsiteEventCommunityController(http.Controller):
class EventCommunityController(http.Controller):
@http.route('/event/<model("event.event"):event>/community', type="http", auth="public", website=True)
def community(self, event, lang=None, **kwargs):
+2
View File
@@ -3,3 +3,5 @@
from . import event_event
from . import event_type
from . import website
from . import website_event_menu
from . import website_menu
+85 -14
View File
@@ -36,6 +36,13 @@ class Event(models.Model):
help="Creates menus Introduction, Location and Register on the page "
"of the event on the website.")
menu_id = fields.Many2one('website.menu', 'Event Menu', copy=False)
community_menu = fields.Boolean(
"Community Menu", compute="_compute_community_menu",
readonly=False, store=True,
help="Display community tab on website")
community_menu_ids = fields.One2many(
"website.event.menu", "event_id", string="Event Community Menus",
domain=[("menu_type", "=", "community")])
def _compute_is_participating(self):
# we don't allow public user to see participating label
@@ -47,13 +54,6 @@ class Event(models.Model):
else:
self.is_participating = False
@api.depends('name')
def _compute_website_url(self):
super(Event, self)._compute_website_url()
for event in self:
if event.id: # avoid to perform a slug on a not yet saved record in case of an onchange.
event.website_url = '/event/%s' % slug(event)
@api.depends('event_type_id')
def _compute_website_menu(self):
""" Also ensure a value for website_menu as it is a trigger notably for
@@ -64,6 +64,24 @@ class Event(models.Model):
elif not event.website_menu:
event.website_menu = False
@api.depends("event_type_id", "website_menu", "community_menu")
def _compute_community_menu(self):
""" At type onchange: synchronize. At website_menu update: synchronize. """
for event in self:
if event.event_type_id and event.event_type_id != event._origin.event_type_id:
event.community_menu = event.event_type_id.community_menu
elif event.website_menu and event.website_menu != event._origin.website_menu or not event.community_menu:
event.community_menu = True
elif not event.website_menu:
event.community_menu = False
@api.depends('name')
def _compute_website_url(self):
super(Event, self)._compute_website_url()
for event in self:
if event.id: # avoid to perform a slug on a not yet saved record in case of an onchange.
event.website_url = '/event/%s' % slug(event)
@api.model
def create(self, vals):
res = super(Event, self).create(vals)
@@ -91,7 +109,10 @@ class Event(models.Model):
:return list: list of fields, each of which triggering a menu update
like website_menu, website_track, ... """
return ['website_menu']
return ['website_menu', 'community_menu']
def _get_menu_type_field_matching(self):
return {'community': 'community_menu'}
def _split_menus_state_by_field(self):
""" For each field linked to a menu, get the set of events having this
@@ -135,7 +156,7 @@ class Event(models.Model):
menus_update_by_field[fname] |= menus_state_by_field[fname]['deactivated'].filtered(lambda event: event[fname])
return menus_update_by_field
def _get_menu_entries(self):
def _get_website_menu_entries(self):
""" Method returning menu entries to display on the website view of the
event, possibly depending on some options in inheriting modules.
@@ -143,14 +164,22 @@ class Event(models.Model):
* name: menu item name
* url: if set, url to a route (do not use xml_id in that case);
* xml_id: template linked to the page (do not use url in that case);
* sequence: specific sequence of menu entry to be set on the menu;
* menu_type: type of menu entry (used in inheriting modules to ease
menu management; not used in this module in 13.3 due to technical
limitations);
"""
self.ensure_one()
return [
(_('Introduction'), False, 'website_event.template_intro'),
(_('Location'), False, 'website_event.template_location'),
(_('Register'), '/event/%s/register' % slug(self), False),
(_('Introduction'), False, 'website_event.template_intro', 1, False),
(_('Location'), False, 'website_event.template_location', 50, False),
(_('Register'), '/event/%s/register' % slug(self), False, 100, False),
]
def _get_community_menu_entries(self):
self.ensure_one()
return [(_('Community'), '/event/%s/community' % slug(self), False, 80, 'community')]
def _update_website_menus(self, menus_update_by_field=None):
""" Synchronize event configuration and its menu entries for frontend.
@@ -161,8 +190,44 @@ class Event(models.Model):
elif event.website_menu and not event.menu_id:
root_menu = self.env['website.menu'].sudo().create({'name': event.name, 'website_id': event.website_id.id})
event.menu_id = root_menu
for sequence, (name, url, xml_id) in enumerate(event._get_menu_entries()):
event._create_menu(sequence, name, url, xml_id)
if event.website_menu and (not menus_update_by_field or event in menus_update_by_field.get('website_menu')):
for name, url, xml_id, menu_sequence, menu_type in event._get_website_menu_entries():
event._create_menu(menu_sequence, name, url, xml_id, menu_type=menu_type)
if event.menu_id and (not menus_update_by_field or event in menus_update_by_field.get('community_menu')):
event._update_website_menu_entry('community_menu', 'community_menu_ids', '_get_community_menu_entries')
def _update_website_menu_entry(self, fname_bool, fname_o2m, method_name):
""" Generic method to create menu entries based on a flag on event. This
method is a bit obscure, but is due to preparation of adding new menus
entries and pages for event in a stable version, leading to some constraints
while developing.
:param fname_bool: field name (e.g. website_track)
:param fname_o2m: o2m linking towards website.event.menu matching the
boolean fields (normally an entry ot website.event.menu with type matching
the boolean field name)
:param method_name: method returning menu entries information: url, sequence, ...
"""
self.ensure_one()
new_menu = None
if self[fname_bool] and not self[fname_o2m]:
# menus not found but boolean True: get menus to create
for sequence, menu_data in enumerate(getattr(self, method_name)()):
# some modules have 4 data: name, url, xml_id, menu_type; however we
# plan to support sequence in future modules, so this hackish code is
# necessary to avoid crashing. Not nice, but stable target = meh.
if len(menu_data) == 4:
(name, url, xml_id, menu_type) = menu_data
menu_sequence = sequence
elif len(menu_data) == 5:
(name, url, xml_id, menu_sequence, menu_type) = menu_data
new_menu = self._create_menu(menu_sequence, name, url, xml_id, menu_type=menu_type)
elif not self[fname_bool]:
# will cascade delete to the website.event.menu
self[fname_o2m].mapped('menu_id').sudo().unlink()
return new_menu
def _create_menu(self, sequence, name, url, xml_id, menu_type=False):
""" If url: create a website menu. Menu leads directly to the URL that
@@ -184,6 +249,12 @@ class Event(models.Model):
'sequence': sequence,
'website_id': self.website_id.id,
})
if menu_type:
self.env['website.event.menu'].create({
'menu_id': website_menu.id,
'event_id': self.id,
'menu_type': menu_type,
})
return website_menu
# ------------------------------------------------------------
+10 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import api, fields, models
class EventType(models.Model):
@@ -9,3 +9,12 @@ class EventType(models.Model):
_inherit = ['event.type']
website_menu = fields.Boolean('Display a dedicated menu on Website')
community_menu = fields.Boolean(
"Community Menu", compute="_compute_community_menu",
readonly=False, store=True,
help="Display community tab on website")
@api.depends('website_menu')
def _compute_community_menu(self):
for event_type in self:
event_type.community_menu = event_type.website_menu
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class EventMenu(models.Model):
_name = "website.event.menu"
_description = "Website Event Menu"
menu_id = fields.Many2one('website.menu', string='Menu', ondelete='cascade')
event_id = fields.Many2one('event.event', string='Event', ondelete='cascade')
menu_type = fields.Selection([
('community', 'Community Menu')], string="Menu Type",
ondelete={'community': 'cascade'}, required=True)
@@ -0,0 +1,29 @@
# -*- 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.
This should be cleaned in upcoming versions. """
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)
# call super that resumes the unlink of menus entries (including website event menus)
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
@@ -6,3 +6,5 @@ access_event_event_ticket_public,event.event.ticket.public,event.model_event_eve
access_event_event_ticket_portal,event.event.ticket.portal,event.model_event_event_ticket,base.group_portal,1,0,0,0
access_event_category_public,event.tag.category.public,event.model_event_tag_category,,1,0,0,0
access_event_tag_public,event.tag.public,event.model_event_tag,,1,0,0,0
access_website_event_menu_public,website.event.menu,model_website_event_menu,,1,0,0,0
access_website_event_menu_manager,website.event.menu,model_website_event_menu,event.group_event_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
6 access_event_event_ticket_portal event.event.ticket.portal event.model_event_event_ticket base.group_portal 1 0 0 0
7 access_event_category_public event.tag.category.public event.model_event_tag_category 1 0 0 0
8 access_event_tag_public event.tag.public event.model_event_tag 1 0 0 0
9 access_website_event_menu_public website.event.menu model_website_event_menu 1 0 0 0
10 access_website_event_menu_manager website.event.menu model_website_event_menu event.group_event_manager 1 1 1 1
@@ -17,6 +17,7 @@ class TestEventWebsite(TestWebsiteEventCommon):
'date_begin': fields.Datetime.to_string(datetime.today() + timedelta(days=1)),
'date_end': fields.Datetime.to_string(datetime.today() + timedelta(days=15)),
'website_menu': True,
'community_menu': False,
})
self._assert_website_menus(event)
@@ -27,6 +28,7 @@ class TestEventWebsite(TestWebsiteEventCommon):
'date_begin': fields.Datetime.to_string(datetime.today() + timedelta(days=1)),
'date_end': fields.Datetime.to_string(datetime.today() + timedelta(days=15)),
'website_menu': True,
'community_menu': False,
})
self.assertTrue(event.website_menu)
self._assert_website_menus(event)
@@ -19,6 +19,14 @@
type="object"
string="Preview Badges"/>
</xpath>
<xpath expr="//div[hasclass('oe_title')]" position="after">
<div name="event_menu_configuration" groups="base.group_no_one">
<label for="website_menu" string="Website Submenu"/>
<field name="website_menu"/>
<label for="community_menu" string="Community"/>
<field name="community_menu"/>
</div>
</xpath>
</field>
</record>
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<odoo><data>
<menuitem id="menu_website_event_menu"
name="Website Menus"
action="website_event_menu_action"
parent="event.menu_event_configuration"
groups="base.group_no_one"
sequence="99"/>
</data></odoo>
@@ -19,6 +19,9 @@
website: registrations, schedule, map, ...
</div>
</div>
<div id="community-menu" class="row mt16" groups="base.group_no_one" attrs="{'invisible': [('website_menu', '=', False)]}">
<label class="col-lg-4" for="community_menu"/> <field name="community_menu"/>
</div>
</div>
</div>
</div>
@@ -8,13 +8,13 @@ from werkzeug.utils import redirect
from odoo import exceptions, http
from odoo.http import request
from odoo.addons.http_routing.models.ir_http import slug
from odoo.addons.website_event_track_online.controllers.community import WebsiteEventCommunityController
from odoo.addons.website_event.controllers.community import EventCommunityController
from odoo.osv import expression
_logger = logging.getLogger(__name__)
class WebsiteEventMeetController(WebsiteEventCommunityController):
class WebsiteEventMeetController(EventCommunityController):
def _get_event_rooms_base_domain(self, event):
search_domain_base = [('event_id', '=', event.id), ('is_published', '=', True)]
@@ -7,4 +7,6 @@ from odoo import fields, models
class EventMenu(models.Model):
_inherit = "website.event.menu"
menu_type = fields.Selection(selection_add=[("meeting_room", "Event Meeting Room Menus")])
menu_type = fields.Selection(
selection_add=[("meeting_room", "Event Meeting Room Menus")],
ondelete={'meeting_room': 'cascade'})
@@ -4,7 +4,7 @@
<record id="event_event_view_form" model="ir.ui.view">
<field name="name">event.event.view.form.inherit.meet</field>
<field name="model">event.event</field>
<field name="inherit_id" ref="website_event_track_online.event_event_view_form"/>
<field name="inherit_id" ref="website_event.event_event_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='is_published']" position="before">
<button class="oe_stat_button" context="{'default_event_id': active_id, 'search_default_event_id': active_id}" icon="fa-comments-o" name="%(event_meeting_room_action)d" type="action">
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.addons.website_event_track_online.controllers.community import WebsiteEventCommunityController
from odoo.http import request
from werkzeug.exceptions import Forbidden
from odoo import http
from odoo.addons.website_event.controllers.community import EventCommunityController
from odoo.http import request
class WebsiteEventTrackQuizMeetController(WebsiteEventCommunityController):
class WebsiteEventTrackQuizMeetController(EventCommunityController):
@http.route(['/event/<model("event.event"):event>/community'], type='http', auth="public", website=True, sitemap=False)
def community(self, event, page=1, lang=None, **kwargs):
@@ -93,40 +93,3 @@ class Event(models.Model):
for event in self:
event.is_participating = event in events
# ------------------------------------------------------------
# WEBSITE MENU MANAGEMENT
# ------------------------------------------------------------
def _get_menu_entries(self):
""" Deprecate old method as a new one with more information is used
starting with website_event_online module. """
return []
def _get_menu_entries_online(self):
""" Method returning menu entries to display on the website view of the
event, possibly depending on some options in inheriting modules.
Each menu entry is a tuple containing :
* name: menu item name
* url: if set, url to a route (do not use xml_id in that case);
* xml_id: template linked to the page (do not use url in that case);
* sequence: specific sequence of menu entry to be set on the menu;
* menu_type: type of menu entry (used in inheriting modules to ease
menu management; not used in this module in 13.3 due to technical
limitations);
"""
self.ensure_one()
return [
(_('Introduction'), False, 'website_event.template_intro', 1, False),
(_('Location'), False, 'website_event.template_location', 50, False),
(_('Register'), '/event/%s/register' % slug(self), False, 100, False),
]
def _update_website_menus(self, menus_update_by_field=None):
""" Synchronize event configuration and its menu entries for frontend. """
super(Event, self)._update_website_menus(menus_update_by_field=menus_update_by_field)
for event in self:
if event.website_menu and (not menus_update_by_field or event in menus_update_by_field.get('website_menu')):
for name, url, xml_id, menu_sequence, menu_type in event._get_menu_entries_online():
event._create_menu(menu_sequence, name, url, xml_id, menu_type=menu_type)
@@ -6,10 +6,8 @@
<field name="model">event.event</field>
<field name="inherit_id" ref="event.view_event_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('oe_title')]" position="after">
<xpath expr="//[field@name='website_menu']" position="after">
<div name="event_menu_configuration" groups="base.group_no_one">
<label for="website_menu" string="Website Submenu"/>
<field name="website_menu"/>
<label for="menu_register_cta" string="Register Button"/>
<field name="menu_register_cta"/>
</div>
@@ -27,7 +27,6 @@
'views/event_sponsor_views.xml',
'views/event_event_views.xml',
'views/event_type_views.xml',
'views/website_event_menu_views.xml',
'views/event_menus.xml',
],
'demo': [
@@ -85,53 +85,10 @@ class Event(models.Model):
if (not menus_update_by_field) or (event in menus_update_by_field.get('website_track_proposal')):
event._update_website_menu_entry('website_track_proposal', 'track_proposal_menu_ids', '_get_track_proposal_menu_entries')
def _update_website_menu_entry(self, fname_bool, fname_o2m, method_name):
""" Generic method to create menu entries based on a flag on event. This
method is a bit obscure, but is due to preparation of adding new menus
entries and pages for event in a stable version, leading to some constraints
while developing.
:param fname_bool: field name (e.g. website_track)
:param fname_o2m: o2m linking towards website.event.menu matching the
boolean fields (normally an entry ot website.event.menu with type matching
the boolean field name)
:param method_name: method returning menu entries information: url, sequence, ...
"""
self.ensure_one()
new_menu = None
if self[fname_bool] and not self[fname_o2m]:
# menus not found but boolean True: get menus to create
for sequence, menu_data in enumerate(getattr(self, method_name)()):
# some modules have 4 data: name, url, xml_id, menu_type; however we
# plan to support sequence in future modules, so this hackish code is
# necessary to avoid crashing. Not nice, but stable target = meh.
if len(menu_data) == 4:
(name, url, xml_id, menu_type) = menu_data
menu_sequence = sequence
elif len(menu_data) == 5:
(name, url, xml_id, menu_sequence, menu_type) = menu_data
new_menu = self._create_menu(menu_sequence, name, url, xml_id, menu_type=menu_type)
elif not self[fname_bool]:
# will cascade delete to the website.event.menu
self[fname_o2m].mapped('menu_id').sudo().unlink()
return new_menu
def _create_menu(self, sequence, name, url, xml_id, menu_type=False):
""" Override menu creation from website_event to link a website.event.menu
to the newly create menu (either page and url). """
website_menu = super(Event, self)._create_menu(sequence, name, url, xml_id, menu_type=menu_type)
if menu_type:
self.env['website.event.menu'].create({
'menu_id': website_menu.id,
'event_id': self.id,
'menu_type': menu_type,
})
return website_menu
def _get_menu_type_field_matching(self):
return {'track_proposal': 'website_track_proposal'}
res = super(Event, self)._get_menu_type_field_matching()
res['track_proposal'] = 'website_track_proposal'
return res
def _get_track_menu_entries(self):
""" Method returning menu entries to display on the website view of the
@@ -146,10 +103,11 @@ class Event(models.Model):
"""
self.ensure_one()
return [
(_('Talks'), '/event/%s/track' % slug(self), False, 'track'),
(_('Agenda'), '/event/%s/agenda' % slug(self), False, False)]
(_('Talks'), '/event/%s/track' % slug(self), False, 10, 'track'),
(_('Agenda'), '/event/%s/agenda' % slug(self), False, 70, False)
]
def _get_track_proposal_menu_entries(self):
""" See website_event_track._get_track_menu_entries() """
self.ensure_one()
return [(_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False, 'track_proposal')]
return [(_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False, 15, 'track_proposal')]
@@ -5,12 +5,8 @@ from odoo import fields, models
class EventMenu(models.Model):
_name = "website.event.menu"
_description = "Website Event Menu"
_inherit = "website.event.menu"
menu_id = fields.Many2one('website.menu', string='Menu', ondelete='cascade')
event_id = fields.Many2one('event.event', string='Event', ondelete='cascade')
menu_type = fields.Selection([
('track', 'Event Tracks Menus'),
('track_proposal', 'Event Proposals Menus'),
])
menu_type = fields.Selection(
selection_add=[('track', 'Event Tracks Menus'), ('track_proposal', 'Event Proposals Menus')],
ondelete={'track': 'cascade', 'track_proposal': 'cascade'})
@@ -18,9 +18,6 @@ class WebsiteMenu(models.Model):
# agenda page that has also menu_type='track'
if event_menu.menu_type == 'track' and '/track' in event_menu.menu_id.url:
to_update.append('website_track')
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)
# call super that resumes the unlink of menus entries (including website event menus)
res = super(WebsiteMenu, self).unlink()
@@ -12,5 +12,3 @@ access_event_track_sponsor_manager,event.track.sponsor.type.public,model_event_s
access_event_track_sponsor_public,event.track.sponsor.public,model_event_sponsor,,1,0,0,0
access_event_track_stage_all,event.track.stage.all,model_event_track_stage,,1,0,0,0
access_event_track_stage_event_manager,event.track.stage.event.manager,model_event_track_stage,event.group_event_manager,1,1,1,1
access_website_event_menu_public,website.event.menu,model_website_event_menu,,1,0,0,0
access_website_event_menu_manager,website.event.menu,model_website_event_menu,event.group_event_manager,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
12 access_event_track_sponsor_public event.track.sponsor.public model_event_sponsor 1 0 0 0
13 access_event_track_stage_all event.track.stage.all model_event_track_stage 1 0 0 0
14 access_event_track_stage_event_manager event.track.stage.event.manager model_event_track_stage event.group_event_manager 1 1 1 1
access_website_event_menu_public website.event.menu model_website_event_menu 1 0 0 0
access_website_event_menu_manager website.event.menu model_website_event_menu event.group_event_manager 1 1 1 1
@@ -11,7 +11,7 @@ from odoo.tests.common import users
class TestEventWebsiteTrack(TestWebsiteEventCommon):
def _get_menus(self):
return super(TestEventWebsiteTrack, self)._get_menus() | set(['Talks', 'Agenda', 'Talk Proposals'])
return super(TestEventWebsiteTrack, self)._get_menus() | set(['Community', 'Talks', 'Agenda', 'Talk Proposals'])
@users('user_eventmanager')
def test_create_menu(self):
@@ -24,6 +24,7 @@ class TestEventWebsiteTrack(TestWebsiteEventCommon):
'name': 'test_reg',
})],
'website_menu': True,
'community_menu': True,
'website_track': True,
'website_track_proposal': True,
})
@@ -37,6 +38,7 @@ class TestEventWebsiteTrack(TestWebsiteEventCommon):
'date_begin': fields.Datetime.to_string(datetime.today() + timedelta(days=1)),
'date_end': fields.Datetime.to_string(datetime.today() + timedelta(days=15)),
'website_menu': True,
'community_menu': True,
'website_track': True,
'website_track_proposal': True,
})
@@ -46,7 +48,7 @@ class TestEventWebsiteTrack(TestWebsiteEventCommon):
introduction_menu = event.menu_id.child_id.filtered(lambda menu: menu.name == 'Introduction')
introduction_menu.unlink()
self._assert_website_menus(event, set(['Location', 'Register', 'Talks', 'Agenda', 'Talk Proposals']))
self._assert_website_menus(event, set(['Location', 'Register', 'Community', 'Talks', 'Agenda', 'Talk Proposals']))
menus = event.menu_id.child_id.filtered(lambda menu: menu.name in ['Agenda', 'Talk Proposals'])
menus.unlink()
@@ -58,12 +60,12 @@ class TestEventWebsiteTrack(TestWebsiteEventCommon):
self.assertFalse(event.website_track)
self.assertFalse(event.website_track_proposal)
self._assert_website_menus(event, set(['Location', 'Register']))
self._assert_website_menus(event, set(['Location', 'Register', 'Community']))
event.write({'website_track_proposal': True})
self.assertTrue(event.website_track)
self.assertTrue(event.website_track_proposal)
self._assert_website_menus(event, set(['Location', 'Register', 'Talks', 'Agenda', 'Talk Proposals']))
self._assert_website_menus(event, set(['Location', 'Register', 'Community', 'Talks', 'Agenda', 'Talk Proposals']))
@users('user_eventmanager')
def test_write_menu(self):
@@ -71,6 +73,7 @@ class TestEventWebsiteTrack(TestWebsiteEventCommon):
self.assertFalse(event.menu_id)
event.write({
'website_menu': True,
'community_menu': True,
'website_track': True,
'website_track_proposal': True,
})
@@ -39,11 +39,4 @@
groups="base.group_no_one"
sequence="40"/>
<menuitem id="menu_website_event_menu"
name="Website Menus"
action="website_event_menu_action"
parent="event.menu_event_configuration"
groups="base.group_no_one"
sequence="99"/>
</data></odoo>
@@ -7,4 +7,6 @@ from odoo import fields, models
class EventMenu(models.Model):
_inherit = "website.event.menu"
menu_type = fields.Selection(selection_add=[('exhibitor', 'Exhibitors Menus')])
menu_type = fields.Selection(
selection_add=[('exhibitor', 'Exhibitors Menus')],
ondelete={'exhibitor': 'cascade'})
@@ -32,7 +32,6 @@
'views/event_track_views.xml',
'views/event_track_tag_views.xml',
'views/event_track_visitor_views.xml',
'views/event_type_views.xml',
'views/website_visitor_views.xml',
'views/event_menus.xml',
],
@@ -2,4 +2,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import event_track
from . import community
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import event_event
from . import event_sponsor
from . import event_sponsor_type
from . import event_track_visitor
from . import event_track
from . import event_track_stage
from . import event_track_tag
from . import event_type
from . import website
from . import website_event_menu
from . import website_visitor
@@ -1,67 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api, _
from odoo.addons.http_routing.models.ir_http import slug
class EventEvent(models.Model):
_inherit = "event.event"
community_menu = fields.Boolean(
"Community Menu", compute="_compute_community_menu",
readonly=False, store=True,
help="Display community tab on website")
community_menu_ids = fields.One2many(
"website.event.menu", "event_id", string="Event Community Menus",
domain=[("menu_type", "=", "community")])
@api.depends("event_type_id", "website_menu", "community_menu")
def _compute_community_menu(self):
""" At type onchange: synchronize. At website_menu update: synchronize. """
for event in self:
if event.event_type_id and event.event_type_id != event._origin.event_type_id:
event.community_menu = event.event_type_id.community_menu
elif event.website_menu and event.website_menu != event._origin.website_menu or not event.community_menu:
event.community_menu = True
elif not event.website_menu:
event.community_menu = False
# ------------------------------------------------------------
# WEBSITE MENU MANAGEMENT
# ------------------------------------------------------------
# OVERRIDES: ADD SEQUENCE
def _get_menu_update_fields(self):
update_fields = super(EventEvent, self)._get_menu_update_fields()
update_fields += ['community_menu']
return update_fields
def _update_website_menus(self, menus_update_by_field=None):
super(EventEvent, self)._update_website_menus(menus_update_by_field=menus_update_by_field)
for event in self:
if not menus_update_by_field or event in menus_update_by_field.get('community_menu'):
event._update_website_menu_entry('community_menu', 'community_menu_ids', '_get_community_menu_entries')
def _get_menu_type_field_matching(self):
res = super(EventEvent, self)._get_menu_type_field_matching()
res['community'] = 'community_menu'
return res
def _get_community_menu_entries(self):
self.ensure_one()
return [(_('Community'), '/event/%s/community' % slug(self), False, 80, 'community')]
def _get_track_menu_entries(self):
""" Remove agenda as this is now managed separately """
self.ensure_one()
return [
(_('Talks'), '/event/%s/track' % slug(self), False, 10, 'track'),
(_('Agenda'), '/event/%s/agenda' % slug(self), False, 70, False)
]
def _get_track_proposal_menu_entries(self):
""" See website_event_track._get_track_menu_entries() """
self.ensure_one()
return [(_('Talk Proposals'), '/event/%s/track_proposal' % slug(self), False, 15, 'track_proposal')]
@@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class EventType(models.Model):
_inherit = "event.type"
community_menu = fields.Boolean(
"Community Menu", compute="_compute_community_menu",
readonly=False, store=True,
help="Display community tab on website")
@api.depends('website_menu')
def _compute_community_menu(self):
for event_type in self:
event_type.community_menu = event_type.website_menu
@@ -1,12 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class EventMenu(models.Model):
_inherit = "website.event.menu"
menu_type = fields.Selection(selection_add=[
('community', 'Community Menu')
])
@@ -12,10 +12,6 @@
<label for="website_track_proposal" string="Allow Track Proposals"/>
<field name="website_track_proposal"/>
</xpath>
<xpath expr="//div[@name='event_menu_configuration']" position='inside'>
<label for="community_menu" string="Community"/>
<field name="community_menu"/>
</xpath>
</field>
</record>
@@ -1,16 +0,0 @@
<?xml version="1.0"?>
<odoo><data>
<record id="event_type_view_form" model="ir.ui.view">
<field name="name">event.type.view.form.inherit.meet</field>
<field name="model">event.type</field>
<field name="inherit_id" ref="website_event.event_type_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='website_menu']" position='after'>
<div id="community-menu" class="row mt16" groups="base.group_no_one" attrs="{'invisible': [('website_menu', '=', False)]}">
<label class="col-lg-4" for="community_menu"/> <field name="community_menu"/>
</div>
</xpath>
</field>
</record>
</data></odoo>
@@ -5,11 +5,11 @@ import math
from odoo import http
from odoo.addons.http_routing.models.ir_http import slug
from odoo.addons.website_event_track_online.controllers.community import WebsiteEventCommunityController
from odoo.addons.website_event.controllers.community import EventCommunityController
from odoo.http import request
class WebsiteEventTrackQuizCommunityController(WebsiteEventCommunityController):
class WebsiteEventTrackQuizCommunityController(EventCommunityController):
_visitors_per_page = 30
_pager_max_pages = 5