1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-TODAY OpenERP S.A. <http://www.openerp.com>
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 ##############################################################################
23 from osv import fields
24 from tools.translate import _
26 class survey_name_wiz(osv.osv_memory):
27 _name = 'survey.name.wiz'
30 'survey_id': fields.many2one('survey', 'Survey', required=True, ondelete='cascade'),
31 'page_no': fields.integer('Page Number'),
32 'note': fields.text("Description"),
33 'page': fields.char('Page Position',size = 12),
34 'transfer': fields.boolean('Page Transfer'),
35 'store_ans': fields.text('Store Answer'),
36 'response': fields.char('Answer',size=16)
43 'survey_id': lambda self,cr,uid,context:context.get('survey_id',False),
44 'store_ans': '{}' #Setting the default pattern as '{}' as the field is of type text. The field always gets the value in dict format
47 def action_next(self, cr, uid, ids, context=None):
49 Start the survey, Increment in started survey field but if set the max_response_limit of
50 survey then check the current user how many times start this survey. if current user max_response_limit
51 is reach then this user can not start this survey(Raise Exception).
53 survey_obj = self.pool.get('survey')
54 search_obj = self.pool.get('ir.ui.view')
55 if context is None: context = {}
57 this = self.browse(cr, uid, ids, context=context)[0]
58 survey_id = this.survey_id.id
59 context.update({'survey_id': survey_id, 'sur_name_id': this.id})
60 cr.execute('select count(id) from survey_history where user_id=%s\
61 and survey_id=%s' % (uid,survey_id))
63 res = cr.fetchone()[0]
64 sur_rec = survey_obj.browse(cr,uid,survey_id,context=context)
65 if sur_rec.response_user and res >= sur_rec.response_user:
66 raise osv.except_osv(_('Warning !'),_("You can not give response for this survey more than %s times") % (sur_rec))
68 if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey:
69 raise osv.except_osv(_('Warning !'),_("You can not give more response. Please contact the author of this survey for further assistance."))
71 search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
75 'res_model': 'survey.question.wiz',
76 'type': 'ir.actions.act_window',
78 'search_view_id': search_id[0],
82 def on_change_survey(self, cr, uid, ids, survey_id, context=None):
84 on change event of survey_id field, if note is available in selected survey then display this note in note fields.
88 notes = self.pool.get('survey').read(cr, uid, survey_id, ['note'])['note']
89 return {'value': {'note': notes}}
91 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: