[IMP] project: added new field "project_id" on delegrate wizard and refactor stuff of delegrate action

bzr revid: hmo@tinyerp.com-20111117150914-hkzrttoe3e2wzuvo
This commit is contained in:
Harry (OpenERP) 2011-11-17 20:39:14 +05:30
parent bf99648acc
commit be1d64f860
3 changed files with 66 additions and 42 deletions

View File

@ -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)

View File

@ -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()

View File

@ -8,18 +8,19 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Project Task Delegate">
<field name="project_id" on_change="onchange_project_id(project_id)"/>
<field name="user_id"/>
<group colspan="2" col="2">
<separator string="Delegated Task" colspan="4"/>
<field name="user_id" colspan="4"/>
<field name="planned_hours" widget="float_time" colspan="4"/>
<field name="name" colspan="4"/>
<field name="name"/>
<field name="planned_hours"/>
<separator string="New Task Description" colspan="4"/>
<field name="new_task_description" colspan="4" nolabel="1"/>
<field name="new_task_description" colspan="4" nolabel="1"/>
</group>
<group colspan="2" col="2">
<separator string="Validation Task" colspan="4"/>
<field name="planned_hours_me" widget="float_time" colspan="4"/>
<field name="prefix" string="Validation Task Title" colspan="4"/>
<field name="prefix" string="Validation Task Title"/>
<field name="planned_hours_me"/>
<field name="state" colspan="4"/>
</group>
<separator string="" colspan="4"/>
@ -40,7 +41,6 @@
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_project_task_delegate"/>
<field name="context">{'record_id' : active_id}</field>
<field name="target">new</field>
</record>