From 73dd49b96ea6729266f17eed5b005e1aa1313324 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Tue, 4 Jan 2011 15:32:05 +0530 Subject: [IMP] Project_long_term : Refector Code of The Schduling of Phases, Resetup Frame work with Faces lib bzr revid: jam@tinyerp.com-20110104100205-m5pu0cut6qebm91t --- addons/project_long_term/project_long_term.py | 176 +++++++++++++++++--------- 1 file changed, 115 insertions(+), 61 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 45d75b16b05..7adbf0273cc 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -25,6 +25,9 @@ from tools.translate import _ from osv import fields, osv from resource.faces import task as Task import operator +from new import classobj +import types +import new class project_phase(osv.osv): _name = "project.phase" @@ -226,84 +229,128 @@ class project_phase(osv.osv): res[phase.id] = resource_objs return res - def generate_schedule(self, cr, uid, ids, start_date=False, calendar_id=False, context=None): - """ - Schedule phase with the start date till all the next phases are completed. - @param: start_date (datetime.datetime) : start date for the phase. It would be either Start date of phase or start date of project or system current date - @param: calendar_id : working calendar of the project - """ + def generate_phase(self, cr, uid, ids, f, parent=False, context=None): if context is None: context = {} + phase_ids = [] resource_pool = self.pool.get('resource.resource') data_pool = self.pool.get('ir.model.data') resource_allocation_pool = self.pool.get('project.resource.allocation') uom_pool = self.pool.get('product.uom') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') - for phase in self.browse(cr, uid, ids, context=context): - if not phase.responsible_id: - raise osv.except_osv(_('No responsible person assigned !'),_("You must assign a responsible person for phase '%s' !") % (phase.name,)) - - if not start_date: - start_date = phase.project_id.date_start or phase.date_start or datetime.now().strftime("%Y-%m-%d") - start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + for phase in self.browse(cr, uid, ids, context=context)[::-1]: phase_resource_obj = self.generate_resources(cr, uid, [phase.id], context=context)[phase.id] avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) if not phase_resource_obj: #TOCHECK: why need this ? avg_days = avg_days - 1 duration = str(avg_days) + 'd' # Create a new project for each phase - def Project(): - # If project has working calendar then that - # else the default one would be considered - start = start_date - minimum_time_unit = 1 - resource = phase_resource_obj - working_hours_per_day = 24 - vacation = [] - if calendar_id: - working_hours_per_day = 8 #TODO: it should be come from calendars - vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id)) - working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) - def phase(): - effort = duration - - project = Task.BalancedProject(Project) - - s_date = project.phase.start.to_datetime() - e_date = project.phase.end.to_datetime() + s = ''' + def Phase_%s(): + effort = \'%s\' + resource = %s +'''%(phase.id, duration, phase_resource_obj) + if parent: + start = 'up.Phase_%s.end' % (parent.id) + s += ''' + start = %s +'''%(start) + f += s + '\n' + phase_ids.append(phase.id) + # Recursive call till all the next phases scheduled + for next_phase in phase.next_phase_ids: + if next_phase.state in ['draft', 'open', 'pending']: + rf, rphase_ids = self.generate_phase(cr, uid, [next_phase.id], f = '', parent=phase, context=context) + f += rf +'\n' + phase_ids += rphase_ids + else: + continue + return f, phase_ids + + def generate_schedule(self, cr, uid, root_phase, start_date=False, calendar_id=False, context=None): + """ + Schedule phase with the start date till all the next phases are completed. + @param: start_date (datetime.datetime) : start date for the phase. It would be either Start date of phase or start date of project or system current date + @param: calendar_id : working calendar of the project + """ + func_str = '' + if context is None: + context = {} + resource_pool = self.pool.get('resource.resource') + data_pool = self.pool.get('ir.model.data') + resource_allocation_pool = self.pool.get('project.resource.allocation') + uom_pool = self.pool.get('product.uom') + data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') + + + if not start_date: + start_date = root_phase.project_id.date_start or root_phase.date_start or datetime.now().strftime("%Y-%m-%d") + start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + + start = start_date + minimum_time_unit = 1 + working_hours_per_day = 24 + working_days_per_week = 7 + working_days_per_month = 30 + working_days_per_year = 365 + + vacation = [] + if calendar_id: + working_hours_per_day = 8 #TODO: it should be come from calendars + working_days_per_week = 5 + working_days_per_month = 20 + working_days_per_year = 200 + vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id)) + working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) + # Create a new project for each phase + func_str += ''' +def Project_%d(): + # If project has working calendar then that + # else the default one would be considered + start = \'%s\' + minimum_time_unit = %s + working_hours_per_day = %s + working_days_per_week = %s + working_days_per_month = %s + working_days_per_year = %s + vacation = %s + working_days = %s +'''%(root_phase.project_id.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) + phases, phase_ids = self.generate_phase(cr, uid, [root_phase.id], func_str, context=context) + exec(phases) + Project = eval('Project_%d' % root_phase.project_id.id) + project = Task.BalancedProject(Project) + for phase_id in phase_ids: + phase = eval("project.Phase_%d" % phase_id) + start_date = phase.start.to_datetime() + end_date = phase.end.to_datetime() + print start_date, end_date # Recalculate date_start and date_end # according to constraints on date start and date end on phase - if phase.constraint_date_start and str(s_date) < phase.constraint_date_start: - start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') - else: - start_date = s_date - if phase.constraint_date_end and str(e_date) > phase.constraint_date_end: - end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') - date_start = phase.constraint_date_end - else: - end_date = e_date - date_start = end_date - # Write the calculated dates back - ctx = context.copy() - ctx.update({'scheduler': True}) - self.write(cr, uid, [phase.id], { +# if phase.constraint_date_start and str(s_date) < phase.constraint_date_start: +# start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') +# else: +# start_date = s_date +# if phase.constraint_date_end and str(e_date) > phase.constraint_date_end: +# end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') +# date_start = phase.constraint_date_end +# else: +# end_date = e_date +# date_start = end_date +# # Write the calculated dates back +# ctx = context.copy() +# ctx.update({'scheduler': True}) + self.write(cr, uid, [phase_id], { 'date_start': start_date.strftime('%Y-%m-%d'), 'date_end': end_date.strftime('%Y-%m-%d') - }, context=ctx) + }, context=context) # write dates into Resources Allocation - for resource in phase.resource_ids: - resource_allocation_pool.write(cr, uid, [resource.id], { - 'date_start': start_date.strftime('%Y-%m-%d'), - 'date_end': end_date.strftime('%Y-%m-%d') - }, context=ctx) - # Recursive call till all the next phases scheduled - for next_phase in phase.next_phase_ids: - if next_phase.state in ['draft', 'open', 'pending']: - id_cal = next_phase.project_id.resource_calendar_id and next_phase.project_id.resource_calendar_id.id or False - self.generate_schedule(cr, uid, [next_phase.id], date_start+timedelta(days=1), id_cal, context=context) - else: - continue - return True +# for resource in phase.resource_ids: +# resource_allocation_pool.write(cr, uid, [resource.id], { +# 'date_start': start_date.strftime('%Y-%m-%d'), +# 'date_end': end_date.strftime('%Y-%m-%d') +# }, context=context) +# # Recursive call till all the next phases scheduled def schedule_tasks(self, cr, uid, ids, context=None): """ @@ -395,7 +442,8 @@ class project(osv.osv): ]) calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False start_date = False - phase_pool.generate_schedule(cr, uid, phase_ids, start_date, calendar_id, context=context) + for phase in phase_pool.browse(cr, uid, phase_ids, context=context): + phase_pool.generate_schedule(cr, uid, phase, start_date, calendar_id, context=context) return True def schedule_tasks(self, cr, uid, ids, context=None): @@ -489,9 +537,15 @@ class project_task(osv.osv): raise osv.except_osv(_('Error'), _('Resources should be allocated to your phases and Members should be assigned to your Project!')) minimum_time_unit = 1 working_hours_per_day = 24 + working_days_per_week = 7 + working_days_per_month = 30 + working_days_per_year = 365 vacation = [] if calendar_id: working_hours_per_day = 8 #TODO: it should be come from calendars + working_days_per_week = 5 + working_days_per_month = 20 + working_days_per_year = 200 vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context)) working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) # Dynamic creation of tasks -- cgit v1.2.3 From 643b28b9e5992a23a98fdec92cbdae81571901b3 Mon Sep 17 00:00:00 2001 From: "Sbh (OpenERP)" Date: Tue, 4 Jan 2011 16:14:12 +0530 Subject: [IMP] account: rename Analytic entries to Analytic items ,[project_long_term: Improve tooltips bzr revid: sbh@tinyerp.com-20110104104412-b72ptzxzr3py1k9x --- addons/project_long_term/project_long_term.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 45d75b16b05..da0978d3535 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -105,7 +105,7 @@ class project_phase(osv.osv): _columns = { 'name': fields.char("Name", size=64, required=True), - 'date_start': fields.date('Start Date', help="It's computed according to the phases order : the start date of the 1st phase is set by you while the other start dates depend on the end date of their previous phases", states={'done':[('readonly',True)], 'cancelled':[('readonly',True)]}), + 'date_start': fields.date('Start Date', help="It's computed by the scheduler according the project date or the end date of the previous phase.", states={'done':[('readonly',True)], 'cancelled':[('readonly',True)]}), 'date_end': fields.date('End Date', help=" It's computed by the scheduler according to the start date and the duration.", states={'done':[('readonly',True)], 'cancelled':[('readonly',True)]}), 'constraint_date_start': fields.date('Minimum Start Date', help='force the phase to start after this date', states={'done':[('readonly',True)], 'cancelled':[('readonly',True)]}), 'constraint_date_end': fields.date('Deadline', help='force the phase to finish before this date', states={'done':[('readonly',True)], 'cancelled':[('readonly',True)]}), -- cgit v1.2.3 From 926e3de1e2ba53834bb7a006ef48b5161d9c1918 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Tue, 4 Jan 2011 18:45:11 +0530 Subject: [IMP] Project_long_term : Refector Code of The Schduling of Phases, Resetup Frame work with Faces lib bzr revid: jam@tinyerp.com-20110104131511-flc8m5kmc86smd03 --- addons/project_long_term/project_long_term.py | 41 ++++++++++++++++++++------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 7adbf0273cc..23ddb41c53e 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -23,7 +23,7 @@ from datetime import datetime, timedelta from dateutil.relativedelta import relativedelta from tools.translate import _ from osv import fields, osv -from resource.faces import task as Task +from resource.faces import task as Task import operator from new import classobj import types @@ -219,13 +219,11 @@ class project_phase(osv.osv): """ Return a list of Resource Class objects for the resources allocated to the phase. """ + res = {} resource_pool = self.pool.get('resource.resource') for phase in self.browse(cr, uid, ids, context=context): - user_ids = map(lambda x:x.resource_id.user_id.id, phase.resource_ids) - project = phase.project_id - calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False - resource_objs = resource_pool.generate_resources(cr, uid, user_ids, calendar_id, context=context) + resource_objs = map(lambda x:x.resource_id.name, phase.resource_ids) res[phase.id] = resource_objs return res @@ -239,17 +237,17 @@ class project_phase(osv.osv): uom_pool = self.pool.get('product.uom') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') for phase in self.browse(cr, uid, ids, context=context)[::-1]: - phase_resource_obj = self.generate_resources(cr, uid, [phase.id], context=context)[phase.id] avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) - if not phase_resource_obj: #TOCHECK: why need this ? - avg_days = avg_days - 1 duration = str(avg_days) + 'd' # Create a new project for each phase + str_resource = ('%s,'*len(phase.resource_ids))[:-1] + str_vals = str_resource % tuple(map(lambda x: 'Resource_%s'%x.resource_id.id, phase.resource_ids)) + # Phases Defination for the Project s = ''' def Phase_%s(): effort = \'%s\' resource = %s -'''%(phase.id, duration, phase_resource_obj) +'''%(phase.id, duration, str_vals or False) if parent: start = 'up.Phase_%s.end' % (parent.id) s += ''' @@ -302,8 +300,22 @@ class project_phase(osv.osv): working_days_per_year = 200 vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id)) working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) + + #Creating resources using the member of the Project + u_ids = [i.id for i in root_phase.project_id.members] + resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context) + cls_str = '' + # Creating Resources for the Project + for key, vals in resource_objs.items(): + cls_str +=''' + class Resource_%s(Resource): + vacation = %s + efficiency = %s +'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) + # Create a new project for each phase func_str += ''' + def Project_%d(): # If project has working calendar then that # else the default one would be considered @@ -315,16 +327,25 @@ def Project_%d(): working_days_per_year = %s vacation = %s working_days = %s + from resource.faces import Resource '''%(root_phase.project_id.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) + func_str += cls_str phases, phase_ids = self.generate_phase(cr, uid, [root_phase.id], func_str, context=context) + #Temp File to test the Code for the Allocation +# fn = '/home/tiny/Desktop/plt.py' +# fp = open(fn, 'w') +# fp.writelines(phases) +# fp.close() + # Allocating Memory for the required Project and Pahses and Resources exec(phases) Project = eval('Project_%d' % root_phase.project_id.id) project = Task.BalancedProject(Project) + for phase_id in phase_ids: phase = eval("project.Phase_%d" % phase_id) start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() - print start_date, end_date +# print phase_id,"\n\n****Phases *********", phase.resource # Recalculate date_start and date_end # according to constraints on date start and date end on phase # if phase.constraint_date_start and str(s_date) < phase.constraint_date_start: -- cgit v1.2.3 From b1fa3dee7d5a7f3c439375f934d6f7762e9ffd02 Mon Sep 17 00:00:00 2001 From: "atp (Open ERP)" Date: Tue, 4 Jan 2011 19:05:15 +0530 Subject: [FIX]: Fix constrain date problem of project phase. bzr revid: atp@tinyerp.co.in-20110104133515-3b2ptv3jf0neq75c --- addons/project_long_term/project_long_term.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index da0978d3535..da4b256f82f 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -220,6 +220,7 @@ class project_phase(osv.osv): resource_pool = self.pool.get('resource.resource') for phase in self.browse(cr, uid, ids, context=context): user_ids = map(lambda x:x.resource_id.user_id.id, phase.resource_ids) + project = phase.project_id calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False resource_objs = resource_pool.generate_resources(cr, uid, user_ids, calendar_id, context=context) @@ -240,12 +241,13 @@ class project_phase(osv.osv): uom_pool = self.pool.get('product.uom') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') for phase in self.browse(cr, uid, ids, context=context): + if not phase.previous_phase_ids: + start_date = False if not phase.responsible_id: raise osv.except_osv(_('No responsible person assigned !'),_("You must assign a responsible person for phase '%s' !") % (phase.name,)) - if not start_date: start_date = phase.project_id.date_start or phase.date_start or datetime.now().strftime("%Y-%m-%d") - start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") phase_resource_obj = self.generate_resources(cr, uid, [phase.id], context=context)[phase.id] avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) if not phase_resource_obj: #TOCHECK: why need this ? @@ -277,6 +279,7 @@ class project_phase(osv.osv): start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') else: start_date = s_date + if phase.constraint_date_end and str(e_date) > phase.constraint_date_end: end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') date_start = phase.constraint_date_end -- cgit v1.2.3 From 344911ad414e7977e17560bee59ddc24eb6fedba Mon Sep 17 00:00:00 2001 From: "Harry (OpenERP)" Date: Wed, 5 Jan 2011 14:35:52 +0530 Subject: [IMP] project_long_term: refector scheduling of phase/task process to make compatable with faces lib bzr revid: hmo@tinyerp.com-20110105090552-s65bdri5j4nr09qh --- addons/project_long_term/project_long_term.py | 543 +++++++++++++++----------- 1 file changed, 314 insertions(+), 229 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 7a23586ffbc..18bc5495caf 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -215,18 +215,6 @@ class project_phase(osv.osv): self.write(cr, uid, ids, {'state': 'done'}) return True - def generate_resources(self, cr, uid, ids, context=None): - """ - Return a list of Resource Class objects for the resources allocated to the phase. - """ - - res = {} - resource_pool = self.pool.get('resource.resource') - for phase in self.browse(cr, uid, ids, context=context): - resource_objs = map(lambda x:x.resource_id.name, phase.resource_ids) - res[phase.id] = resource_objs - return res - def generate_phase(self, cr, uid, ids, f, parent=False, context=None): if context is None: context = {} @@ -236,7 +224,7 @@ class project_phase(osv.osv): resource_allocation_pool = self.pool.get('project.resource.allocation') uom_pool = self.pool.get('product.uom') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') - for phase in self.browse(cr, uid, ids, context=context)[::-1]: + for phase in self.browse(cr, uid, ids, context=context): avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) duration = str(avg_days) + 'd' # Create a new project for each phase @@ -250,7 +238,10 @@ class project_phase(osv.osv): '''%(phase.id, duration, str_vals or False) if parent: start = 'up.Phase_%s.end' % (parent.id) - s += ''' + else: + start = phase.project_id.date_start or phase.date_start + #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") + s += ''' start = %s '''%(start) f += s + '\n' @@ -265,114 +256,7 @@ class project_phase(osv.osv): continue return f, phase_ids - def generate_schedule(self, cr, uid, root_phase, start_date=False, calendar_id=False, context=None): - """ - Schedule phase with the start date till all the next phases are completed. - @param: start_date (datetime.datetime) : start date for the phase. It would be either Start date of phase or start date of project or system current date - @param: calendar_id : working calendar of the project - """ - func_str = '' - if context is None: - context = {} - resource_pool = self.pool.get('resource.resource') - data_pool = self.pool.get('ir.model.data') - resource_allocation_pool = self.pool.get('project.resource.allocation') - uom_pool = self.pool.get('product.uom') - data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') - - - if not start_date: - start_date = root_phase.project_id.date_start or root_phase.date_start or datetime.now().strftime("%Y-%m-%d") - start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") - - start = start_date - minimum_time_unit = 1 - working_hours_per_day = 24 - working_days_per_week = 7 - working_days_per_month = 30 - working_days_per_year = 365 - - vacation = [] - if calendar_id: - working_hours_per_day = 8 #TODO: it should be come from calendars - working_days_per_week = 5 - working_days_per_month = 20 - working_days_per_year = 200 - vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id)) - working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) - - #Creating resources using the member of the Project - u_ids = [i.id for i in root_phase.project_id.members] - resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context) - cls_str = '' - # Creating Resources for the Project - for key, vals in resource_objs.items(): - cls_str +=''' - class Resource_%s(Resource): - vacation = %s - efficiency = %s -'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) - - # Create a new project for each phase - func_str += ''' - -def Project_%d(): - # If project has working calendar then that - # else the default one would be considered - start = \'%s\' - minimum_time_unit = %s - working_hours_per_day = %s - working_days_per_week = %s - working_days_per_month = %s - working_days_per_year = %s - vacation = %s - working_days = %s - from resource.faces import Resource -'''%(root_phase.project_id.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) - func_str += cls_str - phases, phase_ids = self.generate_phase(cr, uid, [root_phase.id], func_str, context=context) - #Temp File to test the Code for the Allocation -# fn = '/home/tiny/Desktop/plt.py' -# fp = open(fn, 'w') -# fp.writelines(phases) -# fp.close() - # Allocating Memory for the required Project and Pahses and Resources - exec(phases) - Project = eval('Project_%d' % root_phase.project_id.id) - project = Task.BalancedProject(Project) - - for phase_id in phase_ids: - phase = eval("project.Phase_%d" % phase_id) - start_date = phase.start.to_datetime() - end_date = phase.end.to_datetime() -# print phase_id,"\n\n****Phases *********", phase.resource - # Recalculate date_start and date_end - # according to constraints on date start and date end on phase - -# if phase.constraint_date_start and str(s_date) < phase.constraint_date_start: -# start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') -# else: -# start_date = s_date -# if phase.constraint_date_end and str(e_date) > phase.constraint_date_end: -# end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') -# date_start = phase.constraint_date_end -# else: -# end_date = e_date -# date_start = end_date -# # Write the calculated dates back -# ctx = context.copy() -# ctx.update({'scheduler': True}) - self.write(cr, uid, [phase_id], { - 'date_start': start_date.strftime('%Y-%m-%d'), - 'date_end': end_date.strftime('%Y-%m-%d') - }, context=context) - # write dates into Resources Allocation -# for resource in phase.resource_ids: -# resource_allocation_pool.write(cr, uid, [resource.id], { -# 'date_start': start_date.strftime('%Y-%m-%d'), -# 'date_end': end_date.strftime('%Y-%m-%d') -# }, context=context) -# # Recursive call till all the next phases scheduled + def schedule_tasks(self, cr, uid, ids, context=None): """ @@ -401,6 +285,102 @@ def Project_%d(): else: return_msg["warning"] = return_msg["warning"] + "\n" + warning_msg return return_msg + + def schedule_tasks(self, cr, uid, ids, context=None): + """ + Schedule tasks base on faces lib + """ + if context is None: + context = {} + if type(ids) in (long, int,): + ids = [ids] + task_pool = self.pool.get('project.task') + resource_pool = self.pool.get('resource.resource') + data_pool = self.pool.get('ir.model.data') + resource_allocation_pool = self.pool.get('project.resource.allocation') + + for phase in self.browse(cr, uid, ids, context=context): + task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)), + ('state', 'in', ['draft', 'open', 'pending']) + ], order='sequence') + project = phase.project_id + calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False + start_date = project.date_start + #Creating resources using the member of the Project + u_ids = [i.id for i in project.members] + resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context) + start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + func_str = '' + start = start_date + minimum_time_unit = 1 + # default values + working_hours_per_day = 24 + working_days_per_week = 7 + working_days_per_month = 30 + working_days_per_year = 365 + + vacation = [] + if calendar_id: + working_hours_per_day = 8 #TODO: it should be come from calendars + working_days_per_week = 5 + working_days_per_month = 20 + working_days_per_year = 200 + vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context)) + + working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) + + cls_str = '' + # Creating Resources for the Project + for key, vals in resource_objs.items(): + cls_str +=''' + class Resource_%s(Resource): + vacation = %s + efficiency = %s +'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) + + # Create a new project for each phase + func_str += ''' +def Phase_%d(): + from resource.faces import Resource + start = \'%s\' + minimum_time_unit = %s + working_hours_per_day = %s + working_days_per_week = %s + working_days_per_month = %s + working_days_per_year = %s + vacation = %s + working_days = %s +'''%(phase.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) + func_str += cls_str + parent = False + task_ids = [] + for task in task_pool.browse(cr, uid, task_ids, context=context): + func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, context=context) + if not parent: + parent = task + task_ids.append(task.id) + + #Temp File to test the Code for the Allocation + #fn = '/home/hmo/Desktop/plt.py' + #fp = open(fn, 'w') + #fp.writelines(func_str) + #fp.close() + + # Allocating Memory for the required Project and Pahses and Resources + exec(func_str) + Phase = eval('Phase_%d' % phase.id) + phase = Task.BalancedProject(Phase) + + for task_id in task_ids: + task = eval("phase.Task_%d" % task_id) + start_date = task.start.to_datetime() + end_date = task.end.to_datetime() + + task_pool.write(cr, uid, [task_id], { + 'date_start': start_date.strftime('%Y-%m-%d'), + 'date_end': end_date.strftime('%Y-%m-%d') + }, context=context) + return True project_phase() class project_resource_allocation(osv.osv): @@ -452,54 +432,214 @@ class project(osv.osv): def schedule_phases(self, cr, uid, ids, context=None): """ - Schedule the phases. + Schedule phase base on faces lib """ + if context is None: + context = {} if type(ids) in (long, int,): ids = [ids] phase_pool = self.pool.get('project.phase') + resource_pool = self.pool.get('resource.resource') + data_pool = self.pool.get('ir.model.data') + resource_allocation_pool = self.pool.get('project.resource.allocation') + uom_pool = self.pool.get('product.uom') + data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') + for project in self.browse(cr, uid, ids, context=context): - phase_ids = phase_pool.search(cr, uid, [('project_id', '=', project.id), + root_phase_ids = phase_pool.search(cr, uid, [('project_id', '=', project.id), ('state', 'in', ['draft', 'open', 'pending']), ('previous_phase_ids', '=', False) ]) calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False - start_date = False - for phase in phase_pool.browse(cr, uid, phase_ids, context=context): - phase_pool.generate_schedule(cr, uid, phase, start_date, calendar_id, context=context) - return True + start_date = project.date_start + #if start_date: + # start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + #Creating resources using the member of the Project + u_ids = [i.id for i in project.members] + resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context) + func_str = '' + start = start_date + minimum_time_unit = 1 + # default values + working_hours_per_day = 24 + working_days_per_week = 7 + working_days_per_month = 30 + working_days_per_year = 365 + + vacation = [] + if calendar_id: + working_hours_per_day = 8 #TODO: it should be come from calendars + working_days_per_week = 5 + working_days_per_month = 20 + working_days_per_year = 200 + vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context)) + + working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) + + + cls_str = '' + # Creating Resources for the Project + for key, vals in resource_objs.items(): + cls_str +=''' + class Resource_%s(Resource): + vacation = %s + efficiency = %s +'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) + + # Create a new project for each phase + func_str += ''' +def Project_%d(): + from resource.faces import Resource + start = \'%s\' + minimum_time_unit = %s + working_hours_per_day = %s + working_days_per_week = %s + working_days_per_month = %s + working_days_per_year = %s + vacation = %s + working_days = %s +'''%(project.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) + func_str += cls_str + phase_ids = [] + for root_phase in phase_pool.browse(cr, uid, root_phase_ids, context=context): + phases, child_phase_ids = phase_pool.generate_phase(cr, uid, [root_phase.id], '', context=context) + func_str += phases + phase_ids += child_phase_ids + #Temp File to test the Code for the Allocation + #fn = '/home/hmo/Desktop/plt.py' + #fp = open(fn, 'w') + #fp.writelines(func_str) + #fp.close() + + # Allocating Memory for the required Project and Pahses and Resources + exec(func_str) + Project = eval('Project_%d' % project.id) + project = Task.BalancedProject(Project) + + for phase_id in phase_ids: + phase = eval("project.Phase_%d" % phase_id) + start_date = phase.start.to_datetime() + end_date = phase.end.to_datetime() + + # Recalculate date_start and date_end + # according to constraints on date start and date end on phase + + #if phase.constraint_date_start and str(s_date) < phase.constraint_date_start: + # start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') + #else: + # start_date = s_date + #if phase.constraint_date_end and str(e_date) > phase.constraint_date_end: + # end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') + # date_start = phase.constraint_date_end + #else: + # end_date = e_date + # date_start = end_date + + # Write the calculated dates back + #ctx = context.copy() + #ctx.update({'scheduler': True}) + phase_pool.write(cr, uid, [phase_id], { + 'date_start': start_date.strftime('%Y-%m-%d'), + 'date_end': end_date.strftime('%Y-%m-%d') + }, context=context) + return True def schedule_tasks(self, cr, uid, ids, context=None): """ - Schedule the tasks according to resource available and priority. + Schedule task base on faces lib """ + if context is None: + context = {} if type(ids) in (long, int,): ids = [ids] - user_pool = self.pool.get('res.users') task_pool = self.pool.get('project.task') resource_pool = self.pool.get('resource.resource') - resources_list = self.generate_members(cr, uid, ids, context=context) - return_msg = {} + data_pool = self.pool.get('ir.model.data') + resource_allocation_pool = self.pool.get('project.resource.allocation') + uom_pool = self.pool.get('product.uom') + data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') + for project in self.browse(cr, uid, ids, context=context): - start_date = project.date_start - if not start_date: - start_date = datetime.now().strftime("%Y-%m-%d") - resources = resources_list.get(project.id, []) - calendar_id = project.resource_calendar_id.id task_ids = task_pool.search(cr, uid, [('project_id', '=', project.id), ('state', 'in', ['draft', 'open', 'pending']) - ]) - - - if task_ids: - task_pool.generate_schedule(cr, uid, task_ids, resources, calendar_id, start_date, context=context) - else: - warning_msg = _("No tasks to compute for Project '%s'.") % (project.name) - if "warning" not in return_msg: - return_msg["warning"] = warning_msg - else: - return_msg["warning"] = return_msg["warning"] + "\n" + warning_msg + ], order='sequence') + calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False + start_date = project.date_start + #Creating resources using the member of the Project + u_ids = [i.id for i in project.members] + resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context) + start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + func_str = '' + start = start_date + minimum_time_unit = 1 + # default values + working_hours_per_day = 24 + working_days_per_week = 7 + working_days_per_month = 30 + working_days_per_year = 365 + + vacation = [] + if calendar_id: + working_hours_per_day = 8 #TODO: it should be come from calendars + working_days_per_week = 5 + working_days_per_month = 20 + working_days_per_year = 200 + vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context)) - return return_msg + working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) + + cls_str = '' + # Creating Resources for the Project + for key, vals in resource_objs.items(): + cls_str +=''' + class Resource_%s(Resource): + vacation = %s + efficiency = %s +'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) + + # Create a new project for each phase + func_str += ''' +def Project_%d(): + from resource.faces import Resource + start = \'%s\' + minimum_time_unit = %s + working_hours_per_day = %s + working_days_per_week = %s + working_days_per_month = %s + working_days_per_year = %s + vacation = %s + working_days = %s +'''%(project.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) + func_str += cls_str + parent = False + task_ids = [] + for task in task_pool.browse(cr, uid, task_ids, context=context): + func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, context=context) + if not parent: + parent = task + task_ids.append(task.id) + + #Temp File to test the Code for the Allocation + fn = '/home/hmo/Desktop/plt.py' + fp = open(fn, 'w') + fp.writelines(func_str) + fp.close() + + # Allocating Memory for the required Project and Pahses and Resources + exec(func_str) + Project = eval('Project_%d' % project.id) + project = Task.BalancedProject(Project) + + for task_id in task_ids: + task = eval("project.Task_%d" % task_id) + start_date = task.start.to_datetime() + end_date = task.end.to_datetime() + + task_pool.write(cr, uid, [task_id], { + 'date_start': start_date.strftime('%Y-%m-%d'), + 'date_end': end_date.strftime('%Y-%m-%d') + }, context=context) + return True project() @@ -523,87 +663,32 @@ class project_task(osv.osv): 'phase_id': fields.many2one('project.phase', 'Project Phase'), } - def generate_schedule(self, cr, uid, ids, resources, calendar_id, start_date, context=None): - """ - Schedule the tasks according to resource available and priority. - """ - resource_pool = self.pool.get('resource.resource') - if not ids: - return False + def generate_task(self, cr, uid, task_id, parent=False, context=None): if context is None: context = {} - user_pool = self.pool.get('res.users') - project_pool = self.pool.get('project.project') - priority_dict = {'0': 1000, '1': 800, '2': 500, '3': 300, '4': 100} - # Create dynamic no of tasks with the resource specified - def create_tasks(task_number, eff, priorty=500, obj=False): - def task(): - """ - task is a dynamic method! - """ - effort = eff - if obj: - resource = obj - priority = priorty - task.__doc__ = "TaskNO%d" %task_number - task.__name__ = "task%d" %task_number - return task - - # Create a 'Faces' project with all the tasks and resources - def Project(): - title = "Project" - start = datetime.strftime(datetime.strptime(start_date, "%Y-%m-%d"), "%Y-%m-%d %H:%M") - try: - resource = reduce(operator.or_, resources) - except: - raise osv.except_osv(_('Error'), _('Resources should be allocated to your phases and Members should be assigned to your Project!')) - minimum_time_unit = 1 - working_hours_per_day = 24 - working_days_per_week = 7 - working_days_per_month = 30 - working_days_per_year = 365 - vacation = [] - if calendar_id: - working_hours_per_day = 8 #TODO: it should be come from calendars - working_days_per_week = 5 - working_days_per_month = 20 - working_days_per_year = 200 - vacation = tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context)) - working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) - # Dynamic creation of tasks - task_number = 0 - for openobect_task in self.browse(cr, uid, ids, context=context): - hours = str(openobect_task.planned_hours )+ 'H' - if openobect_task.priority in priority_dict.keys(): - priorty = priority_dict[openobect_task.priority] - real_resource = False - if openobect_task.user_id: - for task_resource in resources: - if task_resource.__name__ == task_resource: - real_resource = task_resource - break - - task = create_tasks(task_number, hours, priorty, real_resource) - task_number += 1 - - - face_projects = Task.BalancedProject(Project) - loop_no = 0 - # Write back the computed dates - for face_project in face_projects: - s_date = face_project.start.to_datetime() - e_date = face_project.end.to_datetime() - if loop_no > 0: - ctx = context.copy() - ctx.update({'scheduler': True}) - user_id = user_pool.search(cr, uid, [('name', '=', face_project.booked_resource[0].__name__)]) - self.write(cr, uid, [ids[loop_no-1]], { - 'date_start': s_date.strftime('%Y-%m-%d %H:%M:%S'), - 'date_end': e_date.strftime('%Y-%m-%d %H:%M:%S'), - 'user_id': user_id[0] - }, context=ctx) - - loop_no += 1 - return True + resource_pool = self.pool.get('resource.resource') + resource_allocation_pool = self.pool.get('project.resource.allocation') + task = self.browse(cr, uid, task_id, context=context) + duration = str(task.planned_hours )+ 'H' + resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id)], context=context) + resource = False + if len(resource_ids): + resource = 'Resource_%s'%resource_ids[0] + # Phases Defination for the Project + s = ''' + def Task_%s(): + effort = \'%s\' + resource = %s +'''%(task.id, duration, resource) + if parent: + start = 'up.Task_%s.end' % (parent.id) + else: + start = task.project_id.date_start or task.date_start + #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") + s += ''' + start = %s +'''%(start) + s += '\n' + return s project_task() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: -- cgit v1.2.3 From a857948b4ebbd3162c836dcbf668db9702113937 Mon Sep 17 00:00:00 2001 From: "Sbh (OpenERP)" Date: Wed, 5 Jan 2011 14:52:34 +0530 Subject: project_long_term: comment the code bzr revid: sbh@tinyerp.com-20110105092234-qdcy1l0vlz6ufhet --- addons/project_long_term/project_long_term.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 18bc5495caf..ab08247851a 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -620,10 +620,10 @@ def Project_%d(): task_ids.append(task.id) #Temp File to test the Code for the Allocation - fn = '/home/hmo/Desktop/plt.py' - fp = open(fn, 'w') - fp.writelines(func_str) - fp.close() +# fn = '/home/hmo/Desktop/plt.py' +# fp = open(fn, 'w') +# fp.writelines(func_str) +# fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) -- cgit v1.2.3 From 5dbdff512bf33795bd5948b5dbe599140d06e33d Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Wed, 5 Jan 2011 15:26:17 +0530 Subject: [IMP] Project_long_term: Refactoring Scheduling Process. bzr revid: jam@tinyerp.com-20110105095617-bhat8tcnpqv2g5w3 --- addons/project_long_term/project_long_term.py | 130 +++++++++++++------------- 1 file changed, 63 insertions(+), 67 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 18bc5495caf..616d320ceef 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -223,6 +223,7 @@ class project_phase(osv.osv): data_pool = self.pool.get('ir.model.data') resource_allocation_pool = self.pool.get('project.resource.allocation') uom_pool = self.pool.get('product.uom') + task_pool = self.pool.get('project.task') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') for phase in self.browse(cr, uid, ids, context=context): avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) @@ -238,14 +239,30 @@ class project_phase(osv.osv): '''%(phase.id, duration, str_vals or False) if parent: start = 'up.Phase_%s.end' % (parent.id) + s += ''' + start = %s +'''%(start) else: start = phase.project_id.date_start or phase.date_start - #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") - s += ''' - start = %s + s += ''' + start = \"%s\" '''%(start) - f += s + '\n' + #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") + + phase_ids.append(phase.id) + parent = False + task_ids = [] + todo_task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)), + ('state', 'in', ['draft', 'open', 'pending']) + ], order='sequence') + for task in task_pool.browse(cr, uid, todo_task_ids, context=context): + s += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=False, context=context) + if not parent: + parent = task + task_ids.append(task.id) + + f += s + '\n' # Recursive call till all the next phases scheduled for next_phase in phase.next_phase_ids: if next_phase.state in ['draft', 'open', 'pending']: @@ -256,36 +273,6 @@ class project_phase(osv.osv): continue return f, phase_ids - - - def schedule_tasks(self, cr, uid, ids, context=None): - """ - Schedule the tasks according to resource available and priority. - """ - task_pool = self.pool.get('project.task') - resource_pool = self.pool.get('resource.resource') - resources_list = self.generate_resources(cr, uid, ids, context=context) - return_msg = {} - for phase in self.browse(cr, uid, ids, context=context): - start_date = phase.date_start - if not start_date and phase.project_id.date_start: - start_date = phase.project_id.date_start - if not start_date: - start_date = datetime.now().strftime("%Y-%m-%d") - resources = resources_list.get(phase.id, []) - calendar_id = phase.project_id.resource_calendar_id.id - task_ids = map(lambda x : x.id, (filter(lambda x : x.state in ['draft'] , phase.task_ids))) #reassign only task not yet started - if task_ids: - task_pool.generate_schedule(cr, uid, task_ids, resources, calendar_id, start_date, context=context) - - if not task_ids: - warning_msg = _("No tasks to compute for Phase '%s'.") % (phase.name) - if "warning" not in return_msg: - return_msg["warning"] = warning_msg - else: - return_msg["warning"] = return_msg["warning"] + "\n" + warning_msg - return return_msg - def schedule_tasks(self, cr, uid, ids, context=None): """ Schedule tasks base on faces lib @@ -300,9 +287,6 @@ class project_phase(osv.osv): resource_allocation_pool = self.pool.get('project.resource.allocation') for phase in self.browse(cr, uid, ids, context=context): - task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)), - ('state', 'in', ['draft', 'open', 'pending']) - ], order='sequence') project = phase.project_id calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False start_date = project.date_start @@ -354,17 +338,20 @@ def Phase_%d(): func_str += cls_str parent = False task_ids = [] - for task in task_pool.browse(cr, uid, task_ids, context=context): - func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, context=context) + todo_task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)), + ('state', 'in', ['draft', 'open', 'pending']) + ], order='sequence') + for task in task_pool.browse(cr, uid, todo_task_ids, context=context): + func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=True, context=context) if not parent: parent = task task_ids.append(task.id) #Temp File to test the Code for the Allocation - #fn = '/home/hmo/Desktop/plt.py' - #fp = open(fn, 'w') - #fp.writelines(func_str) - #fp.close() +# fn = '/home/hmo/Desktop/plt.py' +# fp = open(fn, 'w') +# fp.writelines(func_str) +# fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) @@ -476,7 +463,6 @@ class project(osv.osv): working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context) - cls_str = '' # Creating Resources for the Project for key, vals in resource_objs.items(): @@ -506,10 +492,10 @@ def Project_%d(): func_str += phases phase_ids += child_phase_ids #Temp File to test the Code for the Allocation - #fn = '/home/hmo/Desktop/plt.py' - #fp = open(fn, 'w') - #fp.writelines(func_str) - #fp.close() + fn = '/home/tiny/Desktop/plt.py' + fp = open(fn, 'w') + fp.writelines(func_str) + fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) @@ -520,7 +506,7 @@ def Project_%d(): phase = eval("project.Phase_%d" % phase_id) start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() - + # Recalculate date_start and date_end # according to constraints on date start and date end on phase @@ -560,9 +546,6 @@ def Project_%d(): data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') for project in self.browse(cr, uid, ids, context=context): - task_ids = task_pool.search(cr, uid, [('project_id', '=', project.id), - ('state', 'in', ['draft', 'open', 'pending']) - ], order='sequence') calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False start_date = project.date_start #Creating resources using the member of the Project @@ -613,17 +596,20 @@ def Project_%d(): func_str += cls_str parent = False task_ids = [] - for task in task_pool.browse(cr, uid, task_ids, context=context): - func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, context=context) + todo_task_ids = task_pool.search(cr, uid, [('project_id', '=', project.id), + ('state', 'in', ['draft', 'open', 'pending']) + ], order='sequence') + for task in task_pool.browse(cr, uid, todo_task_ids, context=context): + func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=True,context=context) if not parent: parent = task task_ids.append(task.id) #Temp File to test the Code for the Allocation - fn = '/home/hmo/Desktop/plt.py' - fp = open(fn, 'w') - fp.writelines(func_str) - fp.close() +# fn = '/home/tiny/Desktop/plt_1.py' +# fp = open(fn, 'w') +# fp.writelines(func_str) +# fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) @@ -663,7 +649,7 @@ class project_task(osv.osv): 'phase_id': fields.many2one('project.phase', 'Project Phase'), } - def generate_task(self, cr, uid, task_id, parent=False, context=None): + def generate_task(self, cr, uid, task_id, parent=False, flag=False, context=None): if context is None: context = {} resource_pool = self.pool.get('resource.resource') @@ -674,18 +660,28 @@ class project_task(osv.osv): resource = False if len(resource_ids): resource = 'Resource_%s'%resource_ids[0] - # Phases Defination for the Project - s = ''' + # Phases Defination for the Project + if not flag: + s = ''' + def Task_%s(): + effort = \'%s\' + resource = %s +'''%(task.id, duration, resource) + if parent: + start = 'up.Task_%s.end' % (parent.id) + s += ''' + start = %s +'''%(start) + #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") + else: + s = ''' def Task_%s(): effort = \'%s\' resource = %s '''%(task.id, duration, resource) - if parent: - start = 'up.Task_%s.end' % (parent.id) - else: - start = task.project_id.date_start or task.date_start - #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") - s += ''' + if parent: + start = 'up.Task_%s.end' % (parent.id) + s += ''' start = %s '''%(start) s += '\n' -- cgit v1.2.3 From 54aa8e6e2033858e4030ef51247079bda26cb447 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Wed, 5 Jan 2011 15:42:59 +0530 Subject: [IMP] Project_long_term: Refactoring Scheduling Process. bzr revid: jam@tinyerp.com-20110105101259-lmgth1kt56xsg5dq --- addons/project_long_term/project_long_term.py | 35 +++++++++++++++++---------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 616d320ceef..933b6540e90 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -234,9 +234,10 @@ class project_phase(osv.osv): # Phases Defination for the Project s = ''' def Phase_%s(): + title = \"%s\" effort = \'%s\' resource = %s -'''%(phase.id, duration, str_vals or False) +'''%(phase.id, phase.name, duration, str_vals or False) if parent: start = 'up.Phase_%s.end' % (parent.id) s += ''' @@ -318,14 +319,16 @@ class project_phase(osv.osv): for key, vals in resource_objs.items(): cls_str +=''' class Resource_%s(Resource): + title = \"%s\" vacation = %s efficiency = %s -'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) +'''%(key, vals.get('name',False), vals.get('vacation', False), vals.get('efficiency', False)) # Create a new project for each phase func_str += ''' def Phase_%d(): from resource.faces import Resource + title = \"%s\" start = \'%s\' minimum_time_unit = %s working_hours_per_day = %s @@ -334,7 +337,7 @@ def Phase_%d(): working_days_per_year = %s vacation = %s working_days = %s -'''%(phase.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) +'''%(phase.id, phase.name, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) func_str += cls_str parent = False task_ids = [] @@ -468,14 +471,16 @@ class project(osv.osv): for key, vals in resource_objs.items(): cls_str +=''' class Resource_%s(Resource): + title = \"%s\" vacation = %s efficiency = %s -'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) +'''%(key, vals.get('name',False), vals.get('vacation', False), vals.get('efficiency', False)) # Create a new project for each phase func_str += ''' def Project_%d(): from resource.faces import Resource + title = \"%s\" start = \'%s\' minimum_time_unit = %s working_hours_per_day = %s @@ -484,7 +489,7 @@ def Project_%d(): working_days_per_year = %s vacation = %s working_days = %s -'''%(project.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) +'''%(project.id, project.name, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) func_str += cls_str phase_ids = [] for root_phase in phase_pool.browse(cr, uid, root_phase_ids, context=context): @@ -492,10 +497,10 @@ def Project_%d(): func_str += phases phase_ids += child_phase_ids #Temp File to test the Code for the Allocation - fn = '/home/tiny/Desktop/plt.py' - fp = open(fn, 'w') - fp.writelines(func_str) - fp.close() +# fn = '/home/tiny/Desktop/plt.py' +# fp = open(fn, 'w') +# fp.writelines(func_str) +# fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) @@ -576,14 +581,16 @@ def Project_%d(): for key, vals in resource_objs.items(): cls_str +=''' class Resource_%s(Resource): + title = \"%s\" vacation = %s efficiency = %s -'''%(key, vals.get('vacation', False), vals.get('efficiency', False)) +'''%(key, vals.get('name',False), vals.get('vacation', False), vals.get('efficiency', False)) # Create a new project for each phase func_str += ''' def Project_%d(): from resource.faces import Resource + title = \"%s\" start = \'%s\' minimum_time_unit = %s working_hours_per_day = %s @@ -592,7 +599,7 @@ def Project_%d(): working_days_per_year = %s vacation = %s working_days = %s -'''%(project.id, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) +'''%(project.id, project.name, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) func_str += cls_str parent = False task_ids = [] @@ -664,9 +671,10 @@ class project_task(osv.osv): if not flag: s = ''' def Task_%s(): + title = \"%s\" effort = \'%s\' resource = %s -'''%(task.id, duration, resource) +'''%(task.id, task.name, duration, resource) if parent: start = 'up.Task_%s.end' % (parent.id) s += ''' @@ -676,9 +684,10 @@ class project_task(osv.osv): else: s = ''' def Task_%s(): + title = \"%s\" effort = \'%s\' resource = %s -'''%(task.id, duration, resource) +'''%(task.id, task.name, duration, resource) if parent: start = 'up.Task_%s.end' % (parent.id) s += ''' -- cgit v1.2.3 From 4bfcaa7c48b28bb1c067bc2c1d66ff6f95cbe437 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Wed, 5 Jan 2011 19:12:58 +0530 Subject: [IMP] Project_long_term: Refactoring Scheduling Process. bzr revid: jam@tinyerp.com-20110105134258-0ew0tmu416ihqttu --- addons/project_long_term/project_long_term.py | 47 +++++++++++++++++++-------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 933b6540e90..fb36c7e293f 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -429,6 +429,7 @@ class project(osv.osv): if type(ids) in (long, int,): ids = [ids] phase_pool = self.pool.get('project.phase') + task_pool = self.pool.get('project.task') resource_pool = self.pool.get('resource.resource') data_pool = self.pool.get('ir.model.data') resource_allocation_pool = self.pool.get('project.resource.allocation') @@ -497,21 +498,35 @@ def Project_%d(): func_str += phases phase_ids += child_phase_ids #Temp File to test the Code for the Allocation -# fn = '/home/tiny/Desktop/plt.py' -# fp = open(fn, 'w') -# fp.writelines(func_str) -# fp.close() + fn = '/home/tiny/Desktop/plt.py' + fp = open(fn, 'w') + fp.writelines(func_str) + fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) Project = eval('Project_%d' % project.id) project = Task.BalancedProject(Project) - + for phase_id in phase_ids: + act_phase = phase_pool.browse(cr, uid, phase_id, context=context) + print "============",act_phase phase = eval("project.Phase_%d" % phase_id) start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() - + if act_phase.task_ids: + for task in act_phase.task_ids: + vals = {} + #Getting values of the Tasks + temp = eval("phase.Task_%s"%task.id) + vals.update({'date_start' : temp.start.strftime('%Y-%m-%d %H:%M:%S')}) +# vals.update({'date_end' : temp.end.strftime('%Y-%m-%d %H:%M:%S')}) + vals.update({'planned_hours' : str(temp._Task__calc_duration().strftime('%H.%M'))}) + vals.update({'date_deadline' : str(temp._Task__calc_end().strftime('%Y-%m-%d %H:%M:%S'))}) + task_pool.write(cr, uid, task.id, vals, context=context) + print ">>>>>",dir(temp) + print ">>>><<<<<<<<<<<<<<<<>",temp.booked_resource + # Recalculate date_start and date_end # according to constraints on date start and date end on phase @@ -613,16 +628,15 @@ def Project_%d(): task_ids.append(task.id) #Temp File to test the Code for the Allocation -# fn = '/home/tiny/Desktop/plt_1.py' -# fp = open(fn, 'w') -# fp.writelines(func_str) -# fp.close() + fn = '/home/tiny/Desktop/plt_1.py' + fp = open(fn, 'w') + fp.writelines(func_str) + fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) Project = eval('Project_%d' % project.id) project = Task.BalancedProject(Project) - for task_id in task_ids: task = eval("project.Task_%d" % task_id) start_date = task.start.to_datetime() @@ -655,6 +669,9 @@ class project_task(osv.osv): _columns = { 'phase_id': fields.many2one('project.phase', 'Project Phase'), } + _defaults = { + 'user_id' : False + } def generate_task(self, cr, uid, task_id, parent=False, flag=False, context=None): if context is None: @@ -663,10 +680,12 @@ class project_task(osv.osv): resource_allocation_pool = self.pool.get('project.resource.allocation') task = self.browse(cr, uid, task_id, context=context) duration = str(task.planned_hours )+ 'H' - resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id)], context=context) resource = False - if len(resource_ids): - resource = 'Resource_%s'%resource_ids[0] + if task.user_id: + resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id),('resource_type','=','user')], context=context) + print "\n\n==========", task.user_id.name, resource_ids + if len(resource_ids): + resource = 'Resource_%s'%resource_ids[0] # Phases Defination for the Project if not flag: s = ''' -- cgit v1.2.3 From 74910bba4ec6159499f98027e11bfe9a2cb6f23b Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Wed, 5 Jan 2011 20:20:56 +0530 Subject: [CHG] Project_long_term: Refactoring Scheduling Process. bzr revid: jam@tinyerp.com-20110105145056-u88eik8isjnfj6md --- addons/project_long_term/project_long_term.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index fdec5c8a3dd..a793db6343e 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -229,7 +229,7 @@ class project_phase(osv.osv): avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) duration = str(avg_days) + 'd' # Create a new project for each phase - str_resource = ('%s,'*len(phase.resource_ids))[:-1] + str_resource = ('%s | '*len(phase.resource_ids))[:-2] str_vals = str_resource % tuple(map(lambda x: 'Resource_%s'%x.resource_id.id, phase.resource_ids)) # Phases Defination for the Project s = ''' @@ -249,8 +249,7 @@ class project_phase(osv.osv): start = \"%s\" '''%(start) #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") - - + phase_ids.append(phase.id) parent = False task_ids = [] @@ -510,8 +509,8 @@ def Project_%d(): for phase_id in phase_ids: act_phase = phase_pool.browse(cr, uid, phase_id, context=context) - print "============",act_phase phase = eval("project.Phase_%d" % phase_id) + start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() if act_phase.task_ids: @@ -524,7 +523,9 @@ def Project_%d(): vals.update({'planned_hours' : str(temp._Task__calc_duration().strftime('%H.%M'))}) vals.update({'date_deadline' : str(temp._Task__calc_end().strftime('%Y-%m-%d %H:%M:%S'))}) task_pool.write(cr, uid, task.id, vals, context=context) - print ">>>>>",dir(temp) + + for i in dir(temp): + print "i**********", i,eval("project.Phase_%d.Task_%s.%s"%(phase_id,task.id,i)) print ">>>><<<<<<<<<<<<<<<<>",temp.booked_resource # Recalculate date_start and date_end @@ -684,7 +685,6 @@ class project_task(osv.osv): resource = False if task.user_id: resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id),('resource_type','=','user')], context=context) - print "\n\n==========", task.user_id.name, resource_ids if len(resource_ids): resource = 'Resource_%s'%resource_ids[0] # Phases Defination for the Project -- cgit v1.2.3 From af54f1c25586ff2422a18a7657b611315078967c Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Thu, 6 Jan 2011 16:36:28 +0530 Subject: [IMP] Project_long_term : Refactoring Phase Scheduling bzr revid: jam@tinyerp.com-20110106110628-guapsfn423rdy95j --- addons/project_long_term/project_long_term.py | 31 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index a793db6343e..00e7c850702 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -350,7 +350,7 @@ def Phase_%d(): task_ids.append(task.id) #Temp File to test the Code for the Allocation -# fn = '/home/hmo/Desktop/plt.py' +# fn = '/home/tiny/Desktop/plt.py' # fp = open(fn, 'w') # fp.writelines(func_str) # fp.close() @@ -509,25 +509,24 @@ def Project_%d(): for phase_id in phase_ids: act_phase = phase_pool.browse(cr, uid, phase_id, context=context) + resources = act_phase.resource_ids phase = eval("project.Phase_%d" % phase_id) - start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() + if resources: + for res in resources: + vals = {} + vals.update({'date_start' : start_date }) + vals.update({'date_end' : end_date}) + resource_allocation_pool.write(cr, uid, res.id, vals) if act_phase.task_ids: for task in act_phase.task_ids: vals = {} #Getting values of the Tasks temp = eval("phase.Task_%s"%task.id) vals.update({'date_start' : temp.start.strftime('%Y-%m-%d %H:%M:%S')}) -# vals.update({'date_end' : temp.end.strftime('%Y-%m-%d %H:%M:%S')}) - vals.update({'planned_hours' : str(temp._Task__calc_duration().strftime('%H.%M'))}) - vals.update({'date_deadline' : str(temp._Task__calc_end().strftime('%Y-%m-%d %H:%M:%S'))}) + vals.update({'date_end' : temp.end.strftime('%Y-%m-%d %H:%M:%S')}) task_pool.write(cr, uid, task.id, vals, context=context) - - for i in dir(temp): - print "i**********", i,eval("project.Phase_%d.Task_%s.%s"%(phase_id,task.id,i)) - print ">>>><<<<<<<<<<<<<<<<>",temp.booked_resource - # Recalculate date_start and date_end # according to constraints on date start and date end on phase @@ -551,6 +550,13 @@ def Project_%d(): }, context=context) return True + #TODO: DO Resource allocation and compute availability + def compute_allocation(self, rc, uid, ids, start_date, end_date, context=None): + if context == None: + contex = {} + allocation = {} + return allocation + def schedule_tasks(self, cr, uid, ids, context=None): """ Schedule task base on faces lib @@ -629,12 +635,11 @@ def Project_%d(): task_ids.append(task.id) #Temp File to test the Code for the Allocation -# fn = '/home/hmo/Desktop/plt.py' +# fn = '/home/tiny/Desktop/plt.py' # fp = open(fn, 'w') # fp.writelines(func_str) # fp.close() - # Allocating Memory for the required Project and Pahses and Resources exec(func_str) Project = eval('Project_%d' % project.id) @@ -684,7 +689,7 @@ class project_task(osv.osv): duration = str(task.planned_hours )+ 'H' resource = False if task.user_id: - resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id),('resource_type','=','user')], context=context) + resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id)], context=context) if len(resource_ids): resource = 'Resource_%s'%resource_ids[0] # Phases Defination for the Project -- cgit v1.2.3 From 1a2943f0a982b60bb9e10e119f8b8bc77841e2f1 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Thu, 6 Jan 2011 20:15:40 +0530 Subject: [FIX] project_long_term refactroing the phase scheduling bzr revid: jam@tinyerp.com-20110106144540-4ex1r9g2pq8cgy55 --- addons/project_long_term/project_long_term.py | 68 +++++++++++++++++---------- 1 file changed, 43 insertions(+), 25 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 00e7c850702..8b82108bdba 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -231,6 +231,7 @@ class project_phase(osv.osv): # Create a new project for each phase str_resource = ('%s | '*len(phase.resource_ids))[:-2] str_vals = str_resource % tuple(map(lambda x: 'Resource_%s'%x.resource_id.id, phase.resource_ids)) + # Phases Defination for the Project s = ''' def Phase_%s(): @@ -238,16 +239,35 @@ class project_phase(osv.osv): effort = \'%s\' resource = %s '''%(phase.id, phase.name, duration, str_vals or False) - if parent: - start = 'up.Phase_%s.end' % (parent.id) + + # Recalculate date_start and date_end + # according to constraints on date start and date end on phase + start_date = '' + end_date = '' + if phase.constraint_date_start: + start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') s += ''' + start = \"%s\" +'''%(datetime.strftime(start_date, "%Y-%m-%d")) + else: + if parent: + start = 'up.Phase_%s.end' % (parent.id) + s += ''' start = %s '''%(start) - else: - start = phase.project_id.date_start or phase.date_start - s += ''' + else: + start = phase.project_id.date_start or phase.date_start + s += ''' start = \"%s\" -'''%(start) +'''%(start) + + if phase.constraint_date_end : + end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') + s += ''' + end = \"%s\" +'''%(datetime.strftime(end_date, "%Y-%m-%d")) + + #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") phase_ids.append(phase.id) @@ -513,12 +533,25 @@ def Project_%d(): phase = eval("project.Phase_%d" % phase_id) start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() + # Write the calculated dates back +# if act_phase.constraint_date_start and str(start_date) < act_phase.constraint_date_start: +# start_date = datetime.strptime(act_phase.constraint_date_start, '%Y-%m-%d') +# else: +# start_date = start_date +# if act_phase.constraint_date_end and str(end_date) > act_phase.constraint_date_end: +# end_date= datetime.strptime(act_phase.constraint_date_end, '%Y-%m-%d') +# date_start = act_phase.constraint_date_end +# else: +# end_date = start_date +# start_date = end_date + ctx = context.copy() + ctx.update({'scheduler': True}) if resources: for res in resources: vals = {} vals.update({'date_start' : start_date }) vals.update({'date_end' : end_date}) - resource_allocation_pool.write(cr, uid, res.id, vals) + resource_allocation_pool.write(cr, uid, res.id, vals, context=ctx) if act_phase.task_ids: for task in act_phase.task_ids: vals = {} @@ -526,28 +559,13 @@ def Project_%d(): temp = eval("phase.Task_%s"%task.id) vals.update({'date_start' : temp.start.strftime('%Y-%m-%d %H:%M:%S')}) vals.update({'date_end' : temp.end.strftime('%Y-%m-%d %H:%M:%S')}) - task_pool.write(cr, uid, task.id, vals, context=context) - # Recalculate date_start and date_end - # according to constraints on date start and date end on phase - - #if phase.constraint_date_start and str(s_date) < phase.constraint_date_start: - # start_date = datetime.strptime(phase.constraint_date_start, '%Y-%m-%d') - #else: - # start_date = s_date - #if phase.constraint_date_end and str(e_date) > phase.constraint_date_end: - # end_date= datetime.strptime(phase.constraint_date_end, '%Y-%m-%d') - # date_start = phase.constraint_date_end - #else: - # end_date = e_date - # date_start = end_date + task_pool.write(cr, uid, task.id, vals, context=ctx) + - # Write the calculated dates back - #ctx = context.copy() - #ctx.update({'scheduler': True}) phase_pool.write(cr, uid, [phase_id], { 'date_start': start_date.strftime('%Y-%m-%d'), 'date_end': end_date.strftime('%Y-%m-%d') - }, context=context) + }, context=ctx) return True #TODO: DO Resource allocation and compute availability -- cgit v1.2.3 From e4b3f02d3aca04c6d28490aaea1d6a027476bdb2 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Fri, 7 Jan 2011 20:20:08 +0530 Subject: [IMP] Project_long_term : Refactoring Phase Scheduling code bzr revid: jam@tinyerp.com-20110107145008-yhe4azi3sgzhrbf9 --- addons/project_long_term/project_long_term.py | 84 ++++++++++++--------------- 1 file changed, 36 insertions(+), 48 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 8b82108bdba..14fdeb4eb39 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -229,7 +229,7 @@ class project_phase(osv.osv): avg_days = uom_pool._compute_qty(cr, uid, phase.product_uom.id, phase.duration, day_uom_id) duration = str(avg_days) + 'd' # Create a new project for each phase - str_resource = ('%s | '*len(phase.resource_ids))[:-2] + str_resource = ('%s & '*len(phase.resource_ids))[:-2] str_vals = str_resource % tuple(map(lambda x: 'Resource_%s'%x.resource_id.id, phase.resource_ids)) # Phases Defination for the Project @@ -276,11 +276,12 @@ class project_phase(osv.osv): todo_task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)), ('state', 'in', ['draft', 'open', 'pending']) ], order='sequence') - for task in task_pool.browse(cr, uid, todo_task_ids, context=context): - s += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=False, context=context) - if not parent: - parent = task - task_ids.append(task.id) + if todo_task_ids : + for task in task_pool.browse(cr, uid, todo_task_ids, context=context): + s += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=False, context=context) + if not parent: + parent = task + task_ids.append(task.id) f += s + '\n' # Recursive call till all the next phases scheduled @@ -357,7 +358,7 @@ def Phase_%d(): vacation = %s working_days = %s '''%(phase.id, phase.name, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) - func_str += cls_str + parent = False task_ids = [] todo_task_ids = task_pool.search(cr, uid, [('id', 'in', map(lambda x : x.id, phase.task_ids)), @@ -368,7 +369,7 @@ def Phase_%d(): if not parent: parent = task task_ids.append(task.id) - + func_str += cls_str #Temp File to test the Code for the Allocation # fn = '/home/tiny/Desktop/plt.py' # fp = open(fn, 'w') @@ -510,6 +511,7 @@ def Project_%d(): vacation = %s working_days = %s '''%(project.id, project.name, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) + func_str += cls_str phase_ids = [] for root_phase in phase_pool.browse(cr, uid, root_phase_ids, context=context): @@ -533,39 +535,34 @@ def Project_%d(): phase = eval("project.Phase_%d" % phase_id) start_date = phase.start.to_datetime() end_date = phase.end.to_datetime() - # Write the calculated dates back -# if act_phase.constraint_date_start and str(start_date) < act_phase.constraint_date_start: -# start_date = datetime.strptime(act_phase.constraint_date_start, '%Y-%m-%d') -# else: -# start_date = start_date -# if act_phase.constraint_date_end and str(end_date) > act_phase.constraint_date_end: -# end_date= datetime.strptime(act_phase.constraint_date_end, '%Y-%m-%d') -# date_start = act_phase.constraint_date_end -# else: -# end_date = start_date -# start_date = end_date - ctx = context.copy() - ctx.update({'scheduler': True}) + if resources: for res in resources: vals = {} vals.update({'date_start' : start_date }) vals.update({'date_end' : end_date}) - resource_allocation_pool.write(cr, uid, res.id, vals, context=ctx) + resource_allocation_pool.write(cr, uid, res.id, vals, context=context) if act_phase.task_ids: for task in act_phase.task_ids: vals = {} #Getting values of the Tasks temp = eval("phase.Task_%s"%task.id) + if temp.booked_resource: + res_name = temp.booked_resource[0].title + res_id = resource_pool.search(cr, uid,[('name','=',res_name)], context = context) + if res_id: + res = resource_pool.browse(cr, uid, res_id[0], context = context) + vals.update({'user_id' : res.user_id.id}) + vals.update({'date_start' : temp.start.strftime('%Y-%m-%d %H:%M:%S')}) vals.update({'date_end' : temp.end.strftime('%Y-%m-%d %H:%M:%S')}) - task_pool.write(cr, uid, task.id, vals, context=ctx) + task_pool.write(cr, uid, task.id, vals, context=context) phase_pool.write(cr, uid, [phase_id], { 'date_start': start_date.strftime('%Y-%m-%d'), 'date_end': end_date.strftime('%Y-%m-%d') - }, context=ctx) + }, context=context) return True #TODO: DO Resource allocation and compute availability @@ -640,18 +637,19 @@ def Project_%d(): vacation = %s working_days = %s '''%(project.id, project.name, start, minimum_time_unit, working_hours_per_day, working_days_per_week, working_days_per_month, working_days_per_year, vacation, working_days ) - func_str += cls_str + parent = False task_ids = [] todo_task_ids = task_pool.search(cr, uid, [('project_id', '=', project.id), ('state', 'in', ['draft', 'open', 'pending']) ], order='sequence') - for task in task_pool.browse(cr, uid, todo_task_ids, context=context): - func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=True,context=context) - if not parent: - parent = task - task_ids.append(task.id) - + if todo_task_ids: + for task in task_pool.browse(cr, uid, todo_task_ids, context=context): + func_str += task_pool.generate_task(cr, uid, task.id, parent=parent, flag=True,context=context) + if not parent: + parent = task + task_ids.append(task.id) + func_str += cls_str #Temp File to test the Code for the Allocation # fn = '/home/tiny/Desktop/plt.py' # fp = open(fn, 'w') @@ -701,28 +699,23 @@ class project_task(osv.osv): def generate_task(self, cr, uid, task_id, parent=False, flag=False, context=None): if context is None: context = {} + phase_pool = self.pool.get('project.phase') resource_pool = self.pool.get('resource.resource') resource_allocation_pool = self.pool.get('project.resource.allocation') task = self.browse(cr, uid, task_id, context=context) duration = str(task.planned_hours )+ 'H' - resource = False - if task.user_id: - resource_ids = self.search(cr, uid, [('user_id', '=', task.user_id.id)], context=context) - if len(resource_ids): - resource = 'Resource_%s'%resource_ids[0] - # Phases Defination for the Project + str_resource = False + if task.phase_id.resource_ids: + str_resource = ('%s | '*len(task.phase_id.resource_ids))[:-2] + str_resource = str_resource % tuple(map(lambda x: 'Resource_%s'%x.resource_id.id, task.phase_id.resource_ids)) + # Task Defination for the Phase of the Project if not flag: s = ''' def Task_%s(): title = \"%s\" effort = \'%s\' resource = %s -'''%(task.id, task.name, duration, resource) - if parent: - start = 'up.Task_%s.end' % (parent.id) - s += ''' - start = %s -'''%(start) +'''%(task.id, task.name, duration, str_resource) #start = datetime.strftime((datetime.strptime(start, "%Y-%m-%d")), "%Y-%m-%d") else: s = ''' @@ -731,11 +724,6 @@ class project_task(osv.osv): effort = \'%s\' resource = %s '''%(task.id, task.name, duration, resource) - if parent: - start = 'up.Task_%s.end' % (parent.id) - s += ''' - start = %s -'''%(start) s += '\n' return s project_task() -- cgit v1.2.3 From d06f5c0831600ba0e351ba653fdfb35da64cc283 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Mon, 10 Jan 2011 11:39:38 +0530 Subject: [IMP] Project_long_term : Task scheduling code Re-factoring bzr revid: jam@tinyerp.com-20110110060938-4wxuptfiu99r7er6 --- addons/project_long_term/project_long_term.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 14fdeb4eb39..2082f156b86 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -723,7 +723,7 @@ class project_task(osv.osv): title = \"%s\" effort = \'%s\' resource = %s -'''%(task.id, task.name, duration, resource) +'''%(task.id, task.name, duration, str_resource) s += '\n' return s project_task() -- cgit v1.2.3 From 740a3169ef2078edbf900d87da14b6edf158df67 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Mon, 10 Jan 2011 10:45:03 +0100 Subject: [FIX] project_long_term : Cleaning temp file bzr revid: tfr@openerp.com-20110110094503-4ovjmqcgyfwym9de --- addons/project_long_term/project_long_term.py | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index 2082f156b86..fc4151d855f 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -370,11 +370,6 @@ def Phase_%d(): parent = task task_ids.append(task.id) func_str += cls_str - #Temp File to test the Code for the Allocation -# fn = '/home/tiny/Desktop/plt.py' -# fp = open(fn, 'w') -# fp.writelines(func_str) -# fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) @@ -518,11 +513,6 @@ def Project_%d(): phases, child_phase_ids = phase_pool.generate_phase(cr, uid, [root_phase.id], '', context=context) func_str += phases phase_ids += child_phase_ids - #Temp File to test the Code for the Allocation - fn = '/home/tiny/Desktop/plt.py' - fp = open(fn, 'w') - fp.writelines(func_str) - fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) @@ -650,11 +640,6 @@ def Project_%d(): parent = task task_ids.append(task.id) func_str += cls_str - #Temp File to test the Code for the Allocation -# fn = '/home/tiny/Desktop/plt.py' -# fp = open(fn, 'w') -# fp.writelines(func_str) -# fp.close() # Allocating Memory for the required Project and Pahses and Resources exec(func_str) -- cgit v1.2.3 From 7b40023158912d0db757f6a52eaaf6f20e332b0e Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Tue, 11 Jan 2011 10:54:23 +0530 Subject: [FIX-BUG] project_long_term - lp:701070 lp bug: https://launchpad.net/bugs/701070 fixed bzr revid: jam@tinyerp.com-20110111052423-ot4hx1b4rj5gtvoy --- addons/project_long_term/project_long_term.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index fc4151d855f..bd0f34ddcc3 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -517,8 +517,11 @@ def Project_%d(): # Allocating Memory for the required Project and Pahses and Resources exec(func_str) Project = eval('Project_%d' % project.id) - project = Task.BalancedProject(Project) - + project = None + try: + project = Task.BalancedProject(Project) + except : + raise osv.except_osv(_('Error !'),_('Invalid resource allocation, Phase Scheduling is not possible.\nPlease check project member resource.')) for phase_id in phase_ids: act_phase = phase_pool.browse(cr, uid, phase_id, context=context) resources = act_phase.resource_ids -- cgit v1.2.3 From 0a62db776f2894763c7fbd0a257cc052a785c227 Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Tue, 11 Jan 2011 11:18:01 +0530 Subject: [FIX] project_long_term - buildbot-trunk-dev-addons1 build:595-test bzr revid: jam@tinyerp.com-20110111054801-xn9s7t653vosdrdy --- addons/project_long_term/project_long_term.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index bd0f34ddcc3..a795dd76dee 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -19,15 +19,10 @@ # ############################################################################## -from datetime import datetime, timedelta -from dateutil.relativedelta import relativedelta +from datetime import datetime from tools.translate import _ from osv import fields, osv from resource.faces import task as Task -import operator -from new import classobj -import types -import new class project_phase(osv.osv): _name = "project.phase" @@ -219,9 +214,7 @@ class project_phase(osv.osv): if context is None: context = {} phase_ids = [] - resource_pool = self.pool.get('resource.resource') data_pool = self.pool.get('ir.model.data') - resource_allocation_pool = self.pool.get('project.resource.allocation') uom_pool = self.pool.get('product.uom') task_pool = self.pool.get('project.task') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') @@ -304,9 +297,6 @@ class project_phase(osv.osv): ids = [ids] task_pool = self.pool.get('project.task') resource_pool = self.pool.get('resource.resource') - data_pool = self.pool.get('ir.model.data') - resource_allocation_pool = self.pool.get('project.resource.allocation') - for phase in self.browse(cr, uid, ids, context=context): project = phase.project_id calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False @@ -448,7 +438,6 @@ class project(osv.osv): resource_pool = self.pool.get('resource.resource') data_pool = self.pool.get('ir.model.data') resource_allocation_pool = self.pool.get('project.resource.allocation') - uom_pool = self.pool.get('product.uom') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') for project in self.browse(cr, uid, ids, context=context): @@ -561,7 +550,7 @@ def Project_%d(): #TODO: DO Resource allocation and compute availability def compute_allocation(self, rc, uid, ids, start_date, end_date, context=None): if context == None: - contex = {} + context = {} allocation = {} return allocation @@ -576,8 +565,6 @@ def Project_%d(): task_pool = self.pool.get('project.task') resource_pool = self.pool.get('resource.resource') data_pool = self.pool.get('ir.model.data') - resource_allocation_pool = self.pool.get('project.resource.allocation') - uom_pool = self.pool.get('product.uom') data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day') for project in self.browse(cr, uid, ids, context=context): @@ -687,9 +674,6 @@ class project_task(osv.osv): def generate_task(self, cr, uid, task_id, parent=False, flag=False, context=None): if context is None: context = {} - phase_pool = self.pool.get('project.phase') - resource_pool = self.pool.get('resource.resource') - resource_allocation_pool = self.pool.get('project.resource.allocation') task = self.browse(cr, uid, task_id, context=context) duration = str(task.planned_hours )+ 'H' str_resource = False -- cgit v1.2.3 From 390a32d7db87bb710ccaa977bd24ce9d416b62cf Mon Sep 17 00:00:00 2001 From: jam-openerp Date: Mon, 17 Jan 2011 17:09:48 +0530 Subject: [IMP/ADD] project_long_term : 1) Improved the Phase sheduling Wizard warning messages 2) Addedd waraning message for Task Scheduling wizard bzr revid: jam@tinyerp.com-20110117113948-eoc37olm4iorqe02 --- addons/project_long_term/project_long_term.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'addons/project_long_term/project_long_term.py') diff --git a/addons/project_long_term/project_long_term.py b/addons/project_long_term/project_long_term.py index a795dd76dee..0e605ed4331 100644 --- a/addons/project_long_term/project_long_term.py +++ b/addons/project_long_term/project_long_term.py @@ -364,7 +364,12 @@ def Phase_%d(): # Allocating Memory for the required Project and Pahses and Resources exec(func_str) Phase = eval('Phase_%d' % phase.id) - phase = Task.BalancedProject(Phase) + phase = None + try: + phase = Task.BalancedProject(Phase) + except : + raise osv.except_osv(_('Error !'),_('Phase Scheduling is not possible.\nProject should have the Start date and member for scheduling.')) + for task_id in task_ids: task = eval("phase.Task_%d" % task_id) @@ -510,7 +515,8 @@ def Project_%d(): try: project = Task.BalancedProject(Project) except : - raise osv.except_osv(_('Error !'),_('Invalid resource allocation, Phase Scheduling is not possible.\nPlease check project member resource.')) + raise osv.except_osv(_('Error !'),_('Phase Scheduling is not possible.\nProject should have the Start date and member for scheduling.')) + for phase_id in phase_ids: act_phase = phase_pool.browse(cr, uid, phase_id, context=context) resources = act_phase.resource_ids @@ -573,7 +579,10 @@ def Project_%d(): #Creating resources using the member of the Project u_ids = [i.id for i in project.members] resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context) - start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + try: + start_date = datetime.strftime((datetime.strptime(start_date, "%Y-%m-%d")), "%Y-%m-%d") + except: + raise osv.except_osv(_('Error !'),_('Task Scheduling is not possible.\nProject should have the Start date for scheduling.')) func_str = '' start = start_date minimum_time_unit = 1 @@ -634,7 +643,12 @@ def Project_%d(): # Allocating Memory for the required Project and Pahses and Resources exec(func_str) Project = eval('Project_%d' % project.id) - project = Task.BalancedProject(Project) + project = None + try: + project = Task.BalancedProject(Project) + except : + raise osv.except_osv(_('Error !'),_('Phase Scheduling is not possible.\nProject should have the Start date and member for scheduling.')) + for task_id in task_ids: task = eval("project.Task_%d" % task_id) start_date = task.start.to_datetime() -- cgit v1.2.3