[IMP] : removed button from tree
[odoo/odoo.git] / addons / survey / wizard / survey_browse_answer.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
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 osv import osv
23 from osv import fields
24
25 class survey_browse_answer(osv.osv_memory):
26     _name = 'survey.browse.answer'
27
28     _columns = {
29         'survey_id': fields.many2one('survey', "Survey", required="1"),
30         'response_id': fields.many2one("survey.response", "Survey Answers", help="If this field is empty, all answers of the selected survey will be print."),
31     }
32
33     def action_next(self, cr, uid, ids, context=None):
34         """
35         Open Browse Response wizard. if you select only survey_id then this wizard open with all response_ids and 
36         if you select survey_id and response_id then open the particular response of the survey.
37         """
38         if context is None: context = {}
39         record = self.read(cr, uid, ids, [])
40         record = record and record[0] or {} 
41         if record['response_id']:
42             res_id = [(record.get('response_id') and record['response_id'][0])]
43         else:
44             sur_response_obj = self.pool.get('survey.response')
45             res_id = sur_response_obj.search(cr, uid, [('survey_id', '=', record['survey_id'][0])])
46         context.update({'active' : True,'survey_id' : record['survey_id'][0], 'response_id' : res_id, 'response_no' : 0})
47         search_obj = self.pool.get('ir.ui.view')
48         search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
49         return {
50             'view_type': 'form',
51             "view_mode": 'form',
52             'res_model': 'survey.question.wiz',
53             'type': 'ir.actions.act_window',
54             'target': 'new',
55             'search_view_id':search_id[0],
56             'context' : context
57          }
58
59 survey_browse_answer()
60
61 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: