summaryrefslogtreecommitdiff
path: root/addons/event/models
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-03-31 09:43:09 +0000
committerThibault Delavallée <tde@odoo.com>2020-04-03 11:07:55 +0000
commitd2840a0519725c8d55cafe9e2b91ebbfe515c804 (patch)
treeafb4de9be079586baa802e7e8d16a46220efce8c /addons/event/models
parent55c8367ce7d6801d4af3dc813c63eafa4725657e (diff)
[FIX] event: include timezoned event date_end in registration open computation
Purpose of this commit is to try to lessen random conditions being concatenated in templates by correctly computing event_registrations_open field that is now correctly based on * event.date_end -> if event is done, registrations are not open anymore; * event.start_sale_date -> lowest start date of tickets (if any; start_sale_date is False if no ticket are defined, see _compute_start_sale_date); * any ticket is available for sale (seats available) if any; * seats are unlimited or seats are available; Some better timezone computation is included even if it could be done better. Task ID 2228189 Community PR odoo/odoo#48652 X-original-commit: a11af9074499465b6dd8ad1400e60c7af96e21c7
Diffstat (limited to 'addons/event/models')
-rw-r--r--addons/event/models/event_event.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/addons/event/models/event_event.py b/addons/event/models/event_event.py
index b76ca84d875..b4f740a89bf 100644
--- a/addons/event/models/event_event.py
+++ b/addons/event/models/event_event.py
@@ -169,7 +169,7 @@ class EventEvent(models.Model):
compute='_compute_from_event_type', readonly=False, store=True)
event_registrations_open = fields.Boolean(
'Registration open', compute='_compute_event_registrations_open',
- help='Registrations are open if seats are available on event and if tickets are sellable if ticketing is used.')
+ help='Registrations are open if event is not ended, seats are available on event and if tickets are sellable if ticketing is used.')
start_sale_date = fields.Date(
'Start sale date', compute='_compute_start_sale_date',
help='If ticketing is used, this is the lowest starting sale date of tickets.')
@@ -241,16 +241,23 @@ class EventEvent(models.Model):
seats_expected = event.seats_unconfirmed + event.seats_reserved + event.seats_used
event.seats_expected = seats_expected
- @api.depends('date_end', 'seats_available', 'seats_limited', 'event_ticket_ids.sale_available')
+ @api.depends('date_tz', 'start_sale_date', 'date_end', 'seats_available', 'seats_limited', 'event_ticket_ids.sale_available')
def _compute_event_registrations_open(self):
""" Compute whether people may take registrations for this event
+ * event.date_end -> if event is done, registrations are not open anymore;
+ * event.start_sale_date -> lowest start date of tickets (if any; start_sale_date
+ is False if no ticket are defined, see _compute_start_sale_date);
* any ticket is available for sale (seats available) if any;
* seats are unlimited or seats are available;
"""
for event in self:
- event.event_registrations_open = event.date_end and (event.date_end > fields.Datetime.now()) and \
- (event.seats_available or not event.seats_limited) and \
+ event = event._set_tz_context()
+ current_datetime = fields.Datetime.context_timestamp(event, fields.Datetime.now())
+ date_end_tz = event.date_end.astimezone(pytz.timezone(event.date_tz or 'UTC')) if event.date_end else False
+ event.event_registrations_open = (event.start_sale_date <= current_datetime.date() if event.start_sale_date else True) and \
+ (date_end_tz >= current_datetime if date_end_tz else True) and \
+ (not event.seats_limited or event.seats_available) and \
(not event.event_ticket_ids or any(ticket.sale_available for ticket in event.event_ticket_ids))
@api.depends('event_ticket_ids.start_sale_date')