[IMP] website_event_online: add time-related computation on events
RATIONALE
Events are sometimes held online, gathering a community. In this merge we
improve Event application to better support full-online events with improved
tracks, wishlists, chat rooms, ...
PURPOSE
Reduce complexity of frontend templates and ease time-related display by
adding computed fields on event.
SPECIFICATIONS
Add following information to be used in future templates
* is_ongoing: between start and end of event;
* is_done: after end of event;
* start_today: will start today, for example to display remaining hours
before start;
* start_remaining: remaining time before start;
Ensure timezone are correctly taken into account. Base heuristic is
* datetime are stored in UTC in database;
* TZ of event is stored on date_tz of event;
* make most computation based on UTC: compare UTC of current visitor to
UTC of event datetime;
LINKS
Community PR #53540
Enterprise PR odoo/enterprise#11384
Task ID-2252655 (Main Online Event task)
Task ID-2283796 (Event B2Basics / Registration Flow)
Co-Authored-By: Aurélien Warnon <awa@odoo.com>
Co-Authored-By: David Beguin <dbe@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
This commit is contained in:
co-authored by
Aurélien Warnon
David Beguin
parent
54dafd3b7f
commit
b3d2df460f
@@ -1,8 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import datetime
|
||||
from pytz import timezone, utc
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.addons.http_routing.models.ir_http import slug
|
||||
from odoo.addons.resource.models.resource import float_to_time
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
@@ -14,12 +18,42 @@ class Event(models.Model):
|
||||
menu_register_cta = fields.Boolean(
|
||||
'Add Register Button', compute='_compute_menu_register_cta',
|
||||
readonly=False, store=True)
|
||||
# live information
|
||||
is_ongoing = fields.Boolean(
|
||||
'Is Ongoing', compute='_compute_time_data', search='_search_is_ongoing',
|
||||
help="Whether event has begun")
|
||||
is_done = fields.Boolean(
|
||||
'Is Done', compute='_compute_time_data',
|
||||
help="Whether event is finished")
|
||||
start_today = fields.Boolean(
|
||||
'Start Today', compute='_compute_time_data',
|
||||
help="Whether event is going to start today if still not ongoing")
|
||||
start_remaining = fields.Integer(
|
||||
'Remaining before start', compute='_compute_time_data',
|
||||
help="Remaining time before event starts (minutes)")
|
||||
|
||||
@api.depends('website_menu')
|
||||
def _compute_menu_register_cta(self):
|
||||
for event in self:
|
||||
event.menu_register_cta = event.website_menu
|
||||
|
||||
@api.depends('date_begin', 'date_end')
|
||||
def _compute_time_data(self):
|
||||
""" Compute start and remaining time. Do everything in UTC as we compute only
|
||||
time deltas here. """
|
||||
now_utc = utc.localize(fields.Datetime.now().replace(microsecond=0))
|
||||
for event in self:
|
||||
date_begin_utc = utc.localize(event.date_begin, is_dst=False)
|
||||
date_end_utc = utc.localize(event.date_end, is_dst=False)
|
||||
event.is_ongoing = date_begin_utc <= now_utc <= date_end_utc
|
||||
event.is_done = now_utc > date_end_utc
|
||||
event.start_today = date_begin_utc.date() == now_utc.date()
|
||||
if date_begin_utc >= now_utc:
|
||||
td = date_begin_utc - now_utc
|
||||
event.start_remaining = int(td.total_seconds() / 60)
|
||||
else:
|
||||
event.start_remaining = 0
|
||||
|
||||
def _compute_is_participating(self):
|
||||
""" Override is_participating to improve heuristic that is now
|
||||
|
||||
|
||||
Reference in New Issue
Block a user