[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
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -157,6 +157,14 @@ class TestEventData(TestEventCommon):
|
||||
def test_event_registrable(self):
|
||||
"""Test if `_compute_event_registrations_open` works properly."""
|
||||
event = self.event_0.with_user(self.env.user)
|
||||
event.write({
|
||||
'date_begin': datetime(2020, 1, 30, 8, 0, 0),
|
||||
'date_end': datetime(2020, 1, 31, 8, 0, 0),
|
||||
})
|
||||
self.assertFalse(event.event_registrations_open)
|
||||
event.write({
|
||||
'date_end': datetime(2020, 2, 4, 8, 0, 0),
|
||||
})
|
||||
self.assertTrue(event.event_registrations_open)
|
||||
|
||||
# ticket without dates boundaries -> ok
|
||||
|
||||
@@ -527,7 +527,7 @@
|
||||
<i class="fa fa-pencil mr-2" role="img" aria-label="Edit" title="Edit event registration in backend"/><em>Configure Event Tickets</em>
|
||||
</a>
|
||||
</div>
|
||||
<div t-if="event.start_sale_date and event.start_sale_date > datetime.date.today() or not event.event_registrations_open" class="bg-white mb-5">
|
||||
<div t-if="not event.event_registrations_open" class="bg-white mb-5">
|
||||
<div class="alert alert-info mb-0 d-flex justify-content-between align-items-center" role="status">
|
||||
<t t-if="event.start_sale_date and event.start_sale_date > datetime.date.today()">
|
||||
<em class="col-md-8">Ticket Sales starting on <t t-esc="event.start_sale_date"/></em>
|
||||
|
||||
Reference in New Issue
Block a user