Skip to content
Snippets Groups Projects
Commit b7db1dfa authored by Aurélien Warnon's avatar Aurélien Warnon
Browse files

[FIX] website_event_track_exhibitor: fix sponsor 'midnight' opening hours


Currently, configuring opening hours for event sponsors 'at midnight' is not
handled properly.

If you set either the start time or the end time opening hours to "00:00",
the sponsor will be considered as always open.

We fix that by correctly taking into account that configuration.

(Note: if the user configures a sponsor to be open 'until midnight', we assume
it means midnight 'the next day').

Tests have been altered to take this into account.

Task-3459777

closes odoo/odoo#131348

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 3b3c7dca
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from datetime import datetime, timedelta
from pytz import timezone, utc
from odoo import api, fields, models
......@@ -73,7 +73,7 @@ class EventSponsor(models.Model):
for sponsor in self:
if not sponsor.event_id.is_ongoing:
sponsor.is_in_opening_hours = False
elif not sponsor.hour_from or not sponsor.hour_to:
elif sponsor.hour_from is False or sponsor.hour_to is False:
sponsor.is_in_opening_hours = True
else:
event_tz = timezone(sponsor.event_id.date_tz)
......@@ -86,6 +86,9 @@ class EventSponsor(models.Model):
# compute opening hours
opening_from_tz = event_tz.localize(datetime.combine(now_tz.date(), float_to_time(sponsor.hour_from)))
opening_to_tz = event_tz.localize(datetime.combine(now_tz.date(), float_to_time(sponsor.hour_to)))
if sponsor.hour_to == 0:
# when closing 'at midnight', we consider it's at midnight the next day
opening_to_tz = opening_to_tz + timedelta(days=1)
opening_from = max([dt_begin, opening_from_tz])
opening_to = min([dt_end, opening_to_tz])
......
......@@ -31,7 +31,7 @@ class TestSponsorData(TestEventTrackOnlineCommon):
@users('user_eventmanager')
def test_event_date_computation(self):
""" Test date computation. Pay attention that mocks returns UTC values, meaning
we have to take into account Europe/Brussels offset """
we have to take into account Europe/Brussels offset (+2 in July) """
event = self.env['event.event'].browse(self.event_0.id)
sponsor = self.env['event.sponsor'].browse(self.sponsor_0.id)
event.invalidate_cache(fnames=['is_ongoing'])
......@@ -85,3 +85,36 @@ class TestSponsorData(TestEventTrackOnlineCommon):
sponsor.invalidate_cache(fnames=['is_in_opening_hours'])
self.assertFalse(sponsor.is_in_opening_hours)
self.assertFalse(event.is_ongoing)
# Use "00:00" as opening hours for sponsor -> should still work
event.invalidate_cache(fnames=['is_ongoing'])
sponsor.hour_from = 0.0 # 0 -> 18
# Inside opening hours (17 < 18)
self.mock_wevent_dt.now.return_value = datetime(2020, 7, 6, 15, 0, 1)
self.mock_wevent_exhib_dt.now.return_value = datetime(2020, 7, 6, 15, 0, 1)
sponsor.invalidate_cache(fnames=['is_in_opening_hours'])
self.assertTrue(sponsor.is_in_opening_hours)
# Outside opening hours (21 > 18)
self.mock_wevent_dt.now.return_value = datetime(2020, 7, 6, 19, 0, 1)
self.mock_wevent_exhib_dt.now.return_value = datetime(2020, 7, 6, 19, 0, 1)
sponsor.invalidate_cache(fnames=['is_in_opening_hours'])
self.assertFalse(sponsor.is_in_opening_hours)
# Use "00:00" as closing hours for sponsor -> should still work
# (considered 'at midnight the next day')
sponsor.hour_from = 10.0
sponsor.hour_to = 0.0
# Inside opening hours (11 > 10)
self.mock_wevent_dt.now.return_value = datetime(2020, 7, 6, 9, 0, 1)
self.mock_wevent_exhib_dt.now.return_value = datetime(2020, 7, 6, 9, 0, 1)
sponsor.invalidate_cache(fnames=['is_in_opening_hours'])
self.assertTrue(sponsor.is_in_opening_hours)
# Outside opening hours (7 < 10)
self.mock_wevent_dt.now.return_value = datetime(2020, 7, 6, 5, 0, 1)
self.mock_wevent_exhib_dt.now.return_value = datetime(2020, 7, 6, 5, 0, 1)
sponsor.invalidate_cache(fnames=['is_in_opening_hours'])
self.assertFalse(sponsor.is_in_opening_hours)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment