Skip to content

Commit

Permalink
[FIX] use datetime_str rather than to_utc_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-champonnois committed Jul 20, 2023
1 parent 7bbb859 commit eca1800
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 3 additions & 5 deletions resource_work_time_from_contracts/models/resource_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from odoo.tools import float_utils

from odoo.addons.resource.models.resource import ROUNDING_FACTOR
from odoo.addons.resource.models.resource_mixin import timezone_datetime


class ResourceMixin(models.AbstractModel):
Expand Down Expand Up @@ -226,10 +227,7 @@ def _get_work_time_from_contracts(self, from_datetime, to_datetime, domain=None)

def _localize_datetimes(self, from_datetime, to_datetime):
# naive datetimes are considered utc
if not from_datetime.tzinfo:
from_datetime = from_datetime.replace(tzinfo=utc)
if not to_datetime.tzinfo:
to_datetime = to_datetime.replace(tzinfo=utc)

from_datetime = timezone_datetime(from_datetime)
to_datetime = timezone_datetime(to_datetime)
tz = timezone(self.tz)
return from_datetime.astimezone(tz), to_datetime.astimezone(tz)
17 changes: 9 additions & 8 deletions resource_work_time_from_contracts/tests/test_work_days_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta, timezone

from .test_work_time_base import TestWorkTimeBase
from odoo.addons.test_resource.tests.test_resource import datetime_str


class TestWorkDaysData(TestWorkTimeBase):
Expand Down Expand Up @@ -164,8 +165,8 @@ def test_with_leaves(self):
{
"name": "Tuesday morning",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 26, 8, 42),
"date_to": self.to_utc_datetime(2021, 10, 26, 12, 30),
"date_from": datetime_str(2021, 10, 26, 8, 42),
"date_to": datetime_str(2021, 10, 26, 12, 30),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand All @@ -174,8 +175,8 @@ def test_with_leaves(self):
{
"name": "Wednesday afternoon",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 27, 13, 30),
"date_to": self.to_utc_datetime(2021, 10, 27, 17, 18),
"date_from": datetime_str(2021, 10, 27, 13, 30),
"date_to": datetime_str(2021, 10, 27, 17, 18),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand All @@ -184,8 +185,8 @@ def test_with_leaves(self):
{
"name": "Friday",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 29, 8, 42),
"date_to": self.to_utc_datetime(2021, 10, 29, 17, 18),
"date_from": datetime_str(2021, 10, 29, 8, 42),
"date_to": datetime_str(2021, 10, 29, 17, 18),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand Down Expand Up @@ -345,8 +346,8 @@ def test_timezone(self):
{
"name": "Leave",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 26, 8, 42),
"date_to": self.to_utc_datetime(2021, 10, 26, 9, 30),
"date_from": datetime_str(2021, 10, 26, 8, 42),
"date_to": datetime_str(2021, 10, 26, 9, 30),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand Down
13 changes: 7 additions & 6 deletions resource_work_time_from_contracts/tests/test_work_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import date, timedelta, timezone

from .test_work_time_base import TestWorkTimeBase
from odoo.addons.test_resource.tests.test_resource import datetime_str


class TestWorkTime(TestWorkTimeBase):
Expand Down Expand Up @@ -150,8 +151,8 @@ def test_with_leaves(self):
{
"name": "Tuesday morning",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 19, 8, 42),
"date_to": self.to_utc_datetime(2021, 10, 19, 12, 30),
"date_from": datetime_str(2021, 10, 19, 8, 42),
"date_to": datetime_str(2021, 10, 19, 12, 30),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand All @@ -160,8 +161,8 @@ def test_with_leaves(self):
{
"name": "Wednesday",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 20, 8, 42),
"date_to": self.to_utc_datetime(2021, 10, 20, 17, 18),
"date_from": datetime_str(2021, 10, 20, 8, 42),
"date_to": datetime_str(2021, 10, 20, 17, 18),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand Down Expand Up @@ -242,8 +243,8 @@ def test_timezone(self):
{
"name": "Leave",
"calendar_id": self.employee1.resource_calendar_id.id,
"date_from": self.to_utc_datetime(2021, 10, 19, 8, 42),
"date_to": self.to_utc_datetime(2021, 10, 19, 9, 30),
"date_from": datetime_str(2021, 10, 19, 8, 42),
"date_to": datetime_str(2021, 10, 19, 9, 30),
"resource_id": self.employee1.resource_id.id,
"time_type": "leave",
}
Expand Down

0 comments on commit eca1800

Please sign in to comment.