summaryrefslogtreecommitdiff
path: root/addons/project_long_term/project_long_term.py
diff options
context:
space:
mode:
authorjam-openerp <jam@tinyerp.com>2011-01-05 15:26:17 +0530
committerjam-openerp <jam@tinyerp.com>2011-01-05 15:26:17 +0530
commit5dbdff512bf33795bd5948b5dbe599140d06e33d (patch)
tree0d9b592996116bff66d9d866e8f8cc5f53d6e1cc /addons/project_long_term/project_long_term.py
parent344911ad414e7977e17560bee59ddc24eb6fedba (diff)
[IMP] Project_long_term: Refactoring Scheduling Process.
bzr revid: jam@tinyerp.com-20110105095617-bhat8tcnpqv2g5w3
Diffstat (limited to 'addons/project_long_term/project_long_term.py')
-rw-r--r--addons/project_long_term/project_long_term.py130
1 files changed, 63 insertions, 67 deletions
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'