[FIX]: project task - set to done - pop up to small
[odoo/odoo.git] / addons / project / wizard / project_task_delegate.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from lxml import etree
23
24 from tools.translate import _
25 from osv import fields, osv
26
27 class project_task_delegate(osv.osv_memory):
28     _name = 'project.task.delegate'
29     _description = 'Task Delegate'
30
31     _columns = {
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")
39     }
40
41     def default_get(self, cr, uid, fields, context=None):
42         """
43         This function gets default values
44         """
45         res = super(project_task_delegate, self).default_get(cr, uid, fields, context=context)
46         if context is None:
47             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)
51
52         if 'name' in fields:
53             if task.name.startswith(_('CHECK: ')):
54                 newname = str(task.name).replace(_('CHECK: '), '')
55             else:
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: '), '')
63             else:
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})
69         return res
70
71
72     _defaults = {
73        'planned_hours_me': 1.0,
74        'state': 'pending',
75     }
76
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']:
83             return res
84
85         eview = etree.fromstring(res['arch'])
86         def _check_rec(eview):
87             if eview.attrib.get('widget','') == 'float_time':
88                 eview.set('widget','float')
89             for child in eview:
90                 _check_rec(child)
91             return True
92
93         _check_rec(eview)
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)
98         return res
99
100     def delegate(self, cr, uid, ids, context=None):
101         if context is None:
102             context = {}
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)
107         return {}
108
109 project_task_delegate()