[IMP] resource: add iterator on work hours count between two datetimes

This commit is contained in:
Thibault Delavallée
2017-05-03 10:13:24 +02:00
parent bf7de4d32f
commit 69631078ba
2 changed files with 14 additions and 0 deletions
+10
View File
@@ -457,6 +457,16 @@ class ResourceCalendar(models.Model):
if intervals:
yield intervals
def _iter_work_hours_count(self, from_datetime, to_datetime, resource_id):
""" Lists the current resource's work hours count between the two provided
datetime expressed in naive UTC. """
for interval in self._iter_work_intervals(from_datetime, to_datetime, resource_id):
td = timedelta()
for work_interval in interval:
td += work_interval[1] - work_interval[0]
yield (interval[0][0].date(), td.total_seconds() / 3600.0)
def _iter_work_days(self, from_date, to_date, resource_id):
""" Lists the current resource's work days between the two provided
dates (inclusive) expressed in naive UTC.
+4
View File
@@ -57,6 +57,10 @@ class ResourceMixin(models.AbstractModel):
calendar = calendar or self.resource_calendar_id
return calendar._iter_work_intervals(from_datetime, to_datetime, self.resource_id.id)
def iter_work_hours_count(self, from_datetime, to_datetime, calendar=None):
calendar = calendar or self.resource_calendar_id
return calendar._iter_work_hours_count(from_datetime, to_datetime, self.resource_id.id)
def get_leaves_day_count(self, from_datetime, to_datetime, calendar=None):
""" Return the number of leave days for the resource, taking into account
attendances. An optional calendar can be given in case multiple calendars