From adea1ca9ca6b62146e4f8be9c8afbd084debd462 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Tue, 5 Sep 2023 13:53:32 +0200 Subject: [PATCH] [FIX] resource_work_time_from_contracts: Make ORM accept UTC datetimes Signed-off-by: Carmen Bianca BAKKER --- .../tests/test_work_time.py | 2 -- .../tests/test_work_time_base.py | 13 ++++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/resource_work_time_from_contracts/tests/test_work_time.py b/resource_work_time_from_contracts/tests/test_work_time.py index 116f505fa..ff78cd8ec 100644 --- a/resource_work_time_from_contracts/tests/test_work_time.py +++ b/resource_work_time_from_contracts/tests/test_work_time.py @@ -3,8 +3,6 @@ from datetime import date, timedelta, timezone -from odoo.addons.test_resource.tests.test_resource import datetime_str - from .test_work_time_base import TestWorkTimeBase diff --git a/resource_work_time_from_contracts/tests/test_work_time_base.py b/resource_work_time_from_contracts/tests/test_work_time_base.py index 4398afed0..acaba1f2c 100644 --- a/resource_work_time_from_contracts/tests/test_work_time_base.py +++ b/resource_work_time_from_contracts/tests/test_work_time_base.py @@ -140,6 +140,13 @@ def to_utc_datetime(self, year, month, day, *args, **kwargs): """ Create a UTC datetime from local time values """ - return self.timezone.localize( - datetime.datetime(year, month, day, *args, **kwargs) - ).astimezone(pytz.utc) + return ( + self.timezone.localize( + datetime.datetime(year, month, day, *args, **kwargs) + ).astimezone(pytz.utc) + # Odoo's ORM refuses to work with datetime objects that have tzinfo + # set. Unset it here instead of doing it manually every time. The + # tzinfo is implicit as a result of this function's name being + # 'to_utc_datetime'. + .replace(tzinfo=None) + )