1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from lxml import etree
24 from tools.translate import _
25 from osv import fields, osv
27 class project_task_delegate(osv.osv_memory):
28 _name = 'project.task.delegate'
29 _description = 'Task Delegate'
32 'name': fields.char('Delegated Title', size=64, required=True, help="New title of the task delegated to the user"),
33 'prefix': fields.char('Your Task Title', size=64, required=True, help="Title for your validation task"),
34 'user_id': fields.many2one('res.users', 'Assign To', required=True, help="User you want to delegate this task to"),
35 'new_task_description': fields.text('New Task Description', help="Reinclude the description of the task in the task of the user"),
36 'planned_hours': fields.float('Planned Hours', help="Estimated time to close this task by the delegated user"),
37 '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"),
38 '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")
41 def default_get(self, cr, uid, fields, context=None):
43 This function gets default values
45 res = super(project_task_delegate, self).default_get(cr, uid, fields, context=context)
48 record_id = context and context.get('active_id', False) or False
49 task_pool = self.pool.get('project.task')
50 task = task_pool.browse(cr, uid, record_id, context=context)
53 if task.name.startswith(_('CHECK: ')):
54 newname = str(task.name).replace(_('CHECK: '), '')
56 newname = task.name or ''
57 res.update({'name': newname})
58 if 'planned_hours' in fields:
59 res.update({'planned_hours': task.remaining_hours or 0.0})
60 if 'prefix' in fields:
61 if task.name.startswith(_('CHECK: ')):
62 newname = str(task.name).replace(_('CHECK: '), '')
64 newname = task.name or ''
65 prefix = _('CHECK: ') + newname
66 res.update({'prefix': prefix})
67 if 'new_task_description' in fields:
68 res.update({'new_task_description': task.description})
73 'planned_hours_me': 1.0,
77 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
78 res = super(project_task_delegate, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu)
79 users_pool = self.pool.get('res.users')
80 obj_tm = users_pool.browse(cr, uid, uid, context).company_id.project_time_mode_id
81 tm = obj_tm and obj_tm.name or 'Hours'
82 if tm in ['Hours','Hour']:
85 eview = etree.fromstring(res['arch'])
86 def _check_rec(eview):
87 if eview.attrib.get('widget','') == 'float_time':
88 eview.set('widget','float')
94 res['arch'] = etree.tostring(eview)
95 for field in res['fields']:
96 if 'Hours' in res['fields'][field]['string']:
97 res['fields'][field]['string'] = res['fields'][field]['string'].replace('Hours',tm)
100 def delegate(self, cr, uid, ids, context=None):
103 task_id = context.get('active_id', False)
104 task_pool = self.pool.get('project.task')
105 delegate_data = self.read(cr, uid, ids, context=context)[0]
106 task_pool.do_delegate(cr, uid, task_id, delegate_data, context=context)
109 project_task_delegate()