Delegation on tasks

bzr revid: fp@tinyerp.com-6eccf820be3e3f0c304232963d7bb871b127a6b3
This commit is contained in:
Fabien Pinckaers 2007-09-07 11:52:33 +00:00
parent 1c47eb2385
commit 4c8f67388c
6 changed files with 139 additions and 15 deletions

View File

@ -93,7 +93,7 @@ class project(osv.osv):
'name': fields.char("Project name", size=128, required=True),
'active': fields.boolean('Active'),
'category_id': fields.many2one('account.analytic.account','Analytic Account'),
'priority': fields.integer('Priority'),
'priority': fields.integer('Sequence'),
'manager': fields.many2one('res.users', 'Project manager'),
'warn_manager': fields.boolean('Warn manager'),
'members': fields.many2many('res.users', 'project_user_rel', 'project_id', 'uid', 'Project members'),
@ -167,6 +167,7 @@ project_task_type()
class task(osv.osv):
_name = "project.task"
_description = "Task"
_date_name = "date_deadline"
def _hours_effect(self, cr, uid, ids, name, args, context):
task_set = ','.join(map(str, ids))
cr.execute(("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in (%s) GROUP BY task_id") % (task_set,))
@ -181,8 +182,7 @@ class task(osv.osv):
'name': fields.char('Task summary', size=128, required=True),
'active': fields.boolean('Active'),
'description': fields.text('Description'),
'cust_desc': fields.text("Description for the customer"),
'priority' : fields.selection([('4','Very Low'), ('3','Low'), ('2','Medium'), ('1','Urgent'), ('0','Very urgent')], 'Priority'),
'priority' : fields.selection([('4','Very Low'), ('3','Low'), ('2','Medium'), ('1','Urgent'), ('0','Very urgent')], 'Importance'),
'sequence': fields.integer('Sequence'),
'type': fields.many2one('project.task.type', 'Type'),
'state': fields.selection([('draft', 'Draft'),('open', 'Open'),('pending', 'Pending'), ('cancelled', 'Cancelled'), ('done', 'Done')], 'State'),
@ -190,6 +190,8 @@ class task(osv.osv):
'date_deadline': fields.datetime('Deadline'),
'date_close': fields.datetime('Date Closed', readonly=True),
'project_id': fields.many2one('project.project', 'Project', ondelete='cascade'),
'parent_id': fields.many2one('project.task', 'Parent Task'),
'child_ids': fields.one2many('project.task', 'parent_id', 'Delegated Tasks'),
'notes': fields.text('Notes'),
'start_sequence': fields.boolean('Wait for previous sequences'),
'planned_hours': fields.float('Planned hours'),
@ -229,6 +231,9 @@ class task(osv.osv):
'ref_doc2': 'project.project,%d'% (project.id,),
})
self.write(cr, uid, [task.id], {'state': 'done', 'date_close':time.strftime('%Y-%m-%d %H:%M:%S'), 'progress': 100})
if task.parent_id and task.parent_id.state in ('pending','draft'):
self.do_reopen(cr, uid, [task.parent_id.id])
if task.procurement_id:
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'mrp.procurement', task.procurement_id.id, 'subflow.done', cr)

View File

@ -77,11 +77,12 @@
<group col="11" colspan="4">
<field name="state" select="1"/>
<button name="do_draft" string="Set to draft" states="open" type="object"/>
<button name="do_draft" string="Set Draft" states="open" type="object"/>
<button name="do_open" string="Open task" states="pending,draft" type="object"/>
<button name="do_reopen" string="Re-open" states="done,cancelled" type="object"/>
<button name="do_pending" states="open" string="Set pending" type="object"/>
<button name="%(wizard_close_task)d" states="pending,open" string="Done" type="action"/>
<button name="%(wizard_delegate_task)d" states="pending,open" string="Delegate" type="action"/>
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object"/>
</group>
</page>
@ -93,12 +94,21 @@
<separator string="Notes" colspan="4"/>
<field name="invoice_id" readonly="True" colspan="4"/>
<field name="notes" colspan="4" nolabel="1"/>
<separator string="Customer Description" colspan="4"/>
<field name="cust_desc" colspan="4" nolabel="1"/>
<newline/>
<field name="type" />
<field name="billable" select="1"/>
<field name="start_sequence"/>
<field name="child_ids" colspan="4" nolabel="1">
<tree string="Delegated tasks">
<field name="name"/>
<field name="user_id"/>
<field name="date_deadline"/>
<field name="planned_hours" widget="float_time"/>
<field name="effective_hours" widget="float_time"/>
<field name="state"/>
</tree>
</field>
<field name="parent_id" colspan="4"/>
</page>
</notebook>
</form>
@ -298,10 +308,11 @@
<newline/>
<group col="11" colspan="4">
<field name="state" select="2"/>
<button name="do_draft" string="Set to draft" states="open" type="object"/>
<button name="do_open" string="Open task" states="pending,draft" type="object"/>
<button name="do_draft" string="Set Draft" states="open" type="object"/>
<button name="do_open" string="Open" states="pending,draft" type="object"/>
<button name="do_reopen" string="Re-open" states="done,cancelled" type="object"/>
<button name="do_pending" states="open" string="Set pending" type="object"/>
<button name="do_pending" states="open" string="Set Pending" type="object"/>
<button name="%(wizard_delegate_task)d" states="pending,open" string="Delegate" type="action"/>
<button name="%(wizard_close_task)d" states="pending,open" string="Done" type="action"/>
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object"/>
@ -320,8 +331,17 @@
<field name="billable" select="2"/>
<separator colspan="4" string="Notes"/>
<field colspan="4" name="notes" nolabel="1"/>
<separator colspan="4" string="Customer Description"/>
<field colspan="4" name="cust_desc" nolabel="1"/>
<field name="child_ids" colspan="4" nolabel="1">
<tree string="Delegated tasks">
<field name="name"/>
<field name="user_id"/>
<field name="date_deadline"/>
<field name="planned_hours" widget="float_time"/>
<field name="effective_hours" widget="float_time"/>
<field name="state"/>
</tree>
</field>
<field name="parent_id" colspan="4"/>
</page>
</notebook>
</form>

