diff --git a/odoo/addons/test_read_group/tests/test_fill_temporal.py b/odoo/addons/test_read_group/tests/test_fill_temporal.py index d7f6fb2856e2264f6bcdc30cde1e04b7efec8410..89894914070b26f61978c70d6e29f970a6f9ff52 100644 --- a/odoo/addons/test_read_group/tests/test_fill_temporal.py +++ b/odoo/addons/test_read_group/tests/test_fill_temporal.py @@ -531,6 +531,50 @@ class TestFillTemporal(common.TransactionCase): self.assertEqual(groups, expected) + def test_quarter_with_timezones(self): + """Test quarter with timezones. + + We group year by quarter and check that it is consistent with timezone. + """ + self.Model.create({'datetime': '2016-01-01 03:30:00', 'value': 2}) + self.Model.create({'datetime': '2016-12-30 22:30:00', 'value': 3}) + + expected = [{ + '__domain': ['&', + ('datetime', '>=', '2015-12-31 17:00:00'), + ('datetime', '<', '2016-03-31 16:00:00')], + 'datetime:quarter': 'Q1 2016', + 'datetime_count': 1, + 'value': 2 + }, { + '__domain': ['&', + ('datetime', '>=', '2016-03-31 16:00:00'), + ('datetime', '<', '2016-06-30 16:00:00')], + 'datetime:quarter': 'Q2 2016', + 'datetime_count': 0, + 'value': False + }, { + '__domain': ['&', + ('datetime', '>=', '2016-06-30 16:00:00'), + ('datetime', '<', '2016-09-30 17:00:00')], + 'datetime:quarter': 'Q3 2016', + 'datetime_count': 0, + 'value': False + }, { + '__domain': ['&', + ('datetime', '>=', '2016-09-30 17:00:00'), + ('datetime', '<', '2016-12-31 17:00:00')], + 'datetime:quarter': 'Q4 2016', + 'datetime_count': 1, + 'value': 3 + }] + + model_fill = self.Model.with_context(tz='Asia/Hovd', fill_temporal=True) + groups = model_fill.read_group([], fields=['datetime', 'value'], + groupby=['datetime:quarter']) + + self.assertEqual(groups, expected) + def test_egde_fx_tz(self): """We test if different edge effect by using a different timezone from the user context diff --git a/odoo/models.py b/odoo/models.py index 4f67eca79fb767fd471f9da5291c915f6ef926d0..edad6bd04b2d92484b76fb71d78a054cd8eb4496 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -2069,6 +2069,8 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})): if gb['tz_convert']: tzinfo = range_start.tzinfo range_start = range_start.astimezone(pytz.utc) + # take into account possible hour change between start and end + range_end = tzinfo.localize(range_end.replace(tzinfo=None)) range_end = range_end.astimezone(pytz.utc) range_start = range_start.strftime(fmt)