[FIX] project_long_term: backported the add of constraint on project members and improved the error handling

bzr revid: qdp-launchpad@tinyerp.com-20110120164920-aowlxatmcrpt0gtf
This commit is contained in:
qdp-launchpad@tinyerp.com
2011-01-20 17:49:20 +01:00
parent e519dac248
commit cea971b94e
+51 -11
View File
@@ -360,17 +360,19 @@ def Phase_%d():
parent = task
task_ids.append(task.id)
func_str += cls_str
phase_id = phase.id
#check known constraints before running Face algorithm in order to have the error translated
if not phase.project_id.date_start:
raise osv.except_osv(_('Error !'),_('Task Scheduling is not possible.\nProject should have the Start date for scheduling.'))
# Allocating Memory for the required Project and Pahses and Resources
exec(func_str)
Phase = eval('Phase_%d' % phase.id)
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.'))
except Exception, e:
raise osv.except_osv(_('Error !'),e)
for task_id in task_ids:
task = eval("phase.Task_%d" % task_id)
start_date = task.start.to_datetime()
@@ -444,6 +446,23 @@ class project(osv.osv):
data_pool = self.pool.get('ir.model.data')
resource_allocation_pool = self.pool.get('project.resource.allocation')
data_model, day_uom_id = data_pool.get_object_reference(cr, uid, 'product', 'uom_day')
#Checking the Valid Phase resource allocation from project member
for project in self.browse(cr, uid, ids, context=context):
flag = False
res_missing = []
members_ids = []
if project.members:
members_ids = [user.id for user in project.members]
for phase in project.phase_ids:
if phase.resource_ids:
res_ids = [ re.id for re in phase.resource_ids]
for res in resource_allocation_pool.browse(cr, uid, res_ids, context=context):
if res.resource_id.user_id.id not in members_ids:
res_missing += [res.resource_id.name]
flag = True
if flag:
raise osv.except_osv(_('Warning !'),_("Resource(s) %s is(are) not member(s) of the project '%s' .") % (",".join(res_missing), project.name))
for project in self.browse(cr, uid, ids, context=context):
root_phase_ids = phase_pool.search(cr, uid, [('project_id', '=', project.id),
@@ -508,14 +527,17 @@ def Project_%d():
func_str += phases
phase_ids += child_phase_ids
# Allocating Memory for the required Project and Pahses and Resources
project_id = project.id
if not project.date_start:
raise osv.except_osv(_('Error !'),_('Task Scheduling is not possible.\nProject should have the Start date for scheduling.'))
# Allocating Memory for the required Project and Phases and Resources
exec(func_str)
Project = eval('Project_%d' % project.id)
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.'))
except Exception, e:
raise osv.except_osv(_('Error !'), e)
for phase_id in phase_ids:
act_phase = phase_pool.browse(cr, uid, phase_id, context=context)
@@ -576,6 +598,22 @@ def Project_%d():
for project in self.browse(cr, uid, ids, context=context):
calendar_id = project.resource_calendar_id and project.resource_calendar_id.id or False
start_date = project.date_start
#Checking the Valid Phase resource allocation from project member
flag = False
res_missing = []
members_ids = []
if project.members:
members_ids = [user.id for user in project.members]
for phase in project.phase_ids:
if phase.resource_ids:
res_ids = [ re.id for re in phase.resource_ids]
for res in self.pool.get('project.resource.allocation').browse(cr, uid, res_ids, context=context):
if res.resource_id.user_id.id not in members_ids:
res_missing += [res.resource_id.name]
flag = True
if flag:
raise osv.except_osv(_('Warning !'),_("Resource(s) %s is(are) not member(s) of the project '%s' .") % (",".join(res_missing), project.name))
#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)
@@ -640,14 +678,16 @@ def Project_%d():
task_ids.append(task.id)
func_str += cls_str
# Allocating Memory for the required Project and Pahses and Resources
if not project.date_start:# or not project.members:
raise osv.except_osv(_('Error !'),_('Task Scheduling is not possible.\nProject should have the Start date for scheduling.'))
# Allocating Memory for the required Project and Phases and Resources
exec(func_str)
Project = eval('Project_%d' % project.id)
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.'))
except Exception, e:
raise osv.except_osv(_('Error !'), e)
for task_id in task_ids:
task = eval("project.Task_%d" % task_id)