[FIX] hr_payroll: Convert a method into a helper function

This commit is contained in:
Yannick Tivisse
2019-02-18 15:28:15 +00:00
parent 8fa8ffdf27
commit ac1ec35af0
4 changed files with 19 additions and 19 deletions
+3 -3
View File
@@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields, api
from odoo.addons.resource.models.resource_mixin import timezone_datetime
class ResourceCalendar(models.Model):
_inherit = 'resource.calendar'
@@ -61,8 +61,8 @@ class ResourceMixin(models.AbstractModel):
domain = [('benefit_type_id', 'in', benefit_type_ids)]
# naive datetimes are made explicit in UTC
from_datetime = self._timezone_datetime(from_datetime)
to_datetime = self._timezone_datetime(to_datetime)
from_datetime = timezone_datetime(from_datetime)
to_datetime = timezone_datetime(to_datetime)
day_total = self._get_day_total(from_datetime, to_datetime, calendar, resource)
# actual hours per day
+2 -3
View File
@@ -45,8 +45,7 @@ if records:
<span class="fa fa-exclamation-triangle mr-2" aria-label="Conflict" title="error"/>
</t>
<t t-if="record.state == 'validated'">
<span class="fa fa-check-circle-o" aria-label="Validated" title="validated"/>
<t t-esc="' '"/>
<span class="fa fa-check-circle-o mr-2" aria-label="Validated" title="validated"/>
</t>
<t t-foreach="widget.displayFields" t-as="name">
<t t-esc="format(record, name)"/>
@@ -67,7 +66,7 @@ if records:
<header>
<field name="display_warning" invisible="1"/>
<field name="leave_id" invisible="1"/>
<button string="Go To Conflicting Leave" name="action_leave" type="object" attrs="{'invisible': ['|', '|', '!',('display_warning', '=', True), '!', ('leave_id', '!=', False), ('benefit_type_id', '=', False)]}"/>
<button string="Go To Conflicting Leave" name="action_leave" type="object" attrs="{'invisible': ['|', '|', '!',('display_warning', '=', True), ('leave_id', '=', False), ('benefit_type_id', '=', False)]}"/>
<field name="state" widget="statusbar" options="{'clickable': '1'}"/>
</header>
<sheet>
+3 -2
View File
@@ -11,6 +11,7 @@ from pytz import timezone, utc
from odoo import api, fields, models, _
from odoo.addons.base.models.res_partner import _tz_get
from odoo.exceptions import ValidationError
from odoo.osv import expression
from odoo.tools.float_utils import float_round
# Default hour per day value. The one should
@@ -211,10 +212,10 @@ class ResourceCalendar(models.Model):
resource_ids = [resource.id, False] if resource else [False]
domain = domain if domain is not None else []
domain = domain + [
domain = expression.AND([domain, [
('calendar_id', '=', self.id),
('resource_id', 'in', resource_ids),
]
]])
# express all dates and times in the resource's timezone
tz = timezone((resource or self).tz)
+11 -11
View File
@@ -12,6 +12,12 @@ from odoo.tools import float_utils
ROUNDING_FACTOR = 16
def timezone_datetime(time):
if not time.tzinfo:
time = time.replace(tzinfo=utc)
return time
class ResourceMixin(models.AbstractModel):
_name = "resource.mixin"
_description = 'Resource Mixin'
@@ -75,7 +81,7 @@ class ResourceMixin(models.AbstractModel):
def _get_day_total(self, from_datetime, to_datetime, calendar, resource):
"""
@return dict with hours of attendance in each day between `from_datetime` and `to_datetime`
:return: dict with hours of attendance in each day between `from_datetime` and `to_datetime`
"""
# total hours per day: retrieve attendances with one extra day margin,
@@ -88,12 +94,6 @@ class ResourceMixin(models.AbstractModel):
day_total[start.date()] += (stop - start).total_seconds() / 3600
return day_total
def _timezone_datetime(self, time):
if not time.tzinfo:
time = time.replace(tzinfo=utc)
return time
def _get_work_days_data(self, from_datetime, to_datetime, compute_leaves=True, calendar=None, domain=None):
"""
By default the resource calendar is used, but it can be
@@ -109,8 +109,8 @@ class ResourceMixin(models.AbstractModel):
calendar = calendar or self.resource_calendar_id
# naive datetimes are made explicit in UTC
from_datetime = self._timezone_datetime(from_datetime)
to_datetime = self._timezone_datetime(to_datetime)
from_datetime = timezone_datetime(from_datetime)
to_datetime = timezone_datetime(to_datetime)
day_total = self._get_day_total(from_datetime, to_datetime, calendar, resource)
@@ -137,8 +137,8 @@ class ResourceMixin(models.AbstractModel):
calendar = calendar or self.resource_calendar_id
# naive datetimes are made explicit in UTC
from_datetime = self._timezone_datetime(from_datetime)
to_datetime = self._timezone_datetime(to_datetime)
from_datetime = timezone_datetime(from_datetime)
to_datetime = timezone_datetime(to_datetime)
day_total = self._get_day_total(from_datetime, to_datetime, calendar, resource)