[IMP] Add group on leave

[IMP] interval_remove_leaves everywhere instead of interval_remove_leaves_groups once

[FIX] Add cr, uid in test
This commit is contained in:
Josse Colpaert
2014-12-19 11:08:19 +01:00
parent fd5e7f20d0
commit 61a415badd
3 changed files with 30 additions and 10 deletions
+4 -4
View File
@@ -86,7 +86,7 @@ class resource_calendar(osv.osv):
cleaned.append(tuple(working_interval))
return cleaned
def interval_remove_leaves(self, interval, leave_intervals):
def interval_remove_leaves(self, cr, uid, interval, leave_intervals, context=None):
""" Utility method that remove leave intervals from a base interval:
- clean the leave intervals, to have an ordered list of not-overlapping
@@ -339,7 +339,7 @@ class resource_calendar(osv.osv):
if default_interval:
working_interval = (start_dt.replace(hour=default_interval[0], minute=0, second=0),
start_dt.replace(hour=default_interval[1], minute=0, second=0))
intervals = self.interval_remove_leaves(working_interval, work_limits)
intervals = self.interval_remove_leaves(cr, uid, working_interval, work_limits, context=context)
return intervals
working_intervals = []
@@ -359,7 +359,7 @@ class resource_calendar(osv.osv):
calendar_working_day.id,
)
working_intervals += self.interval_remove_leaves(working_interval, work_limits)
working_intervals += self.interval_remove_leaves(cr, uid, working_interval, work_limits, context=context)
# find leave intervals
if leaves is None and compute_leaves:
@@ -367,7 +367,7 @@ class resource_calendar(osv.osv):
# filter according to leaves
for interval in working_intervals:
work_intervals = self.interval_remove_leaves(interval, leaves)
work_intervals = self.interval_remove_leaves(cr, uid, interval, leaves, context=context)
intervals += work_intervals
return intervals
+2 -1
View File
@@ -28,6 +28,7 @@ from openerp.addons.resource.tests.common import TestResourceCommon
class TestResource(TestResourceCommon):
def test_00_intervals(self):
cr, uid = self.cr, self.uid
intervals = [
(
datetime.strptime('2013-02-04 09:00:00', '%Y-%m-%d %H:%M:%S'),
@@ -65,7 +66,7 @@ class TestResource(TestResourceCommon):
# Test: disjoint removal
working_interval = (datetime.strptime('2013-02-04 08:00:00', '%Y-%m-%d %H:%M:%S'), datetime.strptime('2013-02-04 18:00:00', '%Y-%m-%d %H:%M:%S'))
result = self.resource_calendar.interval_remove_leaves(working_interval, intervals)
result = self.resource_calendar.interval_remove_leaves(cr, uid, working_interval, intervals)
self.assertEqual(len(result), 1, 'resource_calendar: wrong leave removal from interval')
# First interval: 04, 14-17
self.assertEqual(result[0][0], datetime.strptime('2013-02-04 14:00:00', '%Y-%m-%d %H:%M:%S'), 'resource_calendar: wrong leave removal from interval')
+24 -5
View File
@@ -4,6 +4,12 @@ from openerp.osv import fields, osv
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
class resource_calendar_leaves(osv.osv):
_inherit = "resource.calendar.leaves"
_columns = {
'group_id': fields.many2one('procurement.group', string="Procurement Group"),
}
class resource_calendar(osv.osv):
_inherit = "resource.calendar"
@@ -57,10 +63,14 @@ class resource_calendar(osv.osv):
if start_datetime and date_to < start_datetime:
continue
leaves.append((date_from, date_to))
leaves.append((date_from, date_to, leave.group_id.id))
return leaves
def interval_remove_leaves(self, interval, leave_intervals):
# --------------------------------------------------
# Utility methods
# --------------------------------------------------
def interval_remove_leaves(self, cr, uid, interval, leave_intervals, context=None):
""" Utility method that remove leave intervals from a base interval:
- clean the leave intervals, to have an ordered list of not-overlapping
@@ -76,6 +86,7 @@ class resource_calendar(osv.osv):
interval
- ending within the current interval: update the current interval begin
to match the leave interval ending
- take into account the procurement group when needed
:param tuple interval: a tuple (beginning datetime, ending datetime) that
is the base interval from which the leave intervals
@@ -89,13 +100,22 @@ class resource_calendar(osv.osv):
if leave_intervals is None:
leave_intervals = []
intervals = []
leave_intervals = self.interval_clean(leave_intervals)
current_interval = [interval[0], interval[1]]
#leave_intervals = self.interval_clean(leave_intervals) NOT NECESSARY TO CLEAN HERE AS IT WOULD REMOVE GROUP INFO
current_interval = list(interval)
for leave in leave_intervals:
if len(leave) > 2:
current_group = False
att_obj = self.pool.get("resource.calendar.attendance")
if leave[2]:
if len(current_interval) > 2:
current_group = current_interval[2] and att_obj.browse(cr, uid, current_interval[2], context=context).group_id.id or False
if leave[2] != current_group:
continue
if leave[1] <= current_interval[0]:
continue
if leave[0] >= current_interval[1]:
break
if current_interval[0] < leave[0] < current_interval[1]:
current_interval[1] = leave[0]
intervals.append((current_interval[0], current_interval[1]))
@@ -111,7 +131,6 @@ class resource_calendar(osv.osv):
return intervals
class resource_calendar_attendance(osv.osv):
_inherit = "resource.calendar.attendance"