diff --git a/addons/resource/resource.py b/addons/resource/resource.py index 406bc72cef6..e2035a8d4d1 100644 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -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 diff --git a/addons/resource/tests/test_resource.py b/addons/resource/tests/test_resource.py index 0774c6d4573..1291089fce6 100644 --- a/addons/resource/tests/test_resource.py +++ b/addons/resource/tests/test_resource.py @@ -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') diff --git a/addons/stock_calendar/resource.py b/addons/stock_calendar/resource.py index 238f9906196..2a1a2d45b16 100644 --- a/addons/stock_calendar/resource.py +++ b/addons/stock_calendar/resource.py @@ -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"