Skip to content

Commit

Permalink
[REF] hr*: remove the use of utcnow
Browse files Browse the repository at this point in the history
utcnow is deprecated and should not be used anymore.
this commit swap utcnow() by now(timezone.utc)

see:
python/cpython#103857
python/cpython#81669

python 3.12 changes related to this:
https://docs.python.org/3/whatsnew/3.12.html#deprecated

task-3932942
  • Loading branch information
Flotchet committed May 16, 2024
1 parent 1ee76cf commit 67ff28c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 2 additions & 3 deletions addons/hr_holidays/models/hr_department.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import datetime
from datetime import datetime, timezone
from dateutil.relativedelta import relativedelta

from odoo import api, fields, models
Expand All @@ -23,7 +22,7 @@ class Department(models.Model):
def _compute_leave_count(self):
Requests = self.env['hr.leave']
Allocations = self.env['hr.leave.allocation']
today_date = datetime.datetime.utcnow().date()
today_date = datetime.now(timezone.utc).date()
today_start = fields.Datetime.to_string(today_date) # get the midnight of the current utc day
today_end = fields.Datetime.to_string(today_date + relativedelta(hours=23, minutes=59, seconds=59))

Expand Down
4 changes: 2 additions & 2 deletions addons/hr_holidays/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from datetime import datetime, date, time
from datetime import datetime, date, time, timezone
from collections import defaultdict
from dateutil.relativedelta import relativedelta
import pytz
Expand Down Expand Up @@ -175,7 +175,7 @@ def _search_absent_employee(self, operator, value):
raise UserError(_('Operation not supported'))
# This search is only used for the 'Absent Today' filter however
# this only returns employees that are absent right now.
today_date = datetime.utcnow().date()
today_date = datetime.now(timezone.utc).date()
today_start = fields.Datetime.to_string(today_date)
today_end = fields.Datetime.to_string(today_date + relativedelta(hours=23, minutes=59, seconds=59))
holidays = self.env['hr.leave'].sudo().search([
Expand Down
5 changes: 2 additions & 3 deletions addons/hr_holidays/tests/test_out_of_office.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from datetime import date, datetime
from datetime import date, datetime, timezone
from dateutil.relativedelta import relativedelta

from odoo import fields
Expand Down Expand Up @@ -105,7 +104,7 @@ def test_leave_im_status_performance_partner_leave_offline(self):
def test_search_absent_employee(self):
present_employees = self.env['hr.employee'].search([('is_absent', '!=', True)])
absent_employees = self.env['hr.employee'].search([('is_absent', '=', True)])
today_date = datetime.utcnow().date()
today_date = datetime.now(timezone.utc).date()
holidays = self.env['hr.leave'].sudo().search([
('employee_id', '!=', False),
('state', '=', 'validate'),
Expand Down

0 comments on commit 67ff28c

Please sign in to comment.