[IMP] improves the reporting view Expenses Analysis (add some measures to the table...
[odoo/odoo.git] / addons / survey / wizard / survey_answer.py
1 ## -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 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
22 import base64
23 import datetime
24 from lxml import etree
25 import os
26 from time import strftime
27
28 from openerp import tools
29 from openerp.modules.module import get_module_resource
30 from openerp.osv import fields, osv
31 import openerp.report
32 from openerp.tools import to_xml
33 from openerp.tools.translate import _
34 from openerp.tools.safe_eval import safe_eval
35
36 class survey_question_wiz(osv.osv_memory):
37     _name = 'survey.question.wiz'
38     _columns = {
39         'name': fields.integer('Number'),
40     }
41
42     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
43         """
44         Fields View Get method :- generate the new view and display the survey pages of selected survey.
45         """
46         if context is None:
47             context = {}
48         result = super(survey_question_wiz, self).fields_view_get(cr, uid, view_id, \
49                                         view_type, context, toolbar,submenu)
50
51         surv_name_wiz = self.pool.get('survey.name.wiz')
52         survey_obj = self.pool.get('survey')
53         page_obj = self.pool.get('survey.page')
54         que_obj = self.pool.get('survey.question')
55         ans_obj = self.pool.get('survey.answer')
56         sur_response_obj = self.pool.get('survey.response')
57         que_col_head = self.pool.get('survey.question.column.heading')
58         user_obj = self.pool.get('res.users')
59         mail_message = self.pool.get('mail.message')
60         
61         if view_type in ['form']:
62             wiz_id = 0
63             sur_name_rec = None
64             if 'sur_name_id' in context:
65                 sur_name_rec = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context)
66             elif 'survey_id' in context:
67                 res_data = {
68                     'survey_id': context.get('survey_id', False),
69                     'page_no': -1,
70                     'page': 'next',
71                     'transfer': 1,
72                     'response': 0
73                 }
74                 wiz_id = surv_name_wiz.create(cr, uid, res_data)
75                 sur_name_rec = surv_name_wiz.browse(cr, uid, wiz_id, context=context)
76                 context.update({'sur_name_id' :wiz_id})
77
78             if context.has_key('active_id'):
79                 context.pop('active_id')
80
81             survey_id = context.get('survey_id', False)
82             if not survey_id:
83                 # Try one more time to find it
84                 if sur_name_rec and sur_name_rec.survey_id:
85                     survey_id = sur_name_rec.survey_id.id
86                 else:
87                     # raise osv.except_osv(_('Error!'), _("Cannot locate survey for the question wizard!"))
88                     # If this function is called without a survey_id in
89                     # its context, it makes no sense to return any view.
90                     # Just return the default, empty view for this object,
91                     # in order to please random calls to this fn().
92                     return super(survey_question_wiz, self).\
93                                 fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context,
94                                         toolbar=toolbar, submenu=submenu)
95             sur_rec = survey_obj.browse(cr, uid, survey_id, context=context)
96             p_id = map(lambda x:x.id, sur_rec.page_ids)
97             total_pages = len(p_id)
98             pre_button = False
99             readonly = 0
100
101             if context.get('response_id', False) \
102                             and int(context['response_id'][0]) > 0:
103                 readonly = 1
104
105             if not sur_name_rec.page_no + 1 :
106                 surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'store_ans':{}})
107
108             sur_name_read = surv_name_wiz.browse(cr, uid, context['sur_name_id'], context=context)
109             page_number = int(sur_name_rec.page_no)
110             if sur_name_read.transfer or not sur_name_rec.page_no + 1:
111                 surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'transfer':False})
112                 flag = False
113                 fields = {}
114                 if sur_name_read.page == "next" or sur_name_rec.page_no == -1:
115                     if total_pages > sur_name_rec.page_no + 1:
116                         if ((context.has_key('active') and not context.get('active', False)) \
117                                     or not context.has_key('active')) and not sur_name_rec.page_no + 1:
118                             if sur_rec.state != "open" :
119                                 raise osv.except_osv(_('Warning!'),_("You cannot answer because the survey is not open."))
120                             cr.execute('select count(id) from survey_history where user_id=%s\
121                                                     and survey_id=%s', (uid,survey_id))
122                             res = cr.fetchone()[0]
123                             user_limit = survey_obj.browse(cr, uid, survey_id)
124                             user_limit = user_limit.response_user
125                             if user_limit and res >= user_limit:
126                                 raise osv.except_osv(_('Warning!'),_("You cannot answer this survey more than %s times.") % (user_limit))
127
128                         if sur_rec.max_response_limit and sur_rec.max_response_limit <= sur_rec.tot_start_survey and not sur_name_rec.page_no + 1:
129                             survey_obj.write(cr, uid, survey_id, {'state':'close', 'date_close':strftime("%Y-%m-%d %H:%M:%S")})
130
131                         p_id = p_id[sur_name_rec.page_no + 1]
132                         surv_name_wiz.write(cr, uid, [context['sur_name_id'],], {'page_no' : sur_name_rec.page_no + 1})
133                         flag = True
134                         page_number += 1
135                     if sur_name_rec.page_no > - 1:
136                         pre_button = True
137                     else:
138                         flag = True
139                 else:
140                     if sur_name_rec.page_no != 0:
141                         p_id = p_id[sur_name_rec.page_no - 1]
142                         surv_name_wiz.write(cr, uid, [context['sur_name_id'],],\
143                                              {'page_no' : sur_name_rec.page_no - 1})
144                         flag = True
145                         page_number -= 1
146
147                     if sur_name_rec.page_no > 1:
148                         pre_button = True
149                 if flag:
150                     pag_rec = page_obj.browse(cr, uid, p_id, context=context)
151                     note = False
152                     question_ids = []
153                     if pag_rec:
154                         title = pag_rec.title
155                         note = pag_rec.note
156                         question_ids = pag_rec.question_ids
157                     else:
158                         title = sur_rec.title
159                     xml_form = etree.Element('form', {'string': tools.ustr(title)})
160                     if context.has_key('active') and context.get('active',False) and context.has_key('edit'):
161                         context.update({'page_id' : tools.ustr(p_id),'page_number' : sur_name_rec.page_no , 'transfer' : sur_name_read.transfer})
162                         xml_group3 = etree.SubElement(xml_form, 'group', {'col': '4', 'colspan': '4'})
163                         etree.SubElement(xml_group3, 'button', {'string' :'Add Page','icon': "gtk-new", 'type' :'object','name':"action_new_page", 'context' : tools.ustr(context)})
164                         etree.SubElement(xml_group3, 'button', {'string' :'Edit Page','icon': "gtk-edit", 'type' :'object','name':"action_edit_page", 'context' : tools.ustr(context)})
165                         etree.SubElement(xml_group3, 'button', {'string' :'Delete Page','icon': "gtk-delete", 'type' :'object','name':"action_delete_page", 'context' : tools.ustr(context)})
166                         etree.SubElement(xml_group3, 'button', {'string' :'Add Question','icon': "gtk-new", 'type' :'object','name':"action_new_question", 'context' : tools.ustr(context)})
167
168                     # FP Note
169                     xml_group = xml_form
170
171                     if context.has_key('response_id') and context.get('response_id', False) \
172                          and int(context.get('response_id',0)[0]) > 0:
173                         # TODO: l10n, cleanup this code to make it readable. Or template?
174                         xml_group = etree.SubElement(xml_form, 'group', {'col': '40', 'colspan': '4'})
175                         record = sur_response_obj.browse(cr, uid, context['response_id'][context['response_no']])
176                         etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(_('Answer Of :- ') + record.user_id.name + _(',  Date :- ') + record.date_create.split('.')[0]  )), 'align':"0.0"})
177                         etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(_(" Answer :- ") + str(context.get('response_no',0) + 1) +"/" + str(len(context.get('response_id',0))) )), 'align':"0.0"})
178                         if context.get('response_no',0) > 0:
179                             etree.SubElement(xml_group, 'button', {'colspan':"1",'icon':"gtk-go-back",'name':"action_forward_previous",'string': tools.ustr("Previous Answer"),'type':"object"})
180                         if context.get('response_no',0) + 1 < len(context.get('response_id',0)):
181                             etree.SubElement(xml_group, 'button', {'colspan':"1",'icon': "gtk-go-forward", 'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context)})
182
183                     if wiz_id:
184                         fields["wizardid_" + str(wiz_id)] = {'type':'char', 'size' : 255, 'string':"", 'views':{}}
185                         etree.SubElement(xml_form, 'field', {'invisible':'1','name': "wizardid_" + str(wiz_id),'default':str(lambda *a: 0),'modifiers':'{"invisible":true}'})
186
187                     if note:
188                         xml_group_note = etree.SubElement(xml_form, 'group', {'col': '1','colspan': '4'})
189                         for que_test in note.split('\n'):
190                             etree.SubElement(xml_group_note, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"})
191                     que_ids = question_ids
192                     qu_no = 0
193
194                     for que in que_ids:
195                         qu_no += 1
196                         que_rec = que_obj.browse(cr, uid, que.id, context=context)
197                         descriptive_text = ""
198                         separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec.question)
199                         if ((context.has_key('active') and not context.get('active',False)) or not context.has_key('active')) and que_rec.is_require_answer:
200                             star = '*'
201                         else:
202                             star = ''
203                         if context.has_key('active') and context.get('active',False) and \
204                                     context.has_key('edit'):
205                             etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)})
206
207                             xml_group1 = etree.SubElement(xml_form, 'group', {'col': '2', 'colspan': '2'})
208                             context.update({'question_id' : tools.ustr(que.id),'page_number': sur_name_rec.page_no , 'transfer' : sur_name_read.transfer, 'page_id' : p_id})
209                             etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-edit", 'type' :'object', 'name':"action_edit_question", 'context' : tools.ustr(context)})
210                             etree.SubElement(xml_group1, 'button', {'string':'','icon': "gtk-delete", 'type' :'object','name':"action_delete_question", 'context' : tools.ustr(context)})
211                         else:
212                             etree.SubElement(xml_form, 'newline')
213                             etree.SubElement(xml_form, 'separator', {'string': star+to_xml(separator_string)})
214
215                         ans_ids = que_rec.answer_choice_ids
216                         xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'})
217
218                         if que_rec.type == 'multiple_choice_only_one_ans':
219                             selection = []
220                             for ans in ans_ids:
221                                 selection.append((tools.ustr(ans.id), ans.answer))
222                             xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'})
223                             etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_selection"})
224                             fields[tools.ustr(que.id) + "_selection"] = {'type':'selection', 'selection' :selection, 'string':_('Answer')}
225
226                         elif que_rec.type == 'multiple_choice_multiple_ans':
227                             xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
228                             for ans in ans_ids:
229                                 etree.SubElement(xml_group, 'field', {'readonly':str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
230                                 fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'boolean', 'string':ans.answer}
231
232                         elif que_rec.type in ['matrix_of_choices_only_one_ans', 'rating_scale']:
233                             if que_rec.comment_column:
234                                 col = "4"
235                                 colspan = "4"
236                             else:
237                                col = "2"
238                                colspan = "2"
239                             xml_group = etree.SubElement(xml_group, 'group', {'col': tools.ustr(col), 'colspan': tools.ustr(colspan)})
240                             for row in ans_ids:
241                                 etree.SubElement(xml_group, 'newline')
242                                 etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection_" + tools.ustr(row.id),'string':to_xml(tools.ustr(row.answer))})
243                                 selection = [('','')]
244                                 for col in que_rec.column_heading_ids:
245                                     selection.append((str(col.id), col.title))
246                                 fields[tools.ustr(que.id) + "_selection_" + tools.ustr(row.id)] = {'type':'selection', 'selection' : selection, 'string': "Answer"}
247                                 if que_rec.comment_column:
248                                    fields[tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec.column_name), 'views':{}}
249                                    etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_"+tools.ustr(row.id)+ "_field"})
250
251                         elif que_rec.type == 'matrix_of_choices_only_multi_ans':
252                             xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'})
253                             etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'})
254                             for col in que_rec.column_heading_ids:
255                                 etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'})
256                             for row in ans_ids:
257                                 etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer)) +' :-', 'align': '0.0'})
258                                 for col in que_col_head.browse(cr, uid, [head.id for head in  que_rec.column_heading_ids]):
259                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel':"1"})
260                                     fields[tools.ustr(que.id) + "_" + tools.ustr(row.id)  + "_" + tools.ustr(col.id)] = {'type':'boolean', 'string': col.title}
261
262                         elif que_rec.type == 'matrix_of_drop_down_menus':
263                             xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'})
264                             etree.SubElement(xml_group, 'separator', {'string': '.','colspan': '1'})
265                             for col in que_rec.column_heading_ids:
266                                 etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'})
267                             for row in ans_ids:
268                                 etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(row.answer))+' :-', 'align': '0.0'})
269                                 for col in que_rec.column_heading_ids:
270                                     selection = []
271                                     if col.menu_choice:
272                                         for item in col.menu_choice.split('\n'):
273                                             if item and not item.strip() == '': selection.append((item ,item))
274                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id),'nolabel':'1'})
275                                     fields[tools.ustr(que.id) + "_" + tools.ustr(row.id)  + "_" + tools.ustr(col.id)] = {'type':'selection', 'string': col.title, 'selection':selection}
276
277                         elif que_rec.type == 'multiple_textboxes':
278                             xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
279                             type = "char"
280                             if que_rec.is_validation_require:
281                                 if que_rec.validation_type in ['must_be_whole_number']:
282                                     type = "integer"
283                                 elif que_rec.validation_type in ['must_be_decimal_number']:
284                                     type = "float"
285                                 elif que_rec.validation_type in ['must_be_date']:
286                                     type = "date"
287                             for ans in ans_ids:
288                                 etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
289                                 if type == "char" :
290                                     fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer}
291                                 else:
292                                     fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string':ans.answer}
293
294                         elif que_rec.type == 'numerical_textboxes':
295                             xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
296                             for ans in ans_ids:
297                                 etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"})
298                                 fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type':'integer', 'string':ans.answer}
299
300                         elif que_rec.type == 'date':
301                             xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
302                             for ans in ans_ids:
303                                 etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
304                                 fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'date', 'string':ans.answer}
305
306                         elif que_rec.type == 'date_and_time':
307                             xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
308                             for ans in ans_ids:
309                                 etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)})
310                                 fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type':'datetime', 'string':ans.answer}
311
312                         elif que_rec.type == 'descriptive_text':
313                             if que_rec.descriptive_text:
314                                 for que_test in que_rec.descriptive_text.split('\n'):
315                                     etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"})
316
317                         elif que_rec.type == 'single_textbox':
318                             etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel':"1" ,'colspan':"4"})
319                             fields[tools.ustr(que.id) + "_single"] = {'type':'char', 'size': 255, 'string':"single_textbox", 'views':{}}
320
321                         elif que_rec.type == 'comment':
322                             etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel':"1" ,'colspan':"4"})
323                             fields[tools.ustr(que.id) + "_comment"] = {'type':'text', 'string':"Comment/Eassy Box", 'views':{}}
324
325                         elif que_rec.type == 'table':
326                             xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'})
327                             for col in que_rec.column_heading_ids:
328                                 etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title),'colspan': '1'})
329                             for row in range(0,que_rec.no_of_rows):
330                                 for col in que_rec.column_heading_ids:
331                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row), 'nolabel':"1"})
332                                     fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}}
333
334                         elif que_rec.type == 'multiple_textboxes_diff_type':
335                             xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
336                             for ans in ans_ids:
337                                 if ans.type == "email" :
338                                     fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer}
339                                     etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
340                                 else:
341                                     etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width':"300",'colspan': '1','name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"})
342                                     if ans.type == "char" :
343                                         fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'char', 'size':255, 'string':ans.answer}
344                                     elif ans.type in ['integer','float','date','datetime']:
345                                         fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(ans.type), 'string':ans.answer}
346                                     else:
347                                         selection = []
348                                         if ans.menu_choice:
349                                             for item in ans.menu_choice.split('\n'):
350                                                 if item and not item.strip() == '': selection.append((item ,item))
351                                         fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans.answer}
352
353                         if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale'] and que_rec.is_comment_require:
354                             if que_rec.type in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec.comment_field_type in ['char','text'] and que_rec.make_comment_field:
355                                 etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan':"4"})
356                                 fields[tools.ustr(que.id) + "_otherfield"] = {'type':'boolean', 'string':que_rec.comment_label, 'views':{}}
357                                 if que_rec.comment_field_type == 'char':
358                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"})
359                                     fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}}
360                                 elif que_rec.comment_field_type == 'text':
361                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"})
362                                     fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}}
363                             else:
364                                 if que_rec.comment_field_type == 'char':
365                                     etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"})
366                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"})
367                                     fields[tools.ustr(que.id) + "_other"] = {'type': 'char', 'string': '', 'size':255, 'views':{}}
368                                 elif que_rec.comment_field_type == 'text':
369                                     etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_rec.comment_label)),'colspan':"4"})
370                                     etree.SubElement(xml_group, 'field', {'readonly' :str(readonly), 'name': tools.ustr(que.id) + "_other", 'nolabel':"1" ,'colspan':"4"})
371                                     fields[tools.ustr(que.id) + "_other"] = {'type': 'text', 'string': '', 'views':{}}
372
373                     xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width':"100%"})
374
375                     if pre_button:
376                         etree.SubElement(xml_footer, 'label', {'string': ""})
377                         etree.SubElement(xml_footer, 'button', {'name':"action_previous",'string':_('Previous'),'type':"object"})
378                     but_string = _('Next')
379                     if int(page_number) + 1 == total_pages:
380                         but_string = _('Done')
381                     if context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages and context.has_key('response_id') and context.has_key('response_no') and  context.get('response_no',0) + 1 == len(context.get('response_id',0)):
382                         etree.SubElement(xml_footer, 'label', {'string': ""})
383                         etree.SubElement(xml_footer, 'button', {'special' : 'cancel','string': tools.ustr("Done") ,'context' : tools.ustr(context), 'class':"oe_highlight"})
384                     elif context.has_key('active') and context.get('active', False) and int(page_number) + 1 == total_pages and context.has_key('response_id'):
385                         etree.SubElement(xml_footer, 'label', {'string': ""})
386                         etree.SubElement(xml_footer, 'button', {'name':"action_forward_next",'string': tools.ustr("Next Answer") ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"})
387                     elif context.has_key('active') and context.get('active',False) and int(page_number) + 1 == total_pages:
388                         etree.SubElement(xml_footer, 'label', {'string': ""})
389                         etree.SubElement(xml_footer, 'button', {'special': "cancel", 'string' : 'Done', 'context' : tools.ustr(context), 'class':"oe_highlight"})
390                     else:
391                         etree.SubElement(xml_footer, 'label', {'string': ""})
392                         etree.SubElement(xml_footer, 'button', {'name':"action_next",'string': tools.ustr(but_string) ,'type':"object",'context' : tools.ustr(context), 'class':"oe_highlight"})
393                     etree.SubElement(xml_footer, 'label', {'string': _('or')})
394                     etree.SubElement(xml_footer, 'button', {'special': "cancel",'string':_('Exit'),'class':"oe_link"})
395                     etree.SubElement(xml_footer, 'label', {'string': tools.ustr(page_number+ 1) + "/" + tools.ustr(total_pages), 'class':"oe_survey_title_page oe_right"})
396
397                     root = xml_form.getroottree()
398                     result['arch'] = etree.tostring(root)
399                     result['fields'] = fields
400                     result['context'] = context
401                 else:
402                     survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec.tot_comp_survey + 1})
403                     sur_response_obj.write(cr, uid, [sur_name_read.response], {'state' : 'done'})
404
405                     # mark the survey request as done; call 'survey_req_done' on its actual model
406                     if context.get('active_model') in self.pool:
407                         survey_req_obj = self.pool[context.get('active_model')]
408                         if hasattr(survey_req_obj, 'survey_req_done'): 
409                             survey_req_obj.survey_req_done(cr, uid, context.get('active_ids', []), context=context)
410
411                     if sur_rec.send_response:
412                         survey_data = survey_obj.browse(cr, uid, survey_id)
413                         response_id = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))['response']
414                         report = self.create_report(cr, uid, [survey_id], 'report.survey.browse.response', survey_data.title,context)
415                         attachments = {}
416                         pdf_filename = get_module_resource('survey', 'report') + survey_data.title + ".pdf"
417                         if os.path.exists(pdf_filename):
418                             file = open(pdf_filename)
419                             file_data = ""
420                             while 1:
421                                 line = file.readline()
422                                 file_data += line
423                                 if not line:
424                                     break
425
426                             attachments[survey_data.title + ".pdf"] = file_data
427                             file.close()
428                             os.remove(get_module_resource('survey', 'report') + survey_data.title + ".pdf")
429                         context.update({'response_id':response_id})
430                         user_email = user_obj.browse(cr, uid, uid, context).email
431                         resp_email = survey_data.responsible_id and survey_data.responsible_id.email or False
432
433                         if user_email and resp_email:
434                             user_name = user_obj.browse(cr, uid, uid, context=context).name
435                             mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_name) + " has given the Response Of " + survey_data.title + " Survey.\nThe Response has been attached herewith.\n\n Thanks."
436                             vals = {'state': 'outgoing',
437                                     'subject': "Survey Answer Of " + user_name,
438                                     'body_html': '<pre>%s</pre>' % mail,
439                                     'email_to': [resp_email],
440                                     'email_from': user_email}
441                             if attachments:
442                                 vals['attachment_ids'] = [(0,0,{'name': a_name,
443                                                                 'datas_fname': a_name,
444                                                                 'datas': str(a_content).encode('base64')})
445                                                                 for a_name, a_content in attachments.items()]
446                             self.pool.get('mail.mail').create(cr, uid, vals, context=context)
447
448                     xml_form = etree.Element('form', {'string': _('Complete Survey Answer')})
449                     xml_footer = etree.SubElement(xml_form, 'footer', {'col': '6', 'colspan': '4' ,'class': 'oe_survey_title_height'})
450
451                     etree.SubElement(xml_form, 'separator', {'string': 'Survey Completed', 'colspan': "4"})
452                     etree.SubElement(xml_form, 'label', {'string': 'Thanks for your Answer'})
453                     etree.SubElement(xml_form, 'newline')
454                     etree.SubElement(xml_footer, 'button', {'special':"cancel",'string':"OK",'colspan':"2",'class':'oe_highlight'})
455                     root = xml_form.getroottree()
456                     result['arch'] = etree.tostring(root)
457                     result['fields'] = {}
458                     result['context'] = context
459         return result
460
461     def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
462         """
463         If any user give answer of survey then last create report of this answer and if 'E-mail Notification on Answer' set True in survey  then send mail on responsible person of this survey and attach survey answer report in pdf format.
464         """
465         if not report_name or not res_ids:
466             return (False, Exception('Report name and Resources ids are required !!!'))
467         try:
468             uid = 1
469             result, format = openerp.report.render_report(cr, uid, res_ids, report_name[len('report.'):], {}, context)
470             ret_file_name = get_module_resource('survey', 'report') + file_name + '.pdf'
471             fp = open(ret_file_name, 'wb+');
472             fp.write(result);
473             fp.close();
474             
475             # hr.applicant: if survey answered directly in system: attach report to applicant
476             if context.get('active_model') == 'hr.applicant':
477                 self.pool.get('hr.applicant').write(cr,uid,[context.get('active_ids')[0]],{'response':context.get('response_id')})
478                 result = base64.b64encode(result)
479                 file_name = file_name + '.pdf'
480                 ir_attachment = self.pool.get('ir.attachment').create(cr, uid, 
481                                                                       {'name': file_name,
482                                                                        'datas': result,
483                                                                        'datas_fname': file_name,
484                                                                        'res_model': context.get('active_model'),
485                                                                        'res_id': context.get('active_ids')[0]},
486                                                                       context=context)
487
488         except Exception,e:
489             return (False, str(e))
490         return (True, ret_file_name)
491
492     def default_get(self, cr, uid, fields_list, context=None):
493         """
494         Assign Default value in particular field. If Browse Answers wizard run then read the value into database and Assigne to a particular fields.
495         """
496         value = {}
497         if context is None:
498             context = {}
499         for field in fields_list:
500             if field.split('_')[0] == 'progress':
501                 tot_page_id = self.pool.get('survey').browse(cr, uid, context.get('survey_id',False))
502                 tot_per = (float(100) * (int(field.split('_')[2]) + 1) / len(tot_page_id.page_ids))
503                 value[field] = tot_per
504         response_obj = self.pool.get('survey.response')
505         surv_name_wiz = self.pool.get('survey.name.wiz')
506         if context.has_key('response_id') and context.get('response_id') and int(context['response_id'][0]) > 0:
507             data = super(survey_question_wiz, self).default_get(cr, uid, fields_list, context)
508             response_ans = response_obj.browse(cr, uid, context['response_id'][context['response_no']])
509             fields_list.sort()
510
511             for que in response_ans.question_ids:
512                 for field in fields_list:
513                     if field.split('_')[0] != "progress" and field.split('_')[0] == str(que.question_id.id):
514                         if que.response_answer_ids and len(field.split('_')) == 4 and field.split('_')[1] == "commentcolumn" and field.split('_')[3] == "field":
515                             for ans in que.response_answer_ids:
516                                 if str(field.split('_')[2]) == str(ans.answer_id.id):
517                                     value[field] = ans.comment_field
518
519                         if que.response_table_ids and len(field.split('_')) == 4 and field.split('_')[1] == "table":
520                             for ans in que.response_table_ids:
521                                 if str(field.split('_')[2]) == str(ans.column_id.id) and str(field.split('_')[3]) ==  str(ans.name):
522                                     value[field] = ans.value
523
524                         if que.comment and (field.split('_')[1] == "comment" or field.split('_')[1] == "other"):
525                             value[field] = tools.ustr(que.comment)
526
527                         elif que.single_text and field.split('_')[1] == "single":
528                             value[field] = tools.ustr(que.single_text)
529
530                         elif que.response_answer_ids and len(field.split('_')) == 3 and field.split('_')[1] == "selection":
531                             for ans in que.response_answer_ids:
532                                 if str(field.split('_')[2]) == str( ans.answer_id.id):
533                                     value[field] = str(ans.column_id.id)
534
535                         elif que.response_answer_ids and len(field.split('_')) == 2 and field.split('_')[1] == "selection":
536                             value[field] = str(que.response_answer_ids[0].answer_id.id)
537
538                         elif que.response_answer_ids and len(field.split('_')) == 3 and field.split('_')[2] != "multi" and field.split('_')[2] != "numeric":
539                             for ans in que.response_answer_ids:
540                                 if str(field.split('_')[1]) == str( ans.answer_id.id) and str(field.split('_')[2]) == str(ans.column_id.id):
541                                     if ans.value_choice:
542                                         value[field] = ans.value_choice
543                                     else:
544                                         value[field] = True
545
546                         else:
547                             for ans in que.response_answer_ids:
548                                 if str(field.split('_')[1]) == str( ans.answer_id.id):
549                                     value[field] = ans.answer
550
551         else:
552             
553             if not context.has_key('sur_name_id'):
554                 return value
555             if context.has_key('active') and context.get('active',False):
556                 return value
557             sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False))
558             ans_list = []
559
560             for key,val in safe_eval(sur_name_read.get('store_ans',"{}")).items():
561                 for field in fields_list:
562                     if field in list(val):
563                         value[field] = val[field]
564         return value
565
566     def create(self, cr, uid, vals, context=None):
567         """
568         Create the Answer of survey and store in survey.response object, and if set validation of question then check the value of question if value is wrong then raise the exception.
569         """
570         if context is None: context = {}
571
572         survey_question_wiz_id = super(survey_question_wiz,self).create(cr, uid, {'name': vals.get('name')}, context=context)
573         if context.has_key('active') and context.get('active',False):
574             return survey_question_wiz_id
575
576         for key,val in vals.items():
577             if key.split('_')[0] == "progress":
578                 vals.pop(key)
579             if not context.has_key('sur_name_id') and key.split('_')[0] == "wizardid":
580                 context.update({'sur_name_id': int(key.split('_')[1])})
581                 vals.pop(key)
582
583         click_state = True
584         click_update = []
585         surv_name_wiz = self.pool.get('survey.name.wiz')
586         surv_all_resp_obj = self.pool.get('survey.response')
587         surv_tbl_column_obj = self.pool.get('survey.tbl.column.heading')
588         survey_obj = self.pool.get('survey')
589         resp_obj = self.pool.get('survey.response.line')
590         res_ans_obj = self.pool.get('survey.response.answer')
591         que_obj = self.pool.get('survey.question')
592         sur_name_read = surv_name_wiz.read(cr, uid, context.get('sur_name_id',False), [])
593         response_id =  0
594
595         if not sur_name_read['response']:
596             response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'user_id':uid, 'date_create':datetime.datetime.now(), 'survey_id' : context['survey_id']})
597             surv_name_wiz.write(cr, uid, [context.get('sur_name_id', False)], {'response' : tools.ustr(response_id)})
598         else:
599             response_id = int(sur_name_read['response'])
600
601         if response_id not in surv_all_resp_obj.search(cr, uid, []):
602             response_id = surv_all_resp_obj.create(cr, uid, {'response_type':'link', 'user_id':uid, 'date_create':datetime.datetime.now(), 'survey_id' : context.get('survey_id',False)})
603             surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'response' : tools.ustr(response_id)})
604
605         #click first time on next button then increemnet on total start suvey
606         if not safe_eval(sur_name_read['store_ans']):
607             his_id = self.pool.get('survey.history').create(cr, uid, {'user_id': uid, \
608                                               'date': strftime('%Y-%m-%d %H:%M:%S'), 'survey_id': sur_name_read['survey_id'][0]})
609             survey_id = sur_name_read['survey_id'][0]
610             sur_rec = survey_obj.read(cr, uid, survey_id)
611             survey_obj.write(cr, uid, survey_id,  {'tot_start_survey' : sur_rec['tot_start_survey'] + 1})
612             if context.has_key('cur_id'):
613                 if context.has_key('request') and context.get('request',False):
614                     self.pool[context.get('object')].write(cr, uid, [int(context.get('cur_id',False))], {'response' : response_id})
615                     self.pool[context.get('object')].survey_req_done(cr, uid, [int(context.get('cur_id'))], context)
616                 else:
617                     self.pool[context.get('object')].write(cr, uid, [int(context.get('cur_id',False))], {'response' : response_id})        
618         if sur_name_read['store_ans'] and type(safe_eval(sur_name_read['store_ans'])) == dict:
619             sur_name_read['store_ans'] = safe_eval(sur_name_read['store_ans'])
620             for key,val in sur_name_read['store_ans'].items():
621                 for field in vals:
622                     if field.split('_')[0] == val['question_id']:
623                         click_state = False
624                         click_update.append(key)
625                         break
626         else:
627             sur_name_read['store_ans'] = {}
628         if click_state:
629             que_li = []
630             resp_id_list = []
631             for key, val in vals.items():
632                 que_id = key.split('_')[0]
633                 if que_id not in que_li:
634                     que_li.append(que_id)
635                     que_rec = que_obj.read(cr, uid, [int(que_id)], [])[0]
636                     res_data =  {
637                         'question_id': que_id,
638                         'date_create': datetime.datetime.now(),
639                         'state': 'done',
640                         'response_id': response_id
641                     }
642                     resp_id = resp_obj.create(cr, uid, res_data)
643                     resp_id_list.append(resp_id)
644                     sur_name_read['store_ans'].update({resp_id:{'question_id':que_id}})
645                     surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']})
646                     select_count = 0
647                     numeric_sum = 0
648                     selected_value = []
649                     matrix_list = []
650                     comment_field = False
651                     comment_value = False
652                     response_list = []
653
654                     for key1, val1 in vals.items():
655                         if val1 and key1.split('_')[1] == "table" and key1.split('_')[0] == que_id:
656                             surv_tbl_column_obj.create(cr, uid, {'response_table_id' : resp_id,'column_id':key1.split('_')[2], 'name':key1.split('_')[3], 'value' : val1})
657                             sur_name_read['store_ans'][resp_id].update({key1:val1})
658                             select_count += 1
659
660                         elif val1 and key1.split('_')[1] == "otherfield" and key1.split('_')[0] == que_id:
661                             comment_field = True
662                             sur_name_read['store_ans'][resp_id].update({key1:val1})
663                             select_count += 1
664                             surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']})
665                             continue
666
667                         elif val1 and key1.split('_')[1] == "selection" and key1.split('_')[0] == que_id:
668                             if len(key1.split('_')) > 2:
669                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[-1], 'column_id' : val1})
670                                 selected_value.append(val1)
671                                 response_list.append(str(ans_create_id) + "_" + str(key1.split('_')[-1]))
672                             else:
673                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':val1})
674                             sur_name_read['store_ans'][resp_id].update({key1:val1})
675                             select_count += 1
676
677                         elif key1.split('_')[1] == "other" and key1.split('_')[0] == que_id:
678                             if not val1:
679                                 comment_value = True
680                             else:
681                                 error = False
682                                 if que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_specific_length':
683                                     if (not val1 and  que_rec['comment_minimum_no']) or len(val1) <  que_rec['comment_minimum_no'] or len(val1) > que_rec['comment_maximum_no']:
684                                         error = True
685                                 elif que_rec['is_comment_require'] and  que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']:
686                                     error = False
687                                     try:
688                                         if que_rec['comment_valid_type'] == 'must_be_whole_number':
689                                             value = int(val1)
690                                             if value <  que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']:
691                                                 error = True
692                                         elif que_rec['comment_valid_type'] == 'must_be_decimal_number':
693                                             value = float(val1)
694                                             if value <  que_rec['comment_minimum_float'] or value > que_rec['comment_maximum_float']:
695                                                 error = True
696                                         elif que_rec['comment_valid_type'] == 'must_be_date':
697                                             value = datetime.datetime.strptime(val1, "%Y-%m-%d")
698                                             if value <  datetime.datetime.strptime(que_rec['comment_minimum_date'], "%Y-%m-%d") or value >  datetime.datetime.strptime(que_rec['comment_maximum_date'], "%Y-%m-%d"):
699                                                 error = True
700                                     except:
701                                         error = True
702                                 elif que_rec['is_comment_require'] and  que_rec['comment_valid_type'] == 'must_be_email_address':
703                                     import re
704                                     if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None:
705                                             error = True
706                                 if error:
707                                     for res in resp_id_list:
708                                         sur_name_read['store_ans'].pop(res)
709                                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'  \n" + tools.ustr(que_rec['comment_valid_err_msg']))
710
711                                 resp_obj.write(cr, uid, resp_id, {'comment':val1})
712                                 sur_name_read['store_ans'][resp_id].update({key1:val1})
713
714                         elif val1 and key1.split('_')[1] == "comment" and key1.split('_')[0] == que_id:
715                             resp_obj.write(cr, uid, resp_id, {'comment':val1})
716                             sur_name_read['store_ans'][resp_id].update({key1:val1})
717                             select_count += 1
718
719                         elif val1 and key1.split('_')[0] == que_id and (key1.split('_')[1] == "single"  or (len(key1.split('_')) > 2 and key1.split('_')[2] == 'multi')):
720                             error = False
721                             if que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_specific_length':
722                                 if (not val1 and  que_rec['validation_minimum_no']) or len(val1) <  que_rec['validation_minimum_no'] or len(val1) > que_rec['validation_maximum_no']:
723                                     error = True
724                             elif que_rec['is_validation_require'] and que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']:
725                                 error = False
726                                 try:
727                                     if que_rec['validation_type'] == 'must_be_whole_number':
728                                         value = int(val1)
729                                         if value <  que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']:
730                                             error = True
731                                     elif que_rec['validation_type'] == 'must_be_decimal_number':
732                                         value = float(val1)
733                                         if value <  que_rec['validation_minimum_float'] or value > que_rec['validation_maximum_float']:
734                                             error = True
735                                     elif que_rec['validation_type'] == 'must_be_date':
736                                         value = datetime.datetime.strptime(val1, "%Y-%m-%d")
737                                         if value <  datetime.datetime.strptime(que_rec['validation_minimum_date'], "%Y-%m-%d") or value >  datetime.datetime.strptime(que_rec['validation_maximum_date'], "%Y-%m-%d"):
738                                             error = True
739                                 except:
740                                     error = True
741                             elif que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_email_address':
742                                 import re
743                                 if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None:
744                                         error = True
745                             if error:
746                                 for res in resp_id_list:
747                                     sur_name_read['store_ans'].pop(res)
748                                 raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'  \n" + tools.ustr(que_rec['validation_valid_err_msg']))
749
750                             if key1.split('_')[1] == "single" :
751                                 resp_obj.write(cr, uid, resp_id, {'single_text':val1})
752                             else:
753                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'answer' : val1})
754
755                             sur_name_read['store_ans'][resp_id].update({key1:val1})
756                             select_count += 1
757
758                         elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) > 2 and key1.split('_')[2] == 'numeric':
759                             if not val1=="0":
760                                 try:
761                                     numeric_sum += int(val1)
762                                     ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'answer' : val1})
763                                     sur_name_read['store_ans'][resp_id].update({key1:val1})
764                                     select_count += 1
765                                 except:
766                                     for res in resp_id_list:
767                                         sur_name_read['store_ans'].pop(res)
768                                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' \n" + _("Please enter an integer value."))
769
770                         elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) == 3:
771                             if type(val1) == type('') or type(val1) == type(u''):
772                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'column_id' : key1.split('_')[2], 'value_choice' : val1})
773                                 sur_name_read['store_ans'][resp_id].update({key1:val1})
774                             else:
775                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'column_id' : key1.split('_')[2]})
776                                 sur_name_read['store_ans'][resp_id].update({key1:True})
777
778                             matrix_list.append(key1.split('_')[0] + '_' + key1.split('_')[1])
779                             select_count += 1
780
781                         elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) == 2:
782                             ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[-1], 'answer' : val1})
783                             sur_name_read['store_ans'][resp_id].update({key1:val1})
784                             select_count += 1
785                         surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']})
786
787                     for key,val in vals.items():
788                         if val and key.split('_')[1] == "commentcolumn" and key.split('_')[0] == que_id:
789                             for res_id in response_list:
790                                 if key.split('_')[2] in res_id.split('_')[1]:
791                                     a = res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field':val})
792                                     sur_name_read['store_ans'][resp_id].update({key:val})
793
794                     if comment_field and comment_value:
795                         for res in resp_id_list:
796                             sur_name_read['store_ans'].pop(res)
797                         raise osv.except_osv(_('Warning!'), "'" + que_rec['question']  + "' " + tools.ustr(que_rec['make_comment_field_err_msg']))
798
799                     if que_rec['type'] == "rating_scale" and que_rec['rating_allow_one_column_require'] and len(selected_value) > len(list(set(selected_value))):
800                         for res in resp_id_list:
801                             sur_name_read['store_ans'].pop(res)
802                         raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'\n" + _("You cannot select the same answer more than one time."))
803
804                     if not select_count:
805                         resp_obj.write(cr, uid, resp_id, {'state':'skip'})
806
807                     if que_rec['numeric_required_sum'] and numeric_sum > que_rec['numeric_required_sum']:
808                         for res in resp_id_list:
809                             sur_name_read['store_ans'].pop(res)
810                         raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['numeric_required_sum_err_msg']))
811
812                     if que_rec['type'] in ['multiple_textboxes_diff_type', 'multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']:
813                         if matrix_list:
814                             if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \
815                             (que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \
816                             (que_rec['required_type'] == 'at most' and len(list(set(matrix_list))) > que_rec['req_ans']) or \
817                             (que_rec['required_type'] == 'exactly' and len(list(set(matrix_list))) != que_rec['req_ans']) or \
818                             (que_rec['required_type'] == 'a range' and (len(list(set(matrix_list))) < que_rec['minimum_req_ans'] or len(list(set(matrix_list))) > que_rec['maximum_req_ans'])):
819                                 for res in resp_id_list:
820                                     sur_name_read['store_ans'].pop(res)
821                                 raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg']))
822
823                         elif (que_rec['required_type'] == 'all' and select_count < len(que_rec['answer_choice_ids'])) or \
824                             (que_rec['required_type'] == 'at least' and select_count < que_rec['req_ans']) or \
825                             (que_rec['required_type'] == 'at most' and select_count > que_rec['req_ans']) or \
826                             (que_rec['required_type'] == 'exactly' and select_count != que_rec['req_ans']) or \
827                             (que_rec['required_type'] == 'a range' and (select_count < que_rec['minimum_req_ans'] or select_count > que_rec['maximum_req_ans'])):
828                             for res in resp_id_list:
829                                 sur_name_read['store_ans'].pop(res)
830                             raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg']))
831
832                     if que_rec['type'] in ['multiple_choice_only_one_ans','single_textbox','comment'] and  que_rec['is_require_answer'] and select_count <= 0:
833                         for res in resp_id_list:
834                             sur_name_read['store_ans'].pop(res)
835                         raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg']))
836
837         else:
838             resp_id_list = []
839             for update in click_update:
840                 que_rec = que_obj.read(cr, uid , [int(sur_name_read['store_ans'][update]['question_id'])], [])[0]
841                 res_ans_obj.unlink(cr, uid,res_ans_obj.search(cr, uid, [('response_id', '=', update)]))
842                 surv_tbl_column_obj.unlink(cr, uid,surv_tbl_column_obj.search(cr, uid, [('response_table_id', '=', update)]))
843                 resp_id_list.append(update)
844                 sur_name_read['store_ans'].update({update:{'question_id':sur_name_read['store_ans'][update]['question_id']}})
845                 surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']})
846                 select_count = 0
847                 numeric_sum = 0
848                 selected_value = []
849                 matrix_list = []
850                 comment_field = False
851                 comment_value = False
852                 response_list = []
853
854                 for key, val in vals.items():
855                     ans_id_len = key.split('_')
856                     if ans_id_len[0] == sur_name_read['store_ans'][update]['question_id']:
857                         if val and key.split('_')[1] == "table":
858                             surv_tbl_column_obj.create(cr, uid, {'response_table_id' : update,'column_id':key.split('_')[2], 'name':key.split('_')[3], 'value' : val})
859                             sur_name_read['store_ans'][update].update({key:val})
860                             resp_obj.write(cr, uid, update, {'state': 'done'})
861
862                         elif val and key.split('_')[1] == "otherfield" :
863                             comment_field = True
864                             sur_name_read['store_ans'][update].update({key:val})
865                             select_count += 1
866                             surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans':sur_name_read['store_ans']})
867                             continue
868
869                         elif val and key.split('_')[1] == "selection":
870                             if len(key.split('_')) > 2:
871                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id':key.split('_')[-1], 'column_id' : val})
872                                 selected_value.append(val)
873                                 response_list.append(str(ans_create_id) + "_" + str(key.split('_')[-1]))
874                             else:
875                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id': val})
876                             resp_obj.write(cr, uid, update, {'state': 'done'})
877                             sur_name_read['store_ans'][update].update({key:val})
878                             select_count += 1
879
880                         elif key.split('_')[1] == "other":
881                             if not val:
882                                 comment_value = True
883                             else:
884                                 error = False
885                                 if que_rec['is_comment_require'] and  que_rec['comment_valid_type'] == 'must_be_specific_length':
886                                     if (not val and  que_rec['comment_minimum_no']) or len(val) <  que_rec['comment_minimum_no'] or len(val) > que_rec['comment_maximum_no']:
887                                         error = True
888                                 elif que_rec['is_comment_require'] and  que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']:
889                                     try:
890                                         if que_rec['comment_valid_type'] == 'must_be_whole_number':
891                                             value = int(val)
892                                             if value <  que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']:
893                                                 error = True
894                                         elif que_rec['comment_valid_type'] == 'must_be_decimal_number':
895                                             value = float(val)
896                                             if value <  que_rec['comment_minimum_float'] or value > que_rec['comment_maximum_float']:
897                                                 error = True
898                                         elif que_rec['comment_valid_type'] == 'must_be_date':
899                                             value = datetime.datetime.strptime(val, "%Y-%m-%d")
900                                             if value <  datetime.datetime.strptime(que_rec['comment_minimum_date'], "%Y-%m-%d") or value >  datetime.datetime.strptime(que_rec['comment_maximum_date'], "%Y-%m-%d"):
901                                                 error = True
902                                     except:
903                                         error = True
904                                 elif que_rec['is_comment_require'] and  que_rec['comment_valid_type'] == 'must_be_email_address':
905                                     import re
906                                     if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None:
907                                             error = True
908                                 if error:
909                                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'  \n" + tools.ustr(que_rec['comment_valid_err_msg']))
910                                 resp_obj.write(cr, uid, update, {'comment':val,'state': 'done'})
911                                 sur_name_read['store_ans'][update].update({key:val})
912
913                         elif val and key.split('_')[1] == "comment":
914                             resp_obj.write(cr, uid, update, {'comment':val,'state': 'done'})
915                             sur_name_read['store_ans'][update].update({key:val})
916                             select_count += 1
917
918                         elif val and (key.split('_')[1] == "single"  or (len(key.split('_')) > 2 and key.split('_')[2] == 'multi')):
919                             error = False
920                             if que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_specific_length':
921                                 if (not val and  que_rec['validation_minimum_no']) or len(val) <  que_rec['validation_minimum_no'] or len(val) > que_rec['validation_maximum_no']:
922                                     error = True
923                             elif que_rec['is_validation_require'] and que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']:
924                                 error = False
925                                 try:
926                                     if que_rec['validation_type'] == 'must_be_whole_number':
927                                         value = int(val)
928                                         if value <  que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']:
929                                             error = True
930                                     elif que_rec['validation_type'] == 'must_be_decimal_number':
931                                         value = float(val)
932                                         if value <  que_rec['validation_minimum_float'] or value > que_rec['validation_maximum_float']:
933                                             error = True
934                                     elif que_rec['validation_type'] == 'must_be_date':
935                                         value = datetime.datetime.strptime(val, "%Y-%m-%d")
936                                         if value <  datetime.datetime.strptime(que_rec['validation_minimum_date'], "%Y-%m-%d") or value >  datetime.datetime.strptime(que_rec['validation_maximum_date'], "%Y-%m-%d"):
937                                             error = True
938                                 except Exception ,e:
939                                     error = True
940                             elif que_rec['is_validation_require'] and  que_rec['validation_type'] == 'must_be_email_address':
941                                 import re
942                                 if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None:
943                                         error = True
944                             if error:
945                                 raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'  \n" + tools.ustr(que_rec['validation_valid_err_msg']))
946                             if key.split('_')[1] == "single" :
947                                 resp_obj.write(cr, uid, update, {'single_text':val,'state': 'done'})
948                             else:
949                                 resp_obj.write(cr, uid, update, {'state': 'done'})
950                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id':ans_id_len[1], 'answer' : val})
951                             sur_name_read['store_ans'][update].update({key:val})
952                             select_count += 1
953
954                         elif val and len(key.split('_')) > 2 and key.split('_')[2] == 'numeric':
955                             if not val=="0":
956                                 try:
957                                     numeric_sum += int(val)
958                                     resp_obj.write(cr, uid, update, {'state': 'done'})
959                                     ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[1], 'answer' : val})
960                                     sur_name_read['store_ans'][update].update({key:val})
961                                     select_count += 1
962                                 except:
963                                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "'\n" + _("Please enter an integer value."))
964
965                         elif val and len(key.split('_')) == 3:
966                             resp_obj.write(cr, uid, update, {'state': 'done'})
967                             if type(val) == type('') or type(val) == type(u''):
968                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[1], 'column_id' : ans_id_len[2], 'value_choice' : val})
969                                 sur_name_read['store_ans'][update].update({key:val})
970                             else:
971                                 ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[1], 'column_id' : ans_id_len[2]})
972                                 sur_name_read['store_ans'][update].update({key:True})
973                             matrix_list.append(key.split('_')[0] + '_' + key.split('_')[1])
974                             select_count += 1
975
976                         elif val and len(key.split('_')) == 2:
977                             resp_obj.write(cr, uid, update, {'state': 'done'})
978                             ans_create_id = res_ans_obj.create(cr, uid, {'response_id': update, 'answer_id':ans_id_len[-1], 'answer' : val})
979                             sur_name_read['store_ans'][update].update({key:val})
980                             select_count += 1
981                         surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'store_ans': sur_name_read['store_ans']})
982
983                 for key,val in vals.items():
984                     if val and key.split('_')[1] == "commentcolumn" and key.split('_')[0] == sur_name_read['store_ans'][update]['question_id']:
985                         for res_id in response_list:
986                             if key.split('_')[2] in res_id.split('_')[1]:
987                                 a = res_ans_obj.write(cr, uid, [res_id.split('_')[0]], {'comment_field':val})
988                                 sur_name_read['store_ans'][update].update({key:val})
989
990                 if comment_field and comment_value:
991                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question']  + "' " + tools.ustr(que_rec['make_comment_field_err_msg']))
992
993                 if que_rec['type'] == "rating_scale" and que_rec['rating_allow_one_column_require'] and len(selected_value) > len(list(set(selected_value))):
994                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "\n" + _("You cannot select same answer more than one time.'"))
995
996                 if que_rec['numeric_required_sum'] and numeric_sum > que_rec['numeric_required_sum']:
997                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['numeric_required_sum_err_msg']))
998
999                 if not select_count:
1000                     resp_obj.write(cr, uid, update, {'state': 'skip'})
1001
1002                 if que_rec['type'] in ['multiple_textboxes_diff_type','multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']:
1003                     if matrix_list:
1004                         if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \
1005                         (que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \
1006                         (que_rec['required_type'] == 'at most' and len(list(set(matrix_list))) > que_rec['req_ans']) or \
1007                         (que_rec['required_type'] == 'exactly' and len(list(set(matrix_list))) != que_rec['req_ans']) or \
1008                         (que_rec['required_type'] == 'a range' and (len(list(set(matrix_list))) < que_rec['minimum_req_ans'] or len(list(set(matrix_list))) > que_rec['maximum_req_ans'])):
1009                             raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg']))
1010
1011                     elif (que_rec['required_type'] == 'all' and select_count < len(que_rec['answer_choice_ids'])) or \
1012                         (que_rec['required_type'] == 'at least' and select_count < que_rec['req_ans']) or \
1013                         (que_rec['required_type'] == 'at most' and select_count > que_rec['req_ans']) or \
1014                         (que_rec['required_type'] == 'exactly' and select_count != que_rec['req_ans']) or \
1015                         (que_rec['required_type'] == 'a range' and (select_count < que_rec['minimum_req_ans'] or select_count > que_rec['maximum_req_ans'])):
1016                             raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg']))
1017
1018                 if que_rec['type'] in ['multiple_choice_only_one_ans','single_textbox','comment'] and  que_rec['is_require_answer'] and select_count <= 0:
1019                     raise osv.except_osv(_('Warning!'), "'" + que_rec['question'] + "' " + tools.ustr(que_rec['req_error_msg']))
1020
1021         return survey_question_wiz_id
1022
1023     def action_new_question(self, cr, uid, ids, context=None):
1024         """
1025         New survey.Question form.
1026         """
1027         if context is None:
1028             context = {}
1029         for key,val in context.items():
1030             if type(key) == type(True):
1031                 context.pop(key)
1032         view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question'),\
1033                             ('name','=','survey_question_wizard_test')])
1034         return {
1035             'view_type': 'form',
1036             "view_mode": 'form',
1037             'res_model': 'survey.question',
1038             'type': 'ir.actions.act_window',
1039             'target': 'new',
1040             'view_id': view_id,
1041             'page_id': int(context.get('page_id',0)),
1042             'context': context
1043         }
1044
1045     def action_new_page(self, cr, uid, ids, context=None):
1046         """
1047         New survey.Page form.
1048         """
1049         if context is None:
1050             context = {}
1051         for key,val in context.items():
1052             if type(key) == type(True):
1053                 context.pop(key)
1054         view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.page'),\
1055                                         ('name','=','survey_page_wizard_test')])
1056         return {
1057             'view_type': 'form',
1058             "view_mode": 'form',
1059             'res_model': 'survey.page',
1060             'type': 'ir.actions.act_window',
1061             'target': 'new',
1062             'view_id': view_id,
1063             'context': context
1064         }
1065
1066     def action_edit_page(self, cr, uid, ids, context=None):
1067         """
1068         Edit survey.page.
1069         """
1070         if context is None:
1071             context = {}
1072         for key,val in context.items():
1073             if type(key) == type(True):
1074                 context.pop(key)
1075         view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.page'),\
1076                                 ('name','=','survey_page_wizard_test')])
1077         return {
1078             'view_type': 'form',
1079             "view_mode": 'form',
1080             'res_model': 'survey.page',
1081             'type': 'ir.actions.act_window',
1082             'target': 'new',
1083             'res_id': int(context.get('page_id',0)),
1084             'view_id': view_id,
1085             'context': context
1086         }
1087
1088     def action_delete_page(self, cr, uid, ids, context=None):
1089         """
1090         Delete survey.page.
1091         """
1092         if context is None:
1093             context = {}
1094         for key,val in context.items():
1095             if type(key) == type(True):
1096                 context.pop(key)
1097
1098         self.pool.get('survey.page').unlink(cr, uid, [context.get('page_id',False)])
1099         for survey in self.pool.get('survey').browse(cr, uid, [context.get('survey_id',False)], context=context):
1100             if not survey.page_ids:
1101                 return {'type':'ir.actions.act_window_close'}
1102
1103         search_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question.wiz'),\
1104                                             ('name','=','Survey Search')])
1105         surv_name_wiz = self.pool.get('survey.name.wiz')
1106         surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], \
1107                     {'transfer':True, 'page_no' : context.get('page_number',False) })
1108         return {
1109             'view_type': 'form',
1110             "view_mode": 'form',
1111             'res_model': 'survey.question.wiz',
1112             'type': 'ir.actions.act_window',
1113             'target': 'new',
1114             'search_view_id':search_id[0],
1115             'context': context
1116         }
1117
1118     def action_edit_question(self, cr, uid, ids, context=None):
1119         """
1120         Edit survey.question.
1121         """
1122         if context is None:
1123             context = {}
1124         for key,val in context.items():
1125             if type(key) == type(True):
1126                 context.pop(key)
1127         view_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question'),\
1128                                 ('name','=','survey_question_wizard_test')])
1129         return {
1130             'view_type': 'form',
1131             "view_mode": 'form',
1132             'res_model': 'survey.question',
1133             'type': 'ir.actions.act_window',
1134             'target': 'new',
1135             'res_id' : int(context.get('question_id',0)),
1136             'view_id': view_id,
1137             'context': context
1138         }
1139
1140     def action_delete_question(self, cr, uid, ids, context=None):
1141         """
1142         Delete survey.question.
1143         """
1144         if context is None:
1145             context = {}
1146         for key,val in context.items():
1147             if type(key) == type(True):
1148                 context.pop(key)
1149
1150         que_obj = self.pool.get('survey.question')
1151         que_obj.unlink(cr, uid, [context.get('question_id',False)])
1152         search_id = self.pool.get('ir.ui.view').search(cr,uid,[('model','=','survey.question.wiz'),\
1153                                         ('name','=','Survey Search')])
1154         surv_name_wiz = self.pool.get('survey.name.wiz')
1155         surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)],\
1156                      {'transfer':True, 'page_no' : context.get('page_number',0) })
1157         return {
1158                 'view_type': 'form',
1159                 "view_mode": 'form',
1160                 'res_model': 'survey.question.wiz',
1161                 'type': 'ir.actions.act_window',
1162                 'target': 'new',
1163                 'search_view_id': search_id[0],
1164                 'context': context
1165                 }
1166
1167     def action_forward_previous(self, cr, uid, ids, context=None):
1168         """
1169         Goes to previous Survey Answer.
1170         """
1171         if context is None:
1172             context = {}
1173         search_obj = self.pool.get('ir.ui.view')
1174         surv_name_wiz = self.pool.get('survey.name.wiz')
1175         search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),\
1176                                               ('name','=','Survey Search')])
1177         wiz_id = surv_name_wiz.create(cr,uid, {'survey_id': context.get('survey_id',False),'page_no' :-1,'page':'next','transfer' :1,'response':0})
1178         context.update({'sur_name_id' :wiz_id, 'response_no': context.get('response_no',0) - 1})
1179
1180         if context.get('response_no',0) + 1 > len(context.get('response_id',0)):
1181             return {}
1182         return {
1183             'view_type': 'form',
1184             "view_mode": 'form',
1185             'res_model': 'survey.question.wiz',
1186             'type': 'ir.actions.act_window',
1187             'target': 'new',
1188             'search_view_id': search_id[0],
1189             'context': context
1190         }
1191
1192     def action_forward_next(self, cr, uid, ids, context=None):
1193         """
1194         Goes to Next Survey Answer.
1195         """
1196         if context is None:
1197             context = {}
1198         search_obj = self.pool.get('ir.ui.view')
1199         surv_name_wiz = self.pool.get('survey.name.wiz')
1200         search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),\
1201                                     ('name','=','Survey Search')])
1202         wiz_id = surv_name_wiz.create(cr,uid, {'survey_id' : context.get('survey_id',False),'page_no' :-1,'page':'next','transfer' :1,'response':0})
1203         context.update({'sur_name_id' :wiz_id, 'response_no' : context.get('response_no',0) + 1})
1204
1205         if context.get('response_no',0) + 1 > len(context.get('response_id',0)):
1206             return {}
1207         return {
1208             'view_type': 'form',
1209             "view_mode": 'form',
1210             'res_model': 'survey.question.wiz',
1211             'type': 'ir.actions.act_window',
1212             'target': 'new',
1213             'search_view_id': search_id[0],
1214             'context': context
1215         }
1216
1217     def action_next(self, cr, uid, ids, context=None):
1218         """
1219         Goes to Next page.
1220         """
1221         if context is None:
1222             context = {}
1223         surv_name_wiz = self.pool.get('survey.name.wiz')
1224         search_obj = self.pool.get('ir.ui.view')
1225         search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),('name','=','Survey Search')])
1226         surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page':'next'})
1227         return {
1228             'view_type': 'form',
1229             "view_mode": 'form',
1230             'res_model': 'survey.question.wiz',
1231             'type': 'ir.actions.act_window',
1232             'target': 'new',
1233             'search_view_id': search_id[0],
1234             'context': context
1235         }
1236
1237     def action_previous(self, cr, uid, ids, context=None):
1238         """
1239         Goes to previous page.
1240         """
1241         if context is None:
1242             context = {}
1243         surv_name_wiz = self.pool.get('survey.name.wiz')
1244         search_obj = self.pool.get('ir.ui.view')
1245         search_id = search_obj.search(cr,uid,[('model','=','survey.question.wiz'),\
1246                                     ('name','=','Survey Search')])
1247         surv_name_wiz.write(cr, uid, [context.get('sur_name_id',False)], {'transfer':True, 'page':'previous'})
1248         return {
1249             'view_type': 'form',
1250             "view_mode": 'form',
1251             'res_model': 'survey.question.wiz',
1252             'type': 'ir.actions.act_window',
1253             'target': 'new',
1254             'search_view_id': search_id[0],
1255             'context': context
1256         }
1257
1258
1259 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: