c07f1ae81be0825dacf61b4a00594217c3987c6c
[odoo/odoo.git] / addons / project_long_term / wizard / project_compute_phases.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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 from tools.translate import _
22 from osv import fields, osv
23
24 class project_compute_phases(osv.osv_memory):
25     _name = 'project.compute.phases'
26     _description = 'Project Compute Phases'
27     _columns = {
28        'target_project': fields.selection([('all', 'Compute All Projects'),
29                                            ('one', 'Compute a Single Project'),
30                                            ], 'Schedule', required = True),
31
32         'project_id': fields.many2one('project.project', 'Project')
33     }
34
35     _defaults = {
36         'target_project': 'all'
37     }
38
39     def check_selection(self, cr, uid, ids, context=None):
40         return self.compute_date(cr, uid, ids, context=context)
41
42     
43     def compute_date(self, cr, uid, ids, context=None):
44         """
45         Compute the phases for scheduling.
46         """
47         project_pool = self.pool.get('project.project')
48         data = self.read(cr, uid, ids, [], context=context)[0]
49         if not data['project_id'] and data['target_project'] == 'one':
50             raise osv.except_osv(_('Error!'), _('Please Specify Project to be schedule'))
51
52         if data['project_id']:        # If project mentioned find its phases
53             project_ids = [data['project_id']]
54         else:                        # Else take all the draft,open,pending states phases
55             project_ids = project_pool.search(cr, uid, [], context=context)
56
57         project_pool.schedule_phases(cr, uid, project_ids, context=context)
58         return self._open_phases_list(cr, uid, data, context=context)
59
60     def _open_phases_list(self, cr, uid, data, context=None):
61         """
62         Return the scheduled phases list.
63         """
64         if context is None:
65             context = {}
66         mod_obj = self.pool.get('ir.model.data')
67         act_obj = self.pool.get('ir.actions.act_window')
68         result = mod_obj._get_id(cr, uid, 'project_long_term', 'act_project_phase')
69         id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
70         result = act_obj.read(cr, uid, [id], context=context)[0]
71         result['target'] = 'current'
72         result['context'] = {"search_default_project_id":data['project_id'], "default_project_id":data['project_id'], "search_default_responsible_id":uid, "search_default_current": 1}
73         return result
74
75 project_compute_phases()
76 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: