diff --git a/addons/project/project.py b/addons/project/project.py index 14524a0bd05..9cb367eb8e1 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -840,37 +840,39 @@ class task(osv.osv): self.write(cr, uid, ids, {'state': 'draft'}, context=context) return True - def do_delegate(self, cr, uid, task_id, delegate_data={}, context=None): + def do_delegate(self, cr, uid, ids, delegate_data={}, context=None): """ Delegate Task to another users. """ - task = self.browse(cr, uid, task_id, context=context) - self.copy(cr, uid, task.id, { - 'name': delegate_data['name'], - 'user_id': delegate_data['user_id'], - 'planned_hours': delegate_data['planned_hours'], - 'remaining_hours': delegate_data['planned_hours'], - 'parent_ids': [(6, 0, [task.id])], - 'state': 'draft', - 'description': delegate_data['new_task_description'] or '', - 'child_ids': [], - 'work_ids': [] - }, context=context) - newname = delegate_data['prefix'] or '' - self.write(cr, uid, [task.id], { - 'remaining_hours': delegate_data['planned_hours_me'], - 'planned_hours': delegate_data['planned_hours_me'] + (task.effective_hours or 0.0), - 'name': newname, - }, context=context) - if delegate_data['state'] == 'pending': - self.do_pending(cr, uid, [task.id], context) - else: - self.do_close(cr, uid, [task.id], context=context) - user_pool = self.pool.get('res.users') - delegate_user = user_pool.browse(cr, uid, delegate_data['user_id'], context=context) - message = _("The task '%s' has been delegated to %s.") % (delegate_data['name'], delegate_user.name) - self.log(cr, uid, task.id, message) - return True + assert delegate_data['user_id'], _("Delegated User should be specified") + delegrated_tasks = {} + for task in self.browse(cr, uid, ids, context=context): + delegrated_task_id = self.copy(cr, uid, task.id, { + 'name': delegate_data['name'], + 'project_id': delegate_data['project_id'] and delegate_data['project_id'][0] or False, + 'user_id': delegate_data['user_id'] and delegate_data['user_id'][0] or False, + 'planned_hours': delegate_data['planned_hours'] or 0.0, + 'parent_ids': [(6, 0, [task.id])], + 'state': 'draft', + 'description': delegate_data['new_task_description'] or '', + 'child_ids': [], + 'work_ids': [] + }, context=context) + newname = delegate_data['prefix'] or '' + task.write({ + 'remaining_hours': delegate_data['planned_hours_me'], + 'planned_hours': delegate_data['planned_hours_me'] + (task.effective_hours or 0.0), + 'name': newname, + }, context=context) + if delegate_data['state'] == 'pending': + self.do_pending(cr, uid, task.id, context=context) + elif delegate_data['state'] == 'done': + self.do_close(cr, uid, task.id, context=context) + + message = _("The task '%s' has been delegated to %s.") % (delegate_data['name'], delegate_data['user_id'][1]) + self.log(cr, uid, task.id, message) + delegrated_tasks[task.id] = delegrated_task_id + return delegrated_tasks def do_pending(self, cr, uid, ids, context={}): self.write(cr, uid, ids, {'state': 'pending'}, context=context) diff --git a/addons/project/wizard/project_task_delegate.py b/addons/project/wizard/project_task_delegate.py index eaf5dea3084..4b8da00dc10 100644 --- a/addons/project/wizard/project_task_delegate.py +++ b/addons/project/wizard/project_task_delegate.py @@ -31,14 +31,23 @@ class project_task_delegate(osv.osv_memory): _columns = { 'name': fields.char('Delegated Title', size=64, required=True, help="New title of the task delegated to the user"), - 'prefix': fields.char('Your Task Title', size=64, required=True, help="Title for your validation task"), + 'prefix': fields.char('Your Task Title', size=64, help="Title for your validation task"), + 'project_id': fields.many2one('project.project', 'Project', help="User you want to delegate this task to"), 'user_id': fields.many2one('res.users', 'Assign To', required=True, help="User you want to delegate this task to"), 'new_task_description': fields.text('New Task Description', help="Reinclude the description of the task in the task of the user"), 'planned_hours': fields.float('Planned Hours', help="Estimated time to close this task by the delegated user"), - 'planned_hours_me': fields.float('Hours to Validate', required=True, help="Estimated time for you to validate the work done by the user to whom you delegate this task"), - 'state': fields.selection([('pending','Pending'), ('done','Done'), ], 'Validation State', required=True, help="New state of your own task. Pending will be reopened automatically when the delegated task is closed") + 'planned_hours_me': fields.float('Hours to Validate', help="Estimated time for you to validate the work done by the user to whom you delegate this task"), + 'state': fields.selection([('pending','Pending'), ('done','Done'), ], 'Validation State', help="New state of your own task. Pending will be reopened automatically when the delegated task is closed") } + def onchange_project_id(self, cr, uid, ids, project_id=False, context=None): + project_project = self.pool.get('project.project') + if not project_id: + return {'value':{'user_id': False}} + project = project_project.browse(cr, uid, project_id, context=context) + return {'value': {'user_id': project.user_id and project.user_id.id or False}} + + def default_get(self, cr, uid, fields, context=None): """ This function gets default values @@ -47,10 +56,15 @@ class project_task_delegate(osv.osv_memory): if context is None: context = {} record_id = context and context.get('active_id', False) or False + if not record_id: + return res task_pool = self.pool.get('project.task') task = task_pool.browse(cr, uid, record_id, context=context) task_name =tools.ustr(task.name) + if 'project_id' in fields: + res.update({'project_id': task.project_id and task.project_id.id}) + if 'name' in fields: if task_name.startswith(_('CHECK: ')): newname = tools.ustr(task_name).replace(_('CHECK: '), '') @@ -105,9 +119,17 @@ class project_task_delegate(osv.osv_memory): task_id = context.get('active_id', False) task_pool = self.pool.get('project.task') delegate_data = self.read(cr, uid, ids, context=context)[0] - delegate_data['user_id'] = delegate_data['user_id'][0] - delegate_data['name'] = tools.ustr(delegate_data['name']) - task_pool.do_delegate(cr, uid, task_id, delegate_data, context=context) - return {'type': 'ir.actions.act_window_close'} + delegrated_tasks = task_pool.do_delegate(cr, uid, [task_id], delegate_data, context=context) + models_data = self.pool.get('ir.model.data') + + action_model, action_id = models_data.get_object_reference(cr, uid, 'project', 'action_view_task') + view_model, task_view_form_id = models_data.get_object_reference(cr, uid, 'project', 'view_task_form2') + view_model, task_view_tree_id = models_data.get_object_reference(cr, uid, 'project', 'view_task_tree2') + action = self.pool.get(action_model).read(cr, uid, action_id, context=context) + action['res_id'] = delegrated_tasks[task_id] + action['view_id'] = False + action['views'] = [(task_view_form_id, 'form'), (task_view_tree_id, 'tree')] + action['help'] = False + return action project_task_delegate() diff --git a/addons/project/wizard/project_task_delegate_view.xml b/addons/project/wizard/project_task_delegate_view.xml index f9b27af05b3..072325c2b53 100644 --- a/addons/project/wizard/project_task_delegate_view.xml +++ b/addons/project/wizard/project_task_delegate_view.xml @@ -8,18 +8,19 @@ form
+ + - - - + + - + - - + + @@ -40,7 +41,6 @@ form form - {'record_id' : active_id} new