diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-03-31 09:43:09 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-04-03 11:07:55 +0000 |
| commit | d2840a0519725c8d55cafe9e2b91ebbfe515c804 (patch) | |
| tree | afb4de9be079586baa802e7e8d16a46220efce8c /addons | |
| parent | 55c8367ce7d6801d4af3dc813c63eafa4725657e (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')
| -rw-r--r-- | addons/event/models/event_event.py | 15 | ||||
| -rw-r--r-- | addons/event/tests/test_event_internals.py | 8 | ||||
| -rw-r--r-- | addons/website_event/views/event_templates.xml | 2 |
3 files changed, 20 insertions, 5 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') diff --git a/addons/event/tests/test_event_internals.py b/addons/event/tests/test_event_internals.py index 862f19aaddf..51dd7c33258 100644 --- a/addons/event/tests/test_event_internals.py +++ b/addons/event/tests/test_event_internals.py @@ -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 diff --git a/addons/website_event/views/event_templates.xml b/addons/website_event/views/event_templates.xml index 27815e3215c..c1d73b6d07b 100644 --- a/addons/website_event/views/event_templates.xml +++ b/addons/website_event/views/event_templates.xml @@ -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> |
