[ADD] Project: Convert osv wizard to memory type (delegate task)

bzr revid: mra@tinyerp.com-20100406061355-dwkd6dxqv75cc8c8
This commit is contained in:
mra (Open ERP) 2010-04-06 11:43:55 +05:30
parent c3b1dd56df
commit a1646c335d
6 changed files with 160 additions and 110 deletions

View File

@ -33,6 +33,7 @@ works done on tasks, eso. It is able to render planning, order tasks, eso.
"init_xml" : [],
"update_xml": [
"security/project_security.xml",
"wizard/project_task_delegate_view.xml",
"security/ir.model.access.csv",
"project_data.xml",
"project_wizard.xml",

View File

@ -270,7 +270,7 @@
<button name="do_open" states="pending,draft" string="Start Task" type="object" icon="gtk-execute"/>
<button name="%(action_config_compute_remaining)d" states="done,cancelled" string="Reactivate" type="action" icon="gtk-convert" context="{'button_reactivate':True}" />
<button name="do_pending" states="open" string="Pending" type="object" icon="gtk-media-pause"/>
<button groups="base.group_extended" name="%(wizard_delegate_task)d" states="pending,open" string="Delegate" type="action" icon="gtk-sort-descending"/>
<button groups="base.group_extended" name="%(action_project_task_delegate)d" states="pending,open" string="Delegate" type="action" icon="gtk-sort-descending"/>
<button name="do_close" states="pending,open" string="Done" type="object" icon="gtk-jump-to"/>
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object" icon="gtk-cancel"/>
</group>
@ -349,7 +349,7 @@
<field name="progress" widget="progressbar" invisible="context.get('set_visible',False)"/>
<field name="state" invisible="context.get('set_visible',False)"/>
<button name="do_open" states="pending,draft,done,cancel" string="Start Task" type="object" icon="gtk-execute" help="For changing to open state" invisible="context.get('set_visible',False)"/>
<button groups="base.group_extended" name="%(wizard_delegate_task)d" states="pending,open,draft" string="Delegate" type="action" icon="gtk-execute" help="For changing to delegate state"/>
<button groups="base.group_extended" name="%(action_project_task_delegate)d" states="pending,open,draft" string="Delegate" type="action" icon="gtk-execute" help="For changing to delegate state"/>
<button name="do_close" states="draft,pending,open" string="Done" type="object" icon="gtk-jump-to" help="For changing to done state"/>
<button name="do_cancel" states="draft,open,pending" string="Cancel" type="object" icon="gtk-cancel" help="For cancelling the task"/>
</tree>

View File

@ -20,7 +20,7 @@
##############################################################################
import project_close_task
import task_delegate
import project_task_delegate
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from tools.translate import _
from osv import fields, osv
class project_task_delegate(osv.osv_memory):
_name = 'project.task.delegate'
_description = 'Task Delegate'
_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="New title of your own task to validate the work done"),
'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"),
}
def _get_name(self, cr, uid, context={}):
if 'active_id' in context:
task = self.pool.get('project.task').browse(cr, uid, context['active_id'])
if task.name.startswith(_('CHECK: ')):
newname = task.name.strip(_('CHECK: '))
else:
newname = task.name or ''
return newname
return ''
def _get_plan_hour(self, cr, uid, 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={}):
if 'active_id' in context:
task = self.pool.get('project.task').browse(cr, uid, context['active_id'])
if task.name.startswith(_('CHECK: ')):
newname = task.name.strip(_('CHECK: '))
else:
newname = task.name or ''
return _('CHECK: ')+ newname
return ''
def _get_new_desc(self, cr, uid, 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 validate(self, cr, uid, ids, context={}):
task_obj = 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': 'open',
'description': delegate_data['new_task_description'] or '',
'child_ids': [],
'work_ids': []
})
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,
})
if delegate_data['state'] == 'pending':
task_obj.do_pending(cr, uid, [task.id])
else:
task_obj.do_close(cr, uid, [task.id])
return {}
project_task_delegate()

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_project_task_delegate" model="ir.ui.view">
<field name="name">Project Task Delegate</field>
<field name="model">project.task.delegate</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Project Task Delegate">
<separator string="Delegated Task" colspan="4"/>
<field name="user_id"/>
<newline/>
<field name="planned_hours" widget="float_time"/>
<newline/>
<field name="name"/>
<newline/>
<field name="new_task_description"/>
<newline/>
<separator string="Validation Task" colspan="4"/>
<field name="planned_hours_me" widget="float_time"/>
<newline/>
<field name="prefix" />
<newline/>
<field name="state" />
<newline/>
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="_Cancel"/>
<button icon="gtk-ok" name="validate" string="Validate" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_project_task_delegate" model="ir.actions.act_window">
<field name="name">Project Task Delegate</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">project.task.delegate</field>
<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>
</data>
</openerp>

