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
23 from osv import fields, osv
24 from tools.translate import _
26 class project_task_reevaluate(osv.osv_memory):
27 _name = 'project.task.reevaluate'
29 def _get_remaining(self,cr, uid, context=None):
32 active_id = context.get('active_id', False)
35 res = self.pool.get('project.task').browse(cr, uid, active_id, context=context).remaining_hours
39 'remaining_hours' : fields.float('Remaining Hours', digits=(16,2), help="Put here the remaining hours required to close the task."),
43 'remaining_hours': _get_remaining,
46 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
47 res = super(project_task_reevaluate, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu)
48 users_pool = self.pool.get('res.users')
49 time_mode = users_pool.browse(cr, uid, uid, context).company_id.project_time_mode_id
50 time_mode_name = time_mode and time_mode.name or 'Hours'
51 if time_mode_name in ['Hours','Hour']:
54 eview = etree.fromstring(res['arch'])
56 def _check_rec(eview):
57 if eview.attrib.get('widget','') == 'float_time':
58 eview.set('widget','float')
65 res['arch'] = etree.tostring(eview)
67 for field in res['fields']:
68 if 'Hours' in res['fields'][field]['string']:
69 res['fields'][field]['string'] = res['fields'][field]['string'].replace('Hours',time_mode_name)
72 def compute_hours(self, cr, uid, ids, context=None):
75 data = self.browse(cr, uid, ids, context=context)[0]
76 task_pool = self.pool.get('project.task')
77 task_id = context.get('active_id', False)
79 task_pool.write(cr, uid, task_id, {'remaining_hours': data.remaining_hours})
80 if context.get('button_reactivate', False):
81 task_pool.do_reopen(cr, uid, [task_id], context=context)
82 return {'type': 'ir.actions.act_window_close'}
83 project_task_reevaluate()