[FIX] website_event_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#132605 X-original-commit: 721b996685c8f6943832acfce52b05c8773522f9 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# -*- 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, _
|
||||
@@ -153,7 +153,7 @@ class Sponsor(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)
|
||||
@@ -166,6 +166,9 @@ class Sponsor(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])
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestSponsorData(TestEventExhibitorCommon):
|
||||
@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) """
|
||||
with freeze_time(self.reference_now):
|
||||
event = self.env['event.event'].browse(self.event_0.id)
|
||||
sponsor = self.env['event.sponsor'].browse(self.sponsor_0.id)
|
||||
@@ -62,3 +62,32 @@ class TestSponsorData(TestEventExhibitorCommon):
|
||||
sponsor.invalidate_model(['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_model(fnames=['is_ongoing'])
|
||||
sponsor.hour_from = 0.0 # 0 -> 18
|
||||
|
||||
# Inside opening hours (17 < 18)
|
||||
with freeze_time(datetime(2020, 7, 6, 15, 0, 1)):
|
||||
sponsor.invalidate_model(fnames=['is_in_opening_hours'])
|
||||
self.assertTrue(sponsor.is_in_opening_hours)
|
||||
|
||||
# Outside opening hours (21 > 18)
|
||||
with freeze_time(datetime(2020, 7, 6, 19, 0, 1)):
|
||||
sponsor.invalidate_model(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)
|
||||
with freeze_time(datetime(2020, 7, 6, 9, 0, 1)):
|
||||
sponsor.invalidate_model(fnames=['is_in_opening_hours'])
|
||||
self.assertTrue(sponsor.is_in_opening_hours)
|
||||
|
||||
# Outside opening hours (7 < 10)
|
||||
with freeze_time(datetime(2020, 7, 6, 5, 0, 1)):
|
||||
sponsor.invalidate_model(fnames=['is_in_opening_hours'])
|
||||
self.assertFalse(sponsor.is_in_opening_hours)
|
||||
|
||||
Reference in New Issue
Block a user