From 3b29008aef50504860214ce6a9973f1a6be33abe Mon Sep 17 00:00:00 2001 From: "Rvo (Open ERP)" Date: Thu, 18 Feb 2010 15:37:31 +0530 Subject: [ADD]:added constraints on phases when date_start or date_end field modified,changed interval_min_get method of resource bzr revid: rvo@tinyerp.co.in-20100218100731-cng5emi7udnf0fdf --- addons/resource/__init__.py | 1 + addons/resource/resource.py | 48 +++++++++++++-------------------------------- 2 files changed, 15 insertions(+), 34 deletions(-) (limited to 'addons/resource') diff --git a/addons/resource/__init__.py b/addons/resource/__init__.py index 2aa86a90c65..77485b4f121 100755 --- a/addons/resource/__init__.py +++ b/addons/resource/__init__.py @@ -20,6 +20,7 @@ ############################################################################## import resource +import faces # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/resource/resource.py b/addons/resource/resource.py index 7ac36e5e7bd..aac885c2898 100755 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -36,50 +36,30 @@ class resource_calendar(osv.osv): _defaults = { 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.calendar', c) } - def interval_min_get(self, cr, uid, id, dt_from, hours , resource=0): - dt_leave = [] + def interval_min_get(self, cr, uid, id, dt_from, hours): if not id: return [(dt_from-mx.DateTime.RelativeDateTime(hours=int(hours)*3), dt_from)] - if resource: - resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,[('resource_id','=',resource)]) - if resource_leave_ids: - res_leaves = self.pool.get('resource.calendar.leaves').read(cr,uid,resource_leave_ids,['date_from','date_to']) - for i in range(len(res_leaves)): - dtf = mx.DateTime.strptime(res_leaves[i]['date_from'],'%Y-%m-%d %H:%M:%S') - dtt = mx.DateTime.strptime(res_leaves[i]['date_to'],'%Y-%m-%d %H:%M:%S') - leave_days = ((dtt - dtf).days) + 1 - for x in range(int(leave_days)): - dt_leave.append((dtf + mx.DateTime.RelativeDateTime(days=x)).strftime('%Y-%m-%d')) - dt_leave.sort() todo = hours cycle = 0 result = [] maxrecur = 100 current_hour = dt_from.hour while (todo>0) and maxrecur: - cr.execute("select hour_from,hour_to from resource_calendar_week where dayofweek='%s' and calendar_id=%s order by hour_from", (dt_from.day_of_week,id)) + cr.execute("select hour_from,hour_to from resource_calendar_week where dayofweek='%s' and calendar_id=%s order by hour_from desc", (dt_from.day_of_week,id)) for (hour_from,hour_to) in cr.fetchall(): - if (hour_to>current_hour) and (todo>0): - m = max(hour_from, current_hour) - if (hour_to-m)>todo: - hour_to = m+todo - d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) - d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_to)),int((hour_to%1) * 60)) - dt1 = d1.strftime('%Y-%m-%d') - dt2 = d2.strftime('%Y-%m-%d') - for i in range(len(dt_leave)): - if dt1 == dt_leave[i]: - dt_from += mx.DateTime.RelativeDateTime(days=1) - d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) - d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_to)),int((hour_to%1) * 60)) - dt1 = d1.strftime('%Y-%m-%d') - dt2 = d2.strftime('%Y-%m-%d') - result.append((d1, d2)) - current_hour = hour_to - todo -= (hour_to - m) - dt_from += mx.DateTime.RelativeDateTime(days=1) - current_hour = 0 + if (hour_from0): + m = min(hour_to, current_hour) + if (m-hour_from)>todo: + hour_from = m-todo + d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_from)),int((hour_from%1) * 60)) + d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) + result.append((d1, d2)) + current_hour = hour_from + todo -= (m-hour_from) + dt_from -= mx.DateTime.RelativeDateTime(days=1) + current_hour = 24 maxrecur -= 1 + result.reverse() return result def interval_get(self, cr, uid, id, dt_from, hours, resource=0, byday=True): -- cgit v1.2.3 From 09c358d92dba91cc7abaafdfc152cc4cc6c44a04 Mon Sep 17 00:00:00 2001 From: "Rvo (Open ERP)" Date: Fri, 19 Feb 2010 15:56:24 +0530 Subject: [IMP]:changes in interval_get and minimum_interval_get,added required fields in resource.resource bzr revid: rvo@tinyerp.co.in-20100219102624-22psr47e8xk9beo5 --- addons/resource/resource.py | 90 ++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 34 deletions(-) (limited to 'addons/resource') diff --git a/addons/resource/resource.py b/addons/resource/resource.py index aac885c2898..df58b322e46 100755 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -36,9 +36,23 @@ class resource_calendar(osv.osv): _defaults = { 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.calendar', c) } - def interval_min_get(self, cr, uid, id, dt_from, hours): + + def interval_min_get(self, cr, uid, id, dt_from, hours,resource=None): + dt_leave = [] if not id: return [(dt_from-mx.DateTime.RelativeDateTime(hours=int(hours)*3), dt_from)] + if resource: + resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,['|',('resource_id','=',resource.id),('resource_id','=',False)]) + else: + resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,[('resource_id','=',False)]) + res_leaves = self.pool.get('resource.calendar.leaves').read(cr,uid,resource_leave_ids,['date_from','date_to']) + for leave in res_leaves: + dtf = mx.DateTime.strptime(leave['date_from'],'%Y-%m-%d %H:%M:%S') + dtt = mx.DateTime.strptime(leave['date_to'],'%Y-%m-%d %H:%M:%S') + no = dtt - dtf + [dt_leave.append((dtf + mx.DateTime.RelativeDateTime(days=x)).strftime('%Y-%m-%d')) for x in range(int(no.days + 1))] + dt_leave.sort() + dt_leave.reverse() todo = hours cycle = 0 result = [] @@ -47,37 +61,45 @@ class resource_calendar(osv.osv): while (todo>0) and maxrecur: cr.execute("select hour_from,hour_to from resource_calendar_week where dayofweek='%s' and calendar_id=%s order by hour_from desc", (dt_from.day_of_week,id)) for (hour_from,hour_to) in cr.fetchall(): + leave_flag = False if (hour_from0): m = min(hour_to, current_hour) if (m-hour_from)>todo: hour_from = m-todo - d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_from)),int((hour_from%1) * 60)) - d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) - result.append((d1, d2)) - current_hour = hour_from - todo -= (m-hour_from) + dt_check = dt_from.strftime('%Y-%m-%d') + for leave in dt_leave: + if dt_check == leave: + dt_check = mx.DateTime.strptime(dt_check,"%Y-%m-%d") - mx.DateTime.RelativeDateTime(days=1) + leave_flag = True + if leave_flag: + break + else: + d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_from)),int((hour_from%1) * 60)) + d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) + result.append((d1, d2)) + current_hour = hour_from + todo -= (m-hour_from) dt_from -= mx.DateTime.RelativeDateTime(days=1) current_hour = 24 maxrecur -= 1 result.reverse() return result - def interval_get(self, cr, uid, id, dt_from, hours, resource=0, byday=True): + def interval_get(self, cr, uid, id, dt_from, hours, resource=None, byday=True): dt_leave = [] if not id: return [(dt_from,dt_from+mx.DateTime.RelativeDateTime(hours=int(hours)*3))] if resource: - resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,[('resource_id','=',resource)]) - if resource_leave_ids: - res_leaves = self.pool.get('resource.calendar.leaves').read(cr,uid,resource_leave_ids,['date_from','date_to']) - for i in range(len(res_leaves)): - dtf = mx.DateTime.strptime(res_leaves[i]['date_from'],'%Y-%m-%d %H:%M:%S') - dtt = mx.DateTime.strptime(res_leaves[i]['date_to'],'%Y-%m-%d %H:%M:%S') - no = dtt - dtf - leave_days = no.days + 1 - for x in range(int(leave_days)): - dt_leave.append((dtf + mx.DateTime.RelativeDateTime(days=x)).strftime('%Y-%m-%d')) - dt_leave.sort() + resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,['|',('resource_id','=',resource.id),('resource_id','=',False) ]) + else: + resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,[('resource_id','=',False)]) + res_leaves = self.pool.get('resource.calendar.leaves').read(cr,uid,resource_leave_ids,['date_from','date_to']) + for leave in res_leaves: + dtf = mx.DateTime.strptime(leave['date_from'],'%Y-%m-%d %H:%M:%S') + dtt = mx.DateTime.strptime(leave['date_to'],'%Y-%m-%d %H:%M:%S') + no = dtt - dtf + [dt_leave.append((dtf + mx.DateTime.RelativeDateTime(days=x)).strftime('%Y-%m-%d')) for x in range(int(no.days + 1))] + dt_leave.sort() todo = hours cycle = 0 result = [] @@ -86,24 +108,24 @@ class resource_calendar(osv.osv): while (todo>0) and maxrecur: cr.execute("select hour_from,hour_to from resource_calendar_week where dayofweek='%s' and calendar_id=%s order by hour_from", (dt_from.day_of_week,id)) for (hour_from,hour_to) in cr.fetchall(): + leave_flag = False if (hour_to>current_hour) and (todo>0): m = max(hour_from, current_hour) if (hour_to-m)>todo: hour_to = m+todo - d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) - d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_to)),int((hour_to%1) * 60)) - dt1 = d1.strftime('%Y-%m-%d') - dt2 = d2.strftime('%Y-%m-%d') - for i in range(len(dt_leave)): - if dt1 == dt_leave[i]: - dt_from += mx.DateTime.RelativeDateTime(days=1) - d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) - d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_to)),int((hour_to%1) * 60)) - dt1 = d1.strftime('%Y-%m-%d') - dt2 = d2.strftime('%Y-%m-%d') - result.append((d1, d2)) - current_hour = hour_to - todo -= (hour_to - m) + dt_check = dt_from.strftime('%Y-%m-%d') + for leave in dt_leave: + if dt_check == leave: + dt_check = mx.DateTime.strptime(dt_check,"%Y-%m-%d") + mx.DateTime.RelativeDateTime(days=1) + leave_flag = True + if leave_flag: + break + else: + d1 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(m)),int((m%1) * 60)) + d2 = mx.DateTime.DateTime(dt_from.year,dt_from.month,dt_from.day,int(math.floor(hour_to)),int((hour_to%1) * 60)) + result.append((d1, d2)) + current_hour = hour_to + todo -= (hour_to - m) dt_from += mx.DateTime.RelativeDateTime(days=1) current_hour = 0 maxrecur -= 1 @@ -135,8 +157,8 @@ class resource_resource(osv.osv): 'company_id' : fields.many2one('res.company', 'Company', required=True), 'resource_type': fields.selection([('user','Human'),('material','Material')], 'Resource Type', required=True), 'user_id' : fields.many2one('res.users', 'User',help='Related user name for the resource to manage its access.'), - 'time_efficiency' : fields.float('Efficiency factor', size=8, help="This field depict the efficiency of the resource to complete tasks. e.g resource put alone on a phase of 5 days with 5 tasks assigned to him, will show a load of 100% for this phase by default, but if we put a efficency of 200%, then his load will only be 50%."), - 'calendar_id' : fields.many2one("resource.calendar", "Working time", help="Define the schedule of resource"), + 'time_efficiency' : fields.float('Efficiency factor', size=8, required=True,help="This field depict the efficiency of the resource to complete tasks. e.g resource put alone on a phase of 5 days with 5 tasks assigned to him, will show a load of 100% for this phase by default, but if we put a efficency of 200%, then his load will only be 50%."), + 'calendar_id' : fields.many2one("resource.calendar", "Working time",required=True, help="Define the schedule of resource"), } _defaults = { 'resource_type' : lambda *a: 'user', -- cgit v1.2.3 From ef6b7026343d9bd949c579afc073e71c3bcbac43 Mon Sep 17 00:00:00 2001 From: "Rvo (Open ERP)" Date: Thu, 25 Feb 2010 15:41:23 +0530 Subject: onchange on resource_calendar_leaves,override search on resource_resource bzr revid: rvo@tinyerp.co.in-20100225101123-9zz137jdtvd7t403 --- addons/resource/resource.py | 42 ++++++++++++++++++++++++++++----------- addons/resource/resource_view.xml | 3 +-- 2 files changed, 31 insertions(+), 14 deletions(-) (limited to 'addons/resource') diff --git a/addons/resource/resource.py b/addons/resource/resource.py index df58b322e46..4d4eeaab028 100755 --- a/addons/resource/resource.py +++ b/addons/resource/resource.py @@ -37,15 +37,13 @@ class resource_calendar(osv.osv): 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.calendar', c) } - def interval_min_get(self, cr, uid, id, dt_from, hours,resource=None): + def interval_min_get(self, cr, uid, id, dt_from, hours,resource=False): + resource_cal_leaves = self.pool.get('resource.calendar.leaves') dt_leave = [] if not id: return [(dt_from-mx.DateTime.RelativeDateTime(hours=int(hours)*3), dt_from)] - if resource: - resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,['|',('resource_id','=',resource.id),('resource_id','=',False)]) - else: - resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,[('resource_id','=',False)]) - res_leaves = self.pool.get('resource.calendar.leaves').read(cr,uid,resource_leave_ids,['date_from','date_to']) + resource_leave_ids = resource_cal_leaves.search(cr,uid,[('calendar_id','=',id),'|',('resource_id','=',False),('resource_id','=',resource)]) + res_leaves = resource_cal_leaves.read(cr,uid,resource_leave_ids,['date_from','date_to']) for leave in res_leaves: dtf = mx.DateTime.strptime(leave['date_from'],'%Y-%m-%d %H:%M:%S') dtt = mx.DateTime.strptime(leave['date_to'],'%Y-%m-%d %H:%M:%S') @@ -85,21 +83,20 @@ class resource_calendar(osv.osv): result.reverse() return result - def interval_get(self, cr, uid, id, dt_from, hours, resource=None, byday=True): + def interval_get(self, cr, uid, id, dt_from, hours, resource=False, byday=True): + resource_cal_leaves = self.pool.get('resource.calendar.leaves') dt_leave = [] if not id: return [(dt_from,dt_from+mx.DateTime.RelativeDateTime(hours=int(hours)*3))] - if resource: - resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,['|',('resource_id','=',resource.id),('resource_id','=',False) ]) - else: - resource_leave_ids = self.pool.get('resource.calendar.leaves').search(cr,uid,[('resource_id','=',False)]) - res_leaves = self.pool.get('resource.calendar.leaves').read(cr,uid,resource_leave_ids,['date_from','date_to']) + resource_leave_ids = resource_cal_leaves.search(cr,uid,[('calendar_id','=',id),'|',('resource_id','=',False),('resource_id','=',resource)]) + res_leaves = resource_cal_leaves.read(cr,uid,resource_leave_ids,['date_from','date_to']) for leave in res_leaves: dtf = mx.DateTime.strptime(leave['date_from'],'%Y-%m-%d %H:%M:%S') dtt = mx.DateTime.strptime(leave['date_to'],'%Y-%m-%d %H:%M:%S') no = dtt - dtf [dt_leave.append((dtf + mx.DateTime.RelativeDateTime(days=x)).strftime('%Y-%m-%d')) for x in range(int(no.days + 1))] dt_leave.sort() + print 'dtLevae',dt_leave todo = hours cycle = 0 result = [] @@ -166,6 +163,18 @@ class resource_resource(osv.osv): 'active' : lambda *a: True, 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'resource.resource', c) } + + def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): + if context is None: + context = {} + + if context.get('project_id',False): + project_pool = self.pool.get('project.project') + project_rec = project_pool.browse(cr,uid,context['project_id']) + user_ids = [user_id.id for user_id in project_rec.members] + args.append(('user_id','in',user_ids)) + + return super(resource_resource, self).search(cr, uid, args, offset, limit,order, context, count) resource_resource() class resource_calendar_leaves(osv.osv): @@ -189,5 +198,14 @@ class resource_calendar_leaves(osv.osv): _constraints = [ (check_dates, 'Error! leave start-date must be lower then leave end-date.', ['date_from', 'date_to']) ] + + def onchange_resource(self,cr,uid,ids,resource): + result = {} + if resource: + resource_pool = self.pool.get('resource.resource') + result['calendar_id'] = resource_pool.browse(cr,uid,resource).calendar_id.id + return {'value':result} + return {'value':{'calendar_id':[]}} + resource_calendar_leaves() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/resource/resource_view.xml b/addons/resource/resource_view.xml index 783f9c28bf2..bce5d2f8807 100755 --- a/addons/resource/resource_view.xml +++ b/addons/resource/resource_view.xml @@ -61,7 +61,6 @@ - @@ -135,7 +134,7 @@ - + -- cgit v1.2.3