View File

@ -1,107 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
from tools import email_send as email
import pooler
from tools.translate import _
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" widget="float_time"/>
<field name="name" colspan="4"/>
<field name="new_task_description"/>
<separator string="Validation Task" colspan="4"/>
<field name="planned_hours_me" colspan="4" widget="float_time"/>
<field name="prefix" colspan="4"/>
<field name="state" colspan="4"/>
</form>"""
ask_fields = {
'name': {'string': 'Delegated Title', 'type': 'char', 'required': 'True', 'size':64, 'help':"New title of the task delegated to the user."},
'prefix': {'string': 'Your Task Title', 'type': 'char', 'required': 'True', 'size':64, 'help':"New title of your own task to validate the work done."},
'user_id': {'string':'Assign To', 'type':'many2one', 'relation': 'res.users', 'required':'True', 'help':"User you want to delegate this task to."},
'new_task_description': {'string':'New Task Description', 'type':'text', 'help':"Reinclude the description of the task in the task of the user."},
'planned_hours': {'string':'Planned Hours', 'type':'float', 'widget':'float_time', 'help':"Estimated time to close this task by the delegated user."},
'planned_hours_me': {'string':'Hours to Validate', 'type':'float', 'widget':'float_time', 'help':"Estimated time for you to validate the work done by the user to whom you delegate this task."},
'state': {'string':'Validation State', 'type':'selection', 'selection': [('pending','Pending'),('done','Done')], 'help':"New state of your own task. Pending will be reopened automatically when the delegated task is closed.", 'required':True},
}
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)
newname = data['form']['prefix'] or ''
new_task_id = task_obj.copy(cr, uid, data['id'], {
'name': data['form']['name'],
'user_id': data['form']['user_id'],
'planned_hours': data['form']['planned_hours'],
'remaining_hours': data['form']['planned_hours'],
'parent_ids': [(6, 0, [data['id']])],
'state': 'open',
'description': data['form']['new_task_description'] or '',
'child_ids': [],
'work_ids': []
})
task_obj.write(cr, uid, [data['id']], {
'remaining_hours': data['form']['planned_hours_me'],
'planned_hours': data['form']['planned_hours_me'] + (task.effective_hours or 0.0),
'name': newname,
})
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)
if task.name.startswith(_('CHECK: ')):
newname = task.name.strip(_('CHECK: '))
else:
newname = task.name or ''
return {
'name': newname,
'user_id': False,
'planned_hours': task.remaining_hours,
'planned_hours_me': 1.0,
'prefix': _('CHECK: ')+ newname,
'new_task_description': task.description,
'state': 'pending'
}
states = {
'init': {
'actions': [_ask_auto_complete],
'result': {'type':'form', 'arch':ask_form, 'fields':ask_fields, 'state':[
('end', 'Cancel'),
('valid', 'Validate', '', True)
]},
},
'valid': {
'actions': [_do_assign],
'result': {'type':'state', 'state':'end'},
}
}
wizard_delegate('project.task.delegate')