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
28 class survey_form(report_rml):
29 def create(self, cr, uid, ids, datas, context):
30 _divide_columns_for_matrix = 0.7
31 _display_ans_in_rows = 5
32 _pageSize = ('29.7cm','21.1cm')
33 if datas.has_key('form') and datas['form']['orientation']=='vertical':
34 if datas['form']['paper_size']=='letter':
35 _pageSize = ('21.6cm','27.9cm')
36 elif datas['form']['paper_size']=='legal':
37 _pageSize = ('21.6cm','35.6cm')
38 elif datas['form']['paper_size']=='a4':
39 _pageSize = ('21.1cm','29.7cm')
40 elif datas.has_key('form') and datas['form']['orientation']=='horizontal':
41 if datas['form']['paper_size']=='letter':
42 _pageSize = ('27.9cm','21.6cm')
43 elif datas['form']['paper_size']=='legal':
44 _pageSize = ('35.6cm','21.6cm')
45 elif datas['form']['paper_size']=='a4':
46 _pageSize = ('29.7cm','21.1cm')
48 _frame_width = tools.ustr(_pageSize[0])
49 _frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm'
50 _tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm'
51 rml="""<document filename="Survey Form.pdf">
52 <template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Form.pdf' author="Martin Simon" allowSplitting="20" >
53 <pageTemplate id="first">
54 <frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/>
56 <lineMode width="1.0"/>
57 <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+"""</lines>
58 <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" 1.0cm 1.00cm</lines>
59 <lines>"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>
60 <lines>1.0cm 1.00cm """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>"""
61 if datas.has_key('form') and datas['form']['page_number']:
64 <setFont name="Helvetica" size="10"/>
65 <drawRightString x='"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+"""' y="0.6cm">Page : <pageNumber/> </drawRightString>"""
66 rml +="""</pageGraphics>
70 <blockTableStyle id="ans_tbl">
71 <blockAlignment value="LEFT"/>
72 <blockValign value="TOP"/>
73 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
75 <blockTableStyle id="tbl_white">
76 <blockAlignment value="LEFT"/>
77 <blockValign value="TOP"/>
78 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
79 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
80 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
82 <blockTableStyle id="tbl_gainsboro">
83 <blockAlignment value="LEFT"/>
84 <blockValign value="TOP"/>
85 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
86 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
87 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
88 <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
90 <blockTableStyle id="ans_tbl_white">
91 <blockAlignment value="LEFT"/>
92 <blockValign value="TOP"/>
93 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
95 <blockTableStyle id="ans_tbl_gainsboro">
96 <blockAlignment value="LEFT"/>
97 <blockValign value="TOP"/>
98 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
99 <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
101 <blockTableStyle id="page_tbl">
102 <blockAlignment value="LEFT"/>
103 <blockValign value="TOP"/>
104 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
105 <blockBackground colorName="gray" start="0,0" stop="-1,-1"/>
106 <blockTextColor colorName="white" start="0,0" stop="0,0"/>
108 <blockTableStyle id="title_tbl">
109 <blockAlignment value="LEFT"/>
110 <blockValign value="TOP"/>
111 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
112 <blockBackground colorName="black" start="0,0" stop="-1,-1"/>
113 <blockTextColor colorName="white" start="0,0" stop="0,0"/>
115 <blockTableStyle id="question_tbl">
116 <blockAlignment value="LEFT"/>
117 <blockValign value="TOP"/>
118 <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
120 <blockTableStyle id="note_table">
121 <blockAlignment value="LEFT"/>
122 <blockValign value="TOP"/>
124 <blockTableStyle id="tbl">
125 <blockAlignment value="LEFT"/>
126 <blockValign value="TOP"/>
127 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
128 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
129 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
132 <paraStyle name="all" alignment="justify"/>
134 <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/>
135 <paraStyle name="page" fontName="helvetica-bold" fontSize="15.0" leftIndent="0.0" textColor="white"/>
136 <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
137 <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/>
138 <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="0.0"/>
139 <paraStyle name="descriptive_text" fontName="helvetica" fontSize="10.0" leftIndent="0.0"/>
140 <paraStyle name="answer_left" alignment="LEFT" fontName="helvetica-bold" fontSize="8.0" leftIndent="0.0"/>
141 <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
142 <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
143 <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
144 <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
145 <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
148 surv_obj = pooler.get_pool(cr.dbname).get('survey')
149 for survey in surv_obj.browse(cr,uid,ids):
150 if datas.has_key('form') and datas['form']['survey_title']:
152 <blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl">
153 <tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr>
157 <para style="P2"></para>
158 <blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
159 <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(survey.note)) + """</para><para style="P2"><font></font></para></td></tr>
162 for page in survey.page_ids:
165 <blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl">
166 <tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para></td></tr>
169 rml += """<para style="P2"></para><blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
170 <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
172 for que in page.question_ids:
175 <para style="P2"><font></font></para>
176 <blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
177 <tr><td><para style="question">Que : """ + to_xml(tools.ustr(que.question)) + """</para></td></tr>
179 <para style="P2"><font></font></para>"""
180 if que.type in ['descriptive_text']:
181 cols_widhts.append(float(_tbl_widths.replace('cm','')))
182 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
183 colWidths = colWidths+'cm'
185 <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
188 <para style="descriptive_text">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para>
192 elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']:
194 for ans in que.answer_choice_ids:
195 answer.append(to_xml(tools.ustr((ans.answer))))
197 def divide_list(lst, n):
198 return [lst[i::n] for i in range(n)]
200 divide_list = divide_list(answer,_display_ans_in_rows)
201 for lst in divide_list:
202 if que.type == 'multiple_choice_multiple_ans':
203 if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)):
206 del divide_list[divide_list.index(lst):]
207 for divide in divide_list:
208 a = _divide_columns_for_matrix*len(divide)
209 b = float(_tbl_widths.replace('cm','')) - float(a)
211 for div in range(0,len(divide)):
212 cols_widhts.append(float(a/len(divide)))
213 cols_widhts.append(float(b/len(divide)))
214 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
215 colWidths = colWidths+'cm'
216 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
218 for div in range(0,len(divide)):
220 if que.type == 'multiple_choice_multiple_ans':
224 <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/>
227 <td><para style="answer">""" + divide[div] + """</para></td>"""
232 <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/>
235 <td><para style="answer">""" + divide[div] + """</para></td>"""
241 </tr></blockTable>"""
242 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']:
243 if len(que.column_heading_ids):
244 cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0))
245 for col in que.column_heading_ids:
246 cols_widhts.append(float((float(_tbl_widths.replace('cm',''))/float(2.0))/len(que.column_heading_ids)))
248 cols_widhts.append(float(_tbl_widths.replace('cm','')))
252 if que.comment_column:
253 for col in cols_widhts:
255 cols_widhts[i] = cols_widhts[i]/2.0
259 cols_widhts.append(round(tmp,2))
260 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
261 colWidths = colWidths+'cm'
263 for col in que.column_heading_ids:
264 if col.title not in matrix_ans:
265 matrix_ans.append(col.title)
266 if que.comment_column:
267 matrix_ans.append(to_xml(tools.ustr(que.column_name)))
268 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
270 for mat_col in matrix_ans:
271 rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
272 rml+="""</tr></blockTable>"""
274 for ans in que.answer_choice_ids:
276 style='ans_tbl_white'
278 style='ans_tbl_gainsboro'
281 <blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
282 <tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
283 rec_width = float((sum-tmp)*10+100)
285 if que.type in ['matrix_of_drop_down_menus']:
286 value = """ <fill color="white"/>
287 <rect x="-0.1cm" y="-0.45cm" width='""" + tools.ustr(cols_widhts[-1] - 0.5) +"cm" + """' height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
288 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
289 value = """ <fill color="white"/>
290 <circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>"""
292 value = """ <fill color="white"/>
293 <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
294 for mat_col in range(1,len(matrix_ans)):
295 if matrix_ans[mat_col]==que.column_name:
298 <td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>"""
302 rml+="""<td><illustration>""" + value + """</illustration></td>"""
303 rml+= """</tr></blockTable>"""
304 elif que.type in ['multiple_textboxes','numerical_textboxes', 'date_and_time','date','multiple_textboxes_diff_type']:
305 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
306 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
307 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
308 colWidths = tools.ustr(colWidths) + 'cm'
309 for ans in que.answer_choice_ids:
310 rml +="""<para style="P1"></para>
311 <blockTable colWidths=" """+ colWidths + """ " style="ans_tbl">
313 <td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
316 <rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr(str(cols_widhts[0] - 0.3) + "cm") + """' height="0.6cm" fill="no" stroke="yes"/>
321 elif que.type in ['comment']:
322 cols_widhts.append(float(_tbl_widths.replace('cm','')))
323 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
324 rml+="""<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
326 <td><para style="comment"><font color="white"> </font></para>
328 <rect x="0.1cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.6) +'cm') + """' height="1.5cm" fill="no" stroke="yes"/>
333 elif que.type in ['single_textbox']:
334 cols_widhts.append(float(_tbl_widths.replace('cm','')))
335 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
336 rml+="""<para style="P2"><font color="white"> </font></para>
337 <blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
341 <rect x="0.2cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.7) +'cm') + """' height="0.6cm" fill="no" stroke="yes"/>
346 elif que.type in ['table']:
347 tbl_width = float(_tbl_widths.replace('cm',''))
348 for i in range(0,len(que.column_heading_ids)):
349 cols_widhts.append(tbl_width/float(len(que.column_heading_ids)))
350 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
351 colWidths = colWidths+'cm'
352 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="tbl"><tr>"""
353 for col in que.column_heading_ids:
354 rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>"""
355 rml+="""</tr></blockTable>"""
357 for r in range(0,que.no_of_rows):
361 style='tbl_gainsboro'
363 rml+="""<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'><tr>"""
364 for c in que.column_heading_ids:
366 <td><para style="terp_default_9"><font color="white"> </font></para></td>"""
367 rml+="""</tr></blockTable>"""
368 if datas.has_key('form') and not datas['form']['without_pagebreak']:
369 rml+="""<pageBreak/>"""
370 elif not datas.has_key('form'):
371 rml+="""<pageBreak/>"""
373 rml+="""<para style="P2"><font></font></para>"""
374 rml+="""</story></document>"""
375 report_type = datas.get('report_type', 'pdf')
376 create_doc = self.generators[report_type]
377 pdf = create_doc(rml, title=self.title)
378 return (pdf, report_type)
379 survey_form('report.survey.form', 'survey','','')
381 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: