1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 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 ##############################################################################
21 from tools.translate import _
22 from osv import fields, osv
24 class project_compute_phases(osv.osv_memory):
25 _name = 'project.compute.phases'
26 _description = 'Project Compute Phases'
28 'target_project': fields.selection([
29 ('all', 'Compute All My Projects'),
30 ('one', 'Compute a Single Project'),
31 ], 'Action', required=True),
32 'project_id': fields.many2one('project.project', 'Project')
35 'target_project': 'one'
38 def check_selection(self, cr, uid, ids, context=None):
39 return self.compute_date(cr, uid, ids, context=context)
41 def compute_date(self, cr, uid, ids, context=None):
43 Compute the phases for scheduling.
45 project_pool = self.pool.get('project.project')
46 data = self.read(cr, uid, ids, [], context=context)[0]
47 if not data['project_id'] and data['target_project'] == 'one':
48 raise osv.except_osv(_('Error!'), _('Please specify a project to schedule.'))
50 if data['target_project'] == 'one':
51 project_ids = [data['project_id'][0]]
53 project_ids = project_pool.search(cr, uid, [('user_id','=',uid)], context=context)
55 project_pool.schedule_phases(cr, uid, project_ids, context=context)
56 return self._open_phases_list(cr, uid, data, context=context)
58 def _open_phases_list(self, cr, uid, data, context=None):
60 Return the scheduled phases list.
64 mod_obj = self.pool.get('ir.model.data')
65 act_obj = self.pool.get('ir.actions.act_window')
66 result = mod_obj._get_id(cr, uid, 'project_long_term', 'act_project_phase')
67 id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
68 result = act_obj.read(cr, uid, [id], context=context)[0]
69 result['target'] = 'current'
70 project_id = data.get('project_id') and data.get('project_id')[0] or False
71 result['context'] = {"search_default_project_id":project_id, "default_project_id":project_id, "search_default_current": 1}
74 project_compute_phases()
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: