1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
24 from report.interface import report_rml
25 from tools import to_xml
29 class survey_browse_response(report_rml):
30 def create(self, cr, uid, ids, datas, context):
31 rml ="""<document filename="Survey Analysis Report.pdf">
32 <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
33 <pageTemplate id="first">
34 <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
38 <blockTableStyle id="ans_tbl_white">
39 <blockAlignment value="LEFT"/>
40 <blockValign value="TOP"/>
41 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
43 <blockTableStyle id="ans_tbl_gainsboro">
44 <blockAlignment value="LEFT"/>
45 <blockValign value="TOP"/>
46 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
47 <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
49 <blockTableStyle id="Table1">
50 <blockAlignment value="LEFT"/>
51 <blockValign value="TOP"/>
52 <lineStyle kind="LINEBELOW" colorName="#e6e6e6"/>
54 <blockTableStyle id="note_table">
55 <blockAlignment value="LEFT"/>
56 <blockValign value="TOP"/>
58 <blockTableStyle id="Table2">
59 <blockAlignment value="LEFT"/>
60 <blockValign value="TOP"/>
62 <blockTableStyle id="Table3">
63 <blockAlignment value="LEFT"/>
64 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/>
65 <blockValign value="TOP"/>
67 <blockTableStyle id="Table4">
68 <blockAlignment value="LEFT"/>
69 <blockValign value="TOP"/>
70 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
72 <blockTableStyle id="Table5">
73 <blockAlignment value="LEFT"/>
74 <blockValign value="TOP"/>
75 <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
77 <blockTableStyle id="Table41">
78 <blockAlignment value="LEFT"/>
79 <blockValign value="TOP"/>
80 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
81 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
82 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
84 <blockTableStyle id="Table51">
85 <blockAlignment value="LEFT"/>
86 <blockValign value="TOP"/>
87 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
88 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
89 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
91 <blockTableStyle id="Table_heading">
92 <blockAlignment value="LEFT"/>
93 <blockValign value="TOP"/>
94 <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
95 <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
96 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
97 <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
99 <blockTableStyle id="Table_head_2">
100 <blockAlignment value="LEFT"/>
101 <blockValign value="TOP"/>
102 <lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
103 <lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
104 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
105 <lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
108 <paraStyle name="all" alignment="justify"/>
110 <paraStyle name="answer_right" alignment="RIGHT" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
111 <paraStyle name="Standard1" fontName="helvetica-bold" alignment="RIGHT" fontSize="09.0"/>
112 <paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/>
113 <paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/>
114 <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/>
115 <paraStyle name="page" fontName="helvetica" fontSize="11.0" leftIndent="0.0"/>
116 <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/>
117 <paraStyle name="answer_bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/>
118 <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
119 <paraStyle name="answer1" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
120 <paraStyle name="Title" fontName="helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/>
121 <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
122 <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
123 <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
124 <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
125 <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
126 <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
127 <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
131 <para style="Title"><u>Browse Responses </u></para>
132 <para style="Standard"><font></font></para>
134 <font color="white"> </font>
137 surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response')
138 if datas.has_key('form') and datas['form'].has_key('response_ids'):
139 response_id = datas['form']['response_ids'][0][2]
140 elif context.has_key('response_id'):
141 response_id = [int(context['response_id'])]
143 response_id = surv_resp_obj.search(cr, uid, [('survey_id','in',ids)])
144 surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line')
145 surv_obj = pooler.get_pool(cr.dbname).get('survey')
146 for response in surv_resp_obj.browse(cr,uid, response_id):
147 for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
148 status = "Not Finished"
149 if response.state == "done":
151 rml += """<blockTable colWidths="230.0,120.0,100.0,50" style="Table_heading">
154 <para style="terp_tblheader_General_Centre">Survey Title </para>
157 <para style="terp_tblheader_General_Centre">Response Create Date </para>
160 <para style="terp_tblheader_General_Centre">Respose By </para>
163 <para style="terp_tblheader_General_Centre">Status</para>
167 <blockTable colWidths="230.0,120.0,100.0,50" style="Table_head_2">
170 <para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
173 <para style="terp_default_Centre_8">""" + to_xml(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """</para>
176 <para style="terp_default_Centre_8">""" + to_xml(response.user_id.name) + """</para>
179 <para style="terp_default_Centre_8">""" + status + """</para>
183 for page in survey.page_ids:
184 rml += """<para style="P2"></para>
185 <blockTable colWidths="500" style="Table4">
187 <td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td>
191 rml += """<para style="P2"></para>
192 <blockTable colWidths="500" style="note_table">
194 <td><para style="response">""" + to_xml(tools.ustr(page.note)) + """</para></td>
197 for que in page.question_ids:
198 rml += """<para style="P2"></para>
199 <blockTable colWidths="500" style="Table5">
201 <td><para style="question">Que : """ + to_xml(to_xml(que.question)) + """</para></td>
204 answer = surv_resp_line_obj.browse(cr,uid, surv_resp_line_obj.search(cr, uid, [('question_id','=',que.id),('response_id','=',response.id)]))
205 if que.type in ['descriptive_text']:
206 rml +="""<blockTable colWidths="500" style="Table1">
207 <tr> <td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr>
209 elif que.type in ['table']:
210 if len(answer) and answer[0].state == "done":
211 col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading')
213 for col in range(0, len(que.column_heading_ids)):
214 cols_widhts.append(float(500 / (len(que.column_heading_ids))))
215 colWidths = ",".join(map(tools.ustr, cols_widhts))
217 rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
218 for col in que.column_heading_ids:
219 if col.title not in matrix_ans:
220 matrix_ans.append(col.title)
221 rml +="""<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>"""
222 rml += """</tr></blockTable>"""
223 for row in range(0, que.no_of_rows):
224 rml +="""<blockTable colWidths=" """ + str(colWidths) + """ " style="Table51"><tr>"""
225 table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id),('name','=',row)]))
226 for column in matrix_ans:
228 for col in table_data:
229 if column == col.column_id.title:
232 rml += """<td> <para style="terp_default_9">""" + to_xml(tools.ustr(value)) +"""</para></td>"""
234 rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>"""
235 rml += """</tr></blockTable>"""
237 rml +="""<blockTable colWidths="500" style="Table1">
238 <tr> <td> <para style="response">No Response</para></td> </tr>
240 elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
241 if len(answer) and answer[0].state == "done":
242 for ans in answer[0].response_answer_ids:
243 rml +="""<blockTable colWidths="500" style="Table1">
244 <tr> <td> <para style="response">""" + to_xml(tools.ustr(ans.answer_id.answer)) + """</para></td></tr>
246 if que.comment_field_type:
247 if answer[0].comment:
248 rml+="""<blockTable colWidths="500" style="Table1"><tr>
249 <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
251 rml +="""<blockTable colWidths="500" style="Table1">
252 <tr> <td> <para style="response">No Response</para></td> </tr>
254 elif que.type in ['multiple_textboxes','date','date_and_time','numerical_textboxes']:
255 if len(answer) and answer[0].state == "done":
256 for ans in answer[0].response_answer_ids:
257 rml +="""<blockTable colWidths="200,300" style="Table1">
258 <tr> <td> <para style="response">""" + to_xml(tools.ustr(ans.answer_id.answer)) + """</para></td>
259 <td> <para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td></tr>
262 rml +="""<blockTable colWidths="500" style="Table1">
263 <tr> <td> <para style="response">No Response</para></td> </tr>
265 elif que.type in ['single_textbox']:
266 if len(answer) and answer[0].state == "done":
267 rml +="""<blockTable colWidths="500" style="Table1">
268 <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr>
271 rml +="""<blockTable colWidths="500" style="Table1">
272 <tr> <td> <para style="response">No Response</para></td> </tr>
274 elif que.type in ['comment']:
275 if len(answer) and answer[0].state == "done":
276 rml +="""<blockTable colWidths="500" style="Table1">
277 <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr>
280 rml +="""<blockTable colWidths="500" style="Table1">
281 <tr> <td> <para style="response">No Response</para></td> </tr>
283 elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','matrix_of_drop_down_menus']:
284 if len(answer) and answer[0].state == "done":
285 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
288 cols_widhts.append(200)
289 len_col_heading = len(que.column_heading_ids)
290 for col in range(0, len_col_heading):
291 cols_widhts.append(float(300 / len_col_heading))
295 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
296 for col in cols_widhts:
298 cols_widhts[i] = cols_widhts[i]/2.0
302 cols_widhts.append(round(tmp,2))
303 colWidths = ",".join(map(tools.ustr, cols_widhts))
305 for col in que.column_heading_ids:
306 if col.title not in matrix_ans:
307 matrix_ans.append(col.title)
308 len_matrix = len(matrix_ans)
309 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
310 matrix_ans.append(que.column_name)
311 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
312 for mat_col in matrix_ans:
313 rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
315 rml+="""</blockTable>"""
317 for ans in que.answer_choice_ids:
319 style='ans_tbl_white'
321 style='ans_tbl_gainsboro'
323 rml+="""<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
324 <tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
326 for mat_col in range(1, len_matrix):
328 for res_ans in answer[0].response_answer_ids:
329 if res_ans.answer_id.id == ans.id and res_ans.answer == matrix_ans[mat_col]:
330 comment_value = to_xml(tools.ustr(res_ans.comment_field))
331 if que.type in ['matrix_of_drop_down_menus']:
332 value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>"""
333 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
334 value = """<illustration><fill color="white"/>
335 <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/>
337 <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/>
339 elif que.type in ['matrix_of_choices_only_multi_ans']:
340 value = """<illustration>
341 <fill color="white"/>
342 <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
344 <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
348 if que.type in ['matrix_of_drop_down_menus']:
350 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
351 value = """<illustration><fill color="white"/>
352 <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
354 elif que.type in ['matrix_of_choices_only_multi_ans']:
355 value = """<illustration><fill color="white"/>
356 <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
358 rml+= """<td>""" + value + """</td>"""
359 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
360 if comment_value=='False':
362 rml+= """<td><para style="response">"""+ to_xml(tools.ustr(comment_value)) + """</para></td>"""
363 rml+=""" </tr></blockTable>"""
364 if que.is_comment_require:
365 rml+="""<blockTable colWidths="500" style="Table1"><tr>
366 <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment or '')) + """</para></td></tr></blockTable>"""
368 rml +="""<blockTable colWidths="500" style="Table1">
369 <tr> <td> <para style="response">No Response</para></td> </tr>
372 rml += """<pageBreak/>"""
373 rml += """</story></document>"""
374 report_type = datas.get('report_type', 'pdf')
375 create_doc = self.generators[report_type]
376 pdf = create_doc(rml, title=self.title)
377 return (pdf, report_type)
379 survey_browse_response('report.survey.browse.response', 'survey','','')
381 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: