summaryrefslogtreecommitdiff
path: root/addons/project/project.py
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2011-11-13 16:40:52 +0100
committerFabien Pinckaers <fp@tinyerp.com>2011-11-13 16:40:52 +0100
commit14874a989ecfdd9b0a4db3cc059d2c6bd4d080dc (patch)
tree40b7988faad8b8db8fda0b68b45fe4d84ccb8dab /addons/project/project.py
parent7e785ced6b787402fd04e21067a18a1eda5f5a53 (diff)
[IMP] Clean demo data of project and project long term using scheduler
bzr revid: fp@tinyerp.com-20111113154052-gh2a8y2tqkdv2ll9
Diffstat (limited to 'addons/project/project.py')
-rw-r--r--addons/project/project.py128
1 files changed, 128 insertions, 0 deletions
diff --git a/addons/project/project.py b/addons/project/project.py
index 4b4e3079e38..1fc83771005 100644
--- a/addons/project/project.py
+++ b/addons/project/project.py
@@ -25,6 +25,7 @@ from datetime import datetime, date
from tools.translate import _
from osv import fields, osv
+from resource.faces import task as Task
# I think we can remove this in v6.1 since VMT's improvements in the framework ?
#class project_project(osv.osv):
@@ -139,6 +140,7 @@ class project(osv.osv):
'project.task': (_get_project_task, ['planned_hours', 'effective_hours', 'remaining_hours', 'total_hours', 'progress', 'delay_hours','state'], 10),
}),
'effective_hours': fields.function(_progress_rate, multi="progress", string='Time Spent', help="Sum of spent hours of all tasks related to this project and its child projects."),
+ 'resource_calendar_id': fields.many2one('resource.calendar', 'Working Time', help="Timetable working hours to adjust the gantt diagram report", states={'close':[('readonly',True)]} ),
'total_hours': fields.function(_progress_rate, multi="progress", string='Total Time', help="Sum of total hours of all tasks related to this project and its child projects.",
store = {
'project.project': (lambda self, cr, uid, ids, c={}: ids, ['tasks'], 10),
@@ -305,6 +307,105 @@ class project(osv.osv):
self.setActive(cr, uid, child_ids, value, context=None)
return True
+ def _schedule_header(self, cr, uid, ids, force_members=True, context=None):
+ context = context or {}
+ if type(ids) in (long, int,):
+ ids = [ids]
+ projects = self.browse(cr, uid, ids, context=context)
+
+ for project in projects:
+ if (not project.members) and force_members:
+ raise osv.except_osv(_('Warning !'),_("You must assign members on the project '%s' !") % (project.name,))
+
+ resource_pool = self.pool.get('resource.resource')
+
+ result = "from resource.faces import *\n"
+ result += "import datetime\n"
+ for project in self.browse(cr, uid, ids, context=context):
+ u_ids = [i.id for i in project.members]
+ if project.user_id and (project.user_id.id not in u_ids):
+ u_ids.append(project.user_id.id)
+ for task in project.tasks:
+ if task.state in ('done','cancelled'):
+ continue
+ if task.user_id and (task.user_id.id not in u_ids):
+ u_ids.append(task.user_id.id)
+ calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
+ resource_objs = resource_pool.generate_resources(cr, uid, u_ids, calendar_id, context=context)
+ for key, vals in resource_objs.items():
+ result +='''
+class User_%s(Resource):
+ efficiency = %s
+''' % (key, vals.get('efficiency', False))
+
+ result += '''
+def Project():
+ '''
+ return result
+
+ def _schedule_project(self, cr, uid, project, context=None):
+ resource_pool = self.pool.get('resource.resource')
+ calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
+ working_days = resource_pool.compute_working_calendar(cr, uid, calendar_id, context=context)
+ # TODO: check if we need working_..., default values are ok.
+ puids = [x.id for x in project.members]
+ if project.user_id:
+ puids.append(project.user_id.id)
+ result = """
+ def Project_%d():
+ start = \'%s\'
+ working_days = %s
+ resource = %s
+""" % (
+ project.id,
+ project.date_start, working_days,
+ '|'.join(['User_'+str(x) for x in puids])
+ )
+ vacation = calendar_id and tuple(resource_pool.compute_vacation(cr, uid, calendar_id, context=context)) or False
+ if vacation:
+ result+= """
+ vacation = %s
+""" % ( vacation, )
+ return result
+
+ #TODO: DO Resource allocation and compute availability
+ def compute_allocation(self, rc, uid, ids, start_date, end_date, context=None):
+ if context == None:
+ context = {}
+ allocation = {}
+ return allocation
+
+ def schedule_tasks(self, cr, uid, ids, context=None):
+ context = context or {}
+ if type(ids) in (long, int,):
+ ids = [ids]
+ projects = self.browse(cr, uid, ids, context=context)
+ result = self._schedule_header(cr, uid, ids, False, context=context)
+ for project in projects:
+ result += self._schedule_project(cr, uid, project, context=context)
+ result += self.pool.get('project.task')._generate_task(cr, uid, project.tasks, ident=4, context=context)
+
+ local_dict = {}
+ exec result in local_dict
+ projects_gantt = Task.BalancedProject(local_dict['Project'])
+
+ for project in projects:
+ project_gantt = getattr(projects_gantt, 'Project_%d' % (project.id,))
+ for task in project.tasks:
+ if task.state in ('done','cancelled'):
+ continue
+
+ p = getattr(project_gantt, 'Task_%d' % (task.id,))
+
+ self.pool.get('project.task').write(cr, uid, [task.id], {
+ 'date_start': p.start.strftime('%Y-%m-%d %H:%M:%S'),
+ 'date_end': p.end.strftime('%Y-%m-%d %H:%M:%S')
+ }, context=context)
+ if (not task.user_id) and (p.booked_resource):
+ self.pool.get('project.task').write(cr, uid, [task.id], {
+ 'user_id': int(p.booked_resource[0].name[5:]),
+ }, context=context)
+ return True
project()
class users(osv.osv):
@@ -836,6 +937,33 @@ class task(osv.osv):
res = super(task, self).unlink(cr, uid, ids, context)
return res
+ def _generate_task(self, cr, uid, tasks, ident=4, context=None):
+ context = context or {}
+ result = ""
+ ident = ' '*ident
+ for task in tasks:
+ if task.state in ('done','cancelled'):
+ continue
+ result += '''
+%sdef Task_%s():
+%s todo = \"%.2fH\"
+%s effort = \"%.2fH\"''' % (ident,task.id, ident,task.remaining_hours, ident,task.total_hours)
+ start = []
+ for t2 in task.parent_ids:
+ start.append("up.Task_%s.end" % (t2.id,))
+ if start:
+ result += '''
+%s start = max(%s)
+''' % (ident,','.join(start))
+
+ if task.user_id:
+ result += '''
+%s resource = %s
+''' % (ident, 'User_'+str(task.user_id.id))
+
+ result += "\n"
+ return result
+
task()
class project_work(osv.osv):