View File

@ -3,5 +3,6 @@
<data>
<wizard id="wizard_billing" string="Bill tasks" model="project.task" name="project.wiz_bill"/>
<wizard id="wizard_close_task" string="Close Task" model="project.task" name="project.task.close" menu="False"/>
<wizard id="wizard_delegate_task" string="Delegate Task" model="project.task" name="project.task.delegate" menu="False"/>
</data>
</terp>

View File

@ -29,4 +29,5 @@
import billing
import close_task
import task_delegate

View File

@ -79,15 +79,12 @@ class wizard_close(wizard.interface):
partner_id = task.partner_id or task.project_id.partner_id
if partner_id and partner_id.address[0].email:
email = partner_id.address[0].email
return {'description': task.cust_desc or task.description, 'email':email}
return {'description': task.description, 'email':email}
def _data_send(self, cr, uid, data, context):
task_obj = pooler.get_pool(cr.dbname).get('project.task')
if data['form']['email']:
description = data['form'].get('description', False)
if description:
val = {'cust_desc': description}
task_obj.write(cr, uid, [data['ids'][0]], val)
email_send(cr, uid, data['ids'], data['form']['email'], data['form']['description'])
return {}

View File

@ -0,0 +1,100 @@
##############################################################################
#
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import wizard
from tools import email_send as email
import pooler
ask_form = """<?xml version="1.0" ?>
<form string="Delegate this task to a user">
<separator string="Delegated Task" colspan="4"/>
<field name="user_id" colspan="4"/>
<field name="planned_hours" colspan="4"/>
<field name="name" colspan="4"/>
<separator string="Validation Task" colspan="4"/>
<field name="planned_hours_me" colspan="4"/>
<field name="prefix" colspan="4"/>
<field name="state" colspan="4"/>
</form>"""
ask_fields = {
'name': {'string': 'Title', 'type': 'char', 'required': 'True', 'size':64},
'prefix': {'string': 'Prefix of Task', 'type': 'char', 'required': 'True', 'size':64},
'user_id': {'string':'Assign To', 'type':'many2one', 'relation': 'res.users', 'required':'True'},
'planned_hours': {'string':'Planned Hours', 'type':'float', 'widget':'float_time'},
'planned_hours_me': {'string':'Hours to Validate', 'type':'float', 'widget':'float_time'},
'state': {'string':'Validation State', 'type':'selection', 'selection': [('pending','Pending'),('done','Done')]},
}
class wizard_delegate(wizard.interface):
def _do_assign(self, cr, uid, data, context):
task_obj = pooler.get_pool(cr.dbname).get('project.task')
task = task_obj.browse(cr, uid, data['id'], context)
task_obj.copy(cr, uid, data['id'], {
'name': data['form']['name'],
'user_id': data['form']['user_id'],
'planned_hours': data['form']['planned_hours'],
'parent_id': data['id'],
'state': 'open'
})
task_obj.write(cr, uid, data['id'], {
'planned_hours': data['form']['planned_hours_me'],
'name': (data['form']['prefix'] or '')+task.name
})
if data['form']['state']=='pending':
task_obj.do_pending(cr, uid, [data['id']])
else:
task_obj.do_close(cr, uid, [data['id']])
return {}
def _ask_auto_complete(self, cr, uid, data, context):
task_obj = pooler.get_pool(cr.dbname).get('project.task')
task = task_obj.browse(cr, uid, data['id'], context)
return {
'name':task.name,
'user_id': False,
'planned_hours': task.planned_hours,
'planned_hours_me': task.planned_hours / 5.0,
'prefix': 'VALIDATION: ',
'state': 'pending'
}
states = {
'init': {
'actions': [_ask_auto_complete],
'result': {'type':'form', 'arch':ask_form, 'fields':ask_fields, 'state':[
('end', 'Cancel'),
('valid', 'Validate')
]},
},
'valid': {
'actions': [_do_assign],
'result': {'type':'state', 'state':'end'},
}
}
wizard_delegate('project.task.delegate')