diff options
| author | Harry (OpenERP) <hmo@tinyerp.com> | 2010-08-27 17:35:25 +0530 |
|---|---|---|
| committer | Harry (OpenERP) <hmo@tinyerp.com> | 2010-08-27 17:35:25 +0530 |
| commit | b6c39d806a0d9d36b64a7f77baabdf7d602b8bc4 (patch) | |
| tree | d06a770f5bf4a06e06db7669f872d8ac46ba5fbb | |
| parent | 710cfd96b03f796692fbecff956125f13ab767a8 (diff) | |
[REF] project: task delegation wizard
bzr revid: hmo@tinyerp.com-20100827120525-vunsccgr0ks4rxyt
| -rw-r--r-- | addons/project/project.py | 34 | ||||
| -rw-r--r-- | addons/project/wizard/project_task_delegate.py | 105 | ||||
| -rw-r--r-- | addons/project/wizard/project_task_delegate_view.xml | 4 |
3 files changed, 68 insertions, 75 deletions
diff --git a/addons/project/project.py b/addons/project/project.py index 40de82b7d5b..16d85ce1bd4 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -574,6 +574,40 @@ class task(osv.osv): self.write(cr, uid, ids, {'state': 'draft'}) return True + def do_delegate(self, cr, uid, task_id, delegate_data={}, context=None): + """ + Delegate Task to another users. + """ + if context is None: + context = {} + task = self.browse(cr, uid, task_id, context=context) + new_task_id = 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) + 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) + if delegate_data['state'] == 'pending': + self.do_pending(cr, uid, [task.id], context) + else: + self.do_close(cr, uid, [task.id], context) + user_pool = self.pool.get('res.users') + delegrate_user = user_pool.browse(cr, uid, delegate_data['user_id'], context=context) + message = _('Task ') + " '" + delegate_data['name'] + "' "+ _("is Delegated to User:") +" '"+ delegrate_user.name +"' " + self.log(cr, uid, task.id, message) + return True + def do_pending(self, cr, uid, ids, *args): self.write(cr, uid, ids, {'state': 'pending'}) for (id, name) in self.name_get(cr, uid, ids): diff --git a/addons/project/wizard/project_task_delegate.py b/addons/project/wizard/project_task_delegate.py index 535d527f45b..2ce74ceefc8 100644 --- a/addons/project/wizard/project_task_delegate.py +++ b/addons/project/wizard/project_task_delegate.py @@ -38,67 +38,54 @@ class project_task_delegate(osv.osv_memory): '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") } - def _get_name(self, cr, uid, context=None): + def default_get(self, cr, uid, fields, context=None): + """ + This function gets default values + """ + res = super(project_task_delegate, self).default_get(cr, uid, fields, context=context) if context is None: context = {} - if 'active_id' in context: - task = self.pool.get('project.task').browse(cr, uid, context['active_id']) + record_id = context and context.get('active_id', False) or False + task_pool = self.pool.get('project.task') + task = task_pool.browse(cr, uid, record_id, context=context) + project = task.project_id + manager = project.user_id or False + partner = task.partner_id or task.project_id.partner_id + + if 'name' in fields: if task.name.startswith(_('CHECK: ')): newname = str(task.name).replace(_('CHECK: '), '') else: newname = task.name or '' - return newname - return '' - - def _get_plan_hour(self, cr, uid, context=None): - if context is None: - context = {} - if 'active_id' in context: - task = self.pool.get('project.task').browse(cr, uid, context['active_id']) - return task.remaining_hours - return 0.0 - - def _get_prefix(self, cr, uid, context=None): - if context is None: - context = {} - if 'active_id' in context: - task = self.pool.get('project.task').browse(cr, uid, context['active_id']) + res.update({'name': newname}) + if 'planned_hours' in fields: + res.update({'planned_hours': task.remaining_hours or 0.0}) + if 'prefix' in fields: if task.name.startswith(_('CHECK: ')): newname = str(task.name).replace(_('CHECK: '), '') else: newname = task.name or '' - return _('CHECK: ') + newname - return '' + prefix = _('CHECK: ') + newname + res.update({'prefix': prefix}) + if 'new_task_description' in fields: + res.update({'new_task_description': task.description}) + return res - def _get_new_desc(self, cr, uid, context=None): - if context is None: - context = {} - if 'active_id' in context: - task = self.pool.get('project.task').browse(cr, uid, context['active_id']) - return task.description - return '' _defaults = { - 'name': _get_name, - 'planned_hours': _get_plan_hour, 'planned_hours_me': 1.0, - 'prefix': _get_prefix, - 'new_task_description': _get_new_desc, 'state': 'pending', } def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): - users_obj = self.pool.get('res.users') - obj_tm = users_obj.browse(cr, uid, uid, context).company_id.project_time_mode_id - tm = obj_tm and obj_tm.name or 'Hours' - res = super(project_task_delegate, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu) - + users_pool = self.pool.get('res.users') + obj_tm = users_pool.browse(cr, uid, uid, context).company_id.project_time_mode_id + tm = obj_tm and obj_tm.name or 'Hours' if tm in ['Hours','Hour']: return res eview = etree.fromstring(res['arch']) - def _check_rec(eview): if eview.attrib.get('widget','') == 'float_time': eview.set('widget','float') @@ -107,47 +94,19 @@ class project_task_delegate(osv.osv_memory): return True _check_rec(eview) - res['arch'] = etree.tostring(eview) - - for f in res['fields']: - if 'Hours' in res['fields'][f]['string']: - res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours',tm) - + for field in res['fields']: + if 'Hours' in res['fields'][field]['string']: + res['fields'][field]['string'] = res['fields'][field]['string'].replace('Hours',tm) return res - def validate(self, cr, uid, ids, context=None): + def delegate(self, cr, uid, ids, context=None): if context is None: context = {} - task_obj = self.pool.get('project.task') - user_obj = self.pool.get('res.users') + task_id = context.get('active_id', False) + task_pool = self.pool.get('project.task') delegate_data = self.read(cr, uid, ids, context=context)[0] - task = task_obj.browse(cr, uid, context['active_id'], context=context) - newname = delegate_data['prefix'] or '' - new_task_id = task_obj.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) - task_obj.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) - if delegate_data['state'] == 'pending': - task_obj.do_pending(cr, uid, [task.id], context) - else: - context.update({'mail_send': False} ) - task_obj.do_close(cr, uid, [task.id], context) - delegrate_user = user_obj.browse(cr, uid, delegate_data['user_id'], context=context) - message = _('Task ') + " '" + delegate_data['name'] + "' "+ _("is Delegated to User:") +" '"+ delegrate_user.name +"' " - self.log(cr, uid, task.id, message) + task_pool.do_delegate(cr, uid, task_id, delegate_data, context=context) return {} project_task_delegate() diff --git a/addons/project/wizard/project_task_delegate_view.xml b/addons/project/wizard/project_task_delegate_view.xml index 55ce088ad9a..7bedecd8f53 100644 --- a/addons/project/wizard/project_task_delegate_view.xml +++ b/addons/project/wizard/project_task_delegate_view.xml @@ -25,8 +25,8 @@ <group colspan="2" col="2"> </group> <group colspan="2" col="2"> - <button icon="gtk-close" special="cancel" string="Close"/> - <button icon="gtk-ok" name="validate" string="Approve" type="object"/> + <button icon="gtk-close" special="cancel" string="_Close"/> + <button icon="gtk-ok" name="delegate" string="_Delegate" type="object"/> </group> </form> </field> |
