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="Table4">
106 <blockAlignment value="LEFT"/>
107 <blockValign value="TOP"/>
108 <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
109 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
110 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
112 <blockTableStyle id="Table5">
113 <blockAlignment value="LEFT"/>
114 <blockValign value="TOP"/>
115 <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
116 <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
117 <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
120 <paraStyle name="all" alignment="justify"/>
122 <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/>
123 <paraStyle name="page" fontName="helvetica-bold" fontSize="15.0" leftIndent="0.0" textColor="white"/>
124 <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
125 <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/>
126 <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="0.0"/>
127 <paraStyle name="descriptive_text" fontName="helvetica" fontSize="10.0" leftIndent="0.0"/>
128 <paraStyle name="answer_left" alignment="LEFT" fontName="helvetica-bold" fontSize="8.0" leftIndent="0.0"/>
129 <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
130 <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
131 <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
132 <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
133 <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
136 surv_obj = pooler.get_pool(cr.dbname).get('survey')
137 for survey in surv_obj.browse(cr,uid,ids):
138 if datas.has_key('form') and datas['form']['survey_title']:
140 <blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl">
141 <tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr>
144 for page in survey.page_ids:
147 <blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl">
148 <tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para></td></tr>
150 for que in page.question_ids:
153 <para style="P2"><font></font></para>
154 <blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
155 <tr><td><para style="question">Que : """ + to_xml(tools.ustr(que.question)) + """</para></td></tr>
157 <para style="P2"><font></font></para>"""
158 if que.type in ['descriptive_text']:
159 cols_widhts.append(float(_tbl_widths.replace('cm','')))
160 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
161 colWidths = colWidths+'cm'
163 <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
166 <para style="descriptive_text">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para>
170 elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']:
172 for ans in que.answer_choice_ids:
173 answer.append(to_xml(tools.ustr((ans.answer))))
175 def divide_list(lst, n):
176 return [lst[i::n] for i in range(n)]
178 divide_list = divide_list(answer,_display_ans_in_rows)
179 for lst in divide_list:
180 if que.type == 'multiple_choice_multiple_ans':
181 if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)):
184 del divide_list[divide_list.index(lst):]
185 for divide in divide_list:
186 a = _divide_columns_for_matrix*len(divide)
187 b = float(_tbl_widths.replace('cm','')) - float(a)
189 for div in range(0,len(divide)):
190 cols_widhts.append(float(a/len(divide)))
191 cols_widhts.append(float(b/len(divide)))
192 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
193 colWidths = colWidths+'cm'
194 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
196 for div in range(0,len(divide)):
198 if que.type == 'multiple_choice_multiple_ans':
202 <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/>
205 <td><para style="answer">""" + divide[div] + """</para></td>"""
210 <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/>
213 <td><para style="answer">""" + divide[div] + """</para></td>"""
219 </tr></blockTable>"""
220 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']:
221 if len(que.column_heading_ids):
222 cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0))
223 for col in que.column_heading_ids:
224 cols_widhts.append(float((float(_tbl_widths.replace('cm',''))/float(2.0))/len(que.column_heading_ids)))
226 cols_widhts.append(float(_tbl_widths.replace('cm','')))
230 if que.comment_column:
231 for col in cols_widhts:
233 cols_widhts[i] = cols_widhts[i]/2.0
237 cols_widhts.append(round(tmp,2))
238 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
239 colWidths = colWidths+'cm'
241 for col in que.column_heading_ids:
242 if col.title not in matrix_ans:
243 matrix_ans.append(col.title)
244 if que.comment_column:
245 matrix_ans.append(to_xml(tools.ustr(que.column_name)))
246 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
248 for mat_col in matrix_ans:
249 rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
250 rml+="""</tr></blockTable>"""
252 for ans in que.answer_choice_ids:
254 style='ans_tbl_white'
256 style='ans_tbl_gainsboro'
259 <blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
260 <tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
261 rec_width = float((sum-tmp)*10+100)
263 if que.type in ['matrix_of_drop_down_menus']:
264 value = """ <fill color="white"/>
265 <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"/>"""
266 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
267 value = """ <fill color="white"/>
268 <!--rect x="0.25cm" y="-0.5cm" width="0.8 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/-->
269 <circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>"""
271 value = """ <fill color="white"/>
272 <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
273 for mat_col in range(1,len(matrix_ans)):
274 if matrix_ans[mat_col]==que.column_name:
277 <td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>"""
281 rml+="""<td><illustration>""" + value + """</illustration></td>"""
282 rml+= """</tr></blockTable>"""
283 elif que.type in ['multiple_textboxes','numerical_textboxes', 'date_and_time','date']:
284 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
285 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
286 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
287 colWidths = tools.ustr(colWidths) + 'cm'
289 if que.type in ['multiple_textboxes']:
290 rect_len = tools.ustr(cols_widhts[0] - 0.3) + "cm"
293 for ans in que.answer_choice_ids:
294 rml +="""<para style="P1"></para>
295 <blockTable colWidths=" """+ colWidths + """ " style="ans_tbl">
297 <td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
300 <rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr(rect_len) + """' height="0.6cm" fill="no" stroke="yes"/>
305 elif que.type in ['comment']:
306 cols_widhts.append(float(_tbl_widths.replace('cm','')))
307 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
308 colWidths = colWidths+'cm'
310 rect_len = tools.ustr(cols_widhts[0] - 0.4) + "cm"
311 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
313 <td><para style="comment"><font color="white"> </font></para>
315 <rect x="0.0cm" y="0.3cm" width='""" + tools.ustr(rect_len) + """' height="1.5cm" fill="no" stroke="yes"/>
320 elif que.type in ['single_textbox']:
321 cols_widhts.append(float(_tbl_widths.replace('cm','')))
322 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
323 colWidths = colWidths+'cm'
324 rml+="""<para style="P2"><font color="white"> </font></para>
325 <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
329 <rect x="0.2cm" y="0.3cm" width="15.0 cm" height="0.6cm" fill="no" stroke="yes"/>
334 elif que.type in ['table']:
335 tbl_width = float(_tbl_widths.replace('cm',''))
336 for i in range(0,len(que.column_heading_ids)):
337 cols_widhts.append(tbl_width/float(len(que.column_heading_ids)))
338 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
339 colWidths = colWidths+'cm'
340 rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table4"><tr>"""
341 for col in que.column_heading_ids:
342 rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>"""
343 rml+="""</tr></blockTable>
344 <blockTable colWidths=" """ + colWidths + """ " style="Table5">"""
345 for r in range(0,que.no_of_rows):
347 for c in que.column_heading_ids:
349 <td><para style="terp_default_9"><font color="white"> </font></para></td>"""
351 rml+="""</blockTable>"""
352 if datas.has_key('form') and not datas['form']['without_pagebreak']:
353 rml+="""<pageBreak/>"""
354 elif not datas.has_key('form'):
355 rml+="""<pageBreak/>"""
357 rml+="""<para style="P2"><font></font></para>"""
358 rml+="""</story></document>"""
359 report_type = datas.get('report_type', 'pdf')
360 create_doc = self.generators[report_type]
361 pdf = create_doc(rml, title=self.title)
362 return (pdf, report_type)
363 survey_form('report.survey.form', 'survey','','')
365 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: