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="ans_tbl_white">
76 <blockAlignment value="LEFT"/>
77 <blockValign value="TOP"/>
78 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
80 <blockTableStyle id="ans_tbl_gainsboro">
81 <blockAlignment value="LEFT"/>
82 <blockValign value="TOP"/>
83 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
84 <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
86 <blockTableStyle id="page_tbl">
87 <blockAlignment value="LEFT"/>
88 <blockValign value="TOP"/>
89 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
90 <blockBackground colorName="gray" start="0,0" stop="-1,-1"/>
91 <blockTextColor colorName="white" start="0,0" stop="0,0"/>
93 <blockTableStyle id="title_tbl">
94 <blockAlignment value="LEFT"/>
95 <blockValign value="TOP"/>
96 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
97 <blockBackground colorName="black" start="0,0" stop="-1,-1"/>
98 <blockTextColor colorName="white" start="0,0" stop="0,0"/>
100 <blockTableStyle id="question_tbl">
101 <blockAlignment value="LEFT"/>
102 <blockValign value="TOP"/>
103 <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
105 <blockTableStyle id="note_table">
106 <blockAlignment value="LEFT"/>
107 <blockValign value="TOP"/>
109 <blockTableStyle id="Table4">
110 <blockAlignment value="LEFT"/>
111 <blockValign value="TOP"/>
112 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
113 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
114 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
116 <blockTableStyle id="Table5">
117 <blockAlignment value="LEFT"/>
118 <blockValign value="TOP"/>
119 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
120 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
121 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
124 <paraStyle name="all" alignment="justify"/>
126 <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/>
127 <paraStyle name="page" fontName="helvetica-bold" fontSize="15.0" leftIndent="0.0" textColor="white"/>
128 <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
129 <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/>
130 <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="0.0"/>
131 <paraStyle name="descriptive_text" fontName="helvetica" fontSize="10.0" leftIndent="0.0"/>
132 <paraStyle name="answer_left" alignment="LEFT" fontName="helvetica-bold" fontSize="8.0" leftIndent="0.0"/>
133 <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
134 <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
135 <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
136 <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
137 <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
140 surv_obj = pooler.get_pool(cr.dbname).get('survey')
141 for survey in surv_obj.browse(cr,uid,ids):
142 if datas.has_key('form') and datas['form']['survey_title']:
144 <blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl">
145 <tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr>
148 for page in survey.page_ids:
151 <blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl">
152 <tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para></td></tr>
155 rml += """<para style="P2"></para><blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
156 <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
158 for que in page.question_ids:
161 <para style="P2"><font></font></para>
162 <blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
163 <tr><td><para style="question">Que : """ + to_xml(tools.ustr(que.question)) + """</para></td></tr>
165 <para style="P2"><font></font></para>"""
166 if que.type in ['descriptive_text']:
167 cols_widhts.append(float(_tbl_widths.replace('cm','')))
168 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
169 colWidths = colWidths+'cm'
171 <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
174 <para style="descriptive_text">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para>
178 elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']:
180 for ans in que.answer_choice_ids:
181 answer.append(to_xml(tools.ustr((ans.answer))))
183 def divide_list(lst, n):
184 return [lst[i::n] for i in range(n)]
186 divide_list = divide_list(answer,_display_ans_in_rows)
187 for lst in divide_list:
188 if que.type == 'multiple_choice_multiple_ans':
189 if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)):
192 del divide_list[divide_list.index(lst):]
193 for divide in divide_list:
194 a = _divide_columns_for_matrix*len(divide)
195 b = float(_tbl_widths.replace('cm','')) - float(a)
197 for div in range(0,len(divide)):
198 cols_widhts.append(float(a/len(divide)))
199 cols_widhts.append(float(b/len(divide)))
200 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
201 colWidths = colWidths+'cm'
202 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
204 for div in range(0,len(divide)):
206 if que.type == 'multiple_choice_multiple_ans':
210 <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/>
213 <td><para style="answer">""" + divide[div] + """</para></td>"""
218 <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/>
221 <td><para style="answer">""" + divide[div] + """</para></td>"""
227 </tr></blockTable>"""
228 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']:
229 if len(que.column_heading_ids):
230 cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0))
231 for col in que.column_heading_ids:
232 cols_widhts.append(float((float(_tbl_widths.replace('cm',''))/float(2.0))/len(que.column_heading_ids)))
234 cols_widhts.append(float(_tbl_widths.replace('cm','')))
238 if que.comment_column:
239 for col in cols_widhts:
241 cols_widhts[i] = cols_widhts[i]/2.0
245 cols_widhts.append(round(tmp,2))
246 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
247 colWidths = colWidths+'cm'
249 for col in que.column_heading_ids:
250 if col.title not in matrix_ans:
251 matrix_ans.append(col.title)
252 if que.comment_column:
253 matrix_ans.append(to_xml(tools.ustr(que.column_name)))
254 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
256 for mat_col in matrix_ans:
257 rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
258 rml+="""</tr></blockTable>"""
260 for ans in que.answer_choice_ids:
262 style='ans_tbl_white'
264 style='ans_tbl_gainsboro'
267 <blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
268 <tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
269 rec_width = float((sum-tmp)*10+100)
271 if que.type in ['matrix_of_drop_down_menus']:
272 value = """ <fill color="white"/>
273 <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"/>"""
274 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
275 value = """ <fill color="white"/>
276 <!--rect x="0.25cm" y="-0.5cm" width="0.8 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/-->
277 <circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>"""
279 value = """ <fill color="white"/>
280 <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
281 for mat_col in range(1,len(matrix_ans)):
282 if matrix_ans[mat_col]==que.column_name:
285 <td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>"""
289 rml+="""<td><illustration>""" + value + """</illustration></td>"""
290 rml+= """</tr></blockTable>"""
291 elif que.type in ['multiple_textboxes','numerical_textboxes', 'date_and_time','date']:
292 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
293 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
294 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
295 colWidths = tools.ustr(colWidths) + 'cm'
297 if que.type in ['multiple_textboxes']:
298 rect_len = tools.ustr(cols_widhts[0] - 0.3) + "cm"
301 for ans in que.answer_choice_ids:
302 rml +="""<para style="P1"></para>
303 <blockTable colWidths=" """+ colWidths + """ " style="ans_tbl">
305 <td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
308 <rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr(rect_len) + """' height="0.6cm" fill="no" stroke="yes"/>
313 elif que.type in ['comment']:
314 cols_widhts.append(float(_tbl_widths.replace('cm','')))
315 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
316 colWidths = colWidths+'cm'
318 rect_len = tools.ustr(cols_widhts[0] - 0.4) + "cm"
319 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
321 <td><para style="comment"><font color="white"> </font></para>
323 <rect x="0.0cm" y="0.3cm" width='""" + tools.ustr(rect_len) + """' height="1.5cm" fill="no" stroke="yes"/>
328 elif que.type in ['single_textbox']:
329 cols_widhts.append(float(_tbl_widths.replace('cm','')))
330 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
331 colWidths = colWidths+'cm'
332 rml+="""<para style="P2"><font color="white"> </font></para>
333 <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
337 <rect x="0.2cm" y="0.3cm" width="15.0 cm" height="0.6cm" fill="no" stroke="yes"/>
342 elif que.type in ['table']:
343 tbl_width = float(_tbl_widths.replace('cm',''))
344 for i in range(0,len(que.column_heading_ids)):
345 cols_widhts.append(tbl_width/float(len(que.column_heading_ids)))
346 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
347 colWidths = colWidths+'cm'
348 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table4"><tr>"""
349 for col in que.column_heading_ids:
350 rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>"""
351 rml+="""</tr></blockTable>
352 <blockTable colWidths=" """ + colWidths + """ " style="Table5">"""
353 for r in range(0,que.no_of_rows):
355 for c in que.column_heading_ids:
357 <td><para style="terp_default_9"><font color="white"> </font></para></td>"""
359 rml+="""</blockTable>"""
360 if datas.has_key('form') and not datas['form']['without_pagebreak']:
361 rml+="""<pageBreak/>"""
362 elif not datas.has_key('form'):
363 rml+="""<pageBreak/>"""
365 rml+="""<para style="P2"><font></font></para>"""
366 rml+="""</story></document>"""
367 report_type = datas.get('report_type', 'pdf')
368 create_doc = self.generators[report_type]
369 pdf = create_doc(rml, title=self.title)
370 return (pdf, report_type)
371 survey_form('report.survey.form', 'survey','','')
373 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: