[IMP]:survey:(REF.YSA)

*Improved module with response mail.
*Improved the browse and print survey report.
*Improved demo data for survey.

bzr revid: apa@tinyerp.com-20100122121346-e2ccbpx4uh6gxqpw
This commit is contained in:
apa-tiny 2010-01-22 17:43:46 +05:30
parent 767e644faf
commit 1134203b6c
6 changed files with 290 additions and 242 deletions

View File

@ -120,7 +120,7 @@ class survey_analysis(report_rml):
<blockTable colWidths="280.0,100.0,120.0" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(survey.title) + """</para>
<para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_start_survey) + """</para>
@ -133,13 +133,13 @@ class survey_analysis(report_rml):
for page in survey.page_ids:
rml += """ <blockTable colWidths="500" style="Table4">
# <tr>
# <td><para style="page">Page :- """ + to_xml(page.title) + """</para></td>
# <td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td>
# </tr>
# </blockTable>"""
for que in page.question_ids:
rml +="""<blockTable colWidths="500" style="Table5">
<tr>
<td><para style="question">""" + tools.ustr(prefix) + to_xml(que.question) + """</para></td>
<td><para style="question">""" + to_xml(tools.ustr(prefix)) + to_xml(tools.ustr(que.question)) + """</para></td>
</tr>
</blockTable>"""
cols_widhts = []
@ -154,12 +154,12 @@ class survey_analysis(report_rml):
matrix_ans.append(col.title)
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in matrix_ans:
rml+="""<td><para style="response">""" + to_xml(mat_col) + """</para></td>"""
rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml+="""<td><para style="response">Response Count</para></td>
</tr>"""
last_col = cols_widhts[-1]
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer">""" + to_xml(ans.answer) + """</para></td>"""
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
cr.execute("select count(id) from survey_response_answer sra where sra.answer_id = %d"%(ans.id))
tot_res = cr.fetchone()[0]
cr.execute("select count(id) ,sra.answer from survey_response_answer sra where sra.answer_id = %d group by sra.answer" % ans.id)
@ -182,7 +182,7 @@ class survey_analysis(report_rml):
if que.comment_field_type:
cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id)
tot_res = cr.fetchone()[0]
rml+="""<blockTable colWidths=" """+ str(500 - last_col) +"," + str(last_col) + """ " style="Table1"><tr><td><para style="answer_right">""" + to_xml(que.comment_label) + """</para></td>
rml+="""<blockTable colWidths=" """+ str(500 - last_col) +"," + str(last_col) + """ " style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
elif que.type in['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'multiple_textboxes','date_and_time','date']:
@ -193,7 +193,7 @@ class survey_analysis(report_rml):
<td> <para style="response">Response Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer">""" + to_xml(ans.answer) + """</para></td>
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
<td><para style="answer">""" + tools.ustr(ans.average) + """%</para></td>
<td><para style="answer">""" + tools.ustr(ans.response) + """</para></td></tr>"""
rml+="""</blockTable>"""
@ -204,13 +204,13 @@ class survey_analysis(report_rml):
tot_avg = 0.00
if que.tot_resp:
tot_avg = round(float(tot_res * 100)/ que.tot_resp,2)
rml+="""<blockTable colWidths="280.0,120,100.0" style="Table1"><tr><td><para style="answer">""" + to_xml(que.comment_label) + """</para></td>
rml+="""<blockTable colWidths="280.0,120,100.0" style="Table1"><tr><td><para style="answer">""" +to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer">""" + str(tot_avg) + """%</para></td>
<td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
else:
cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id)
tot_res = cr.fetchone()[0]
rml+="""<blockTable colWidths="400.0,100.0" style="Table1"><tr><td><para style="answer_right">""" + to_xml(que.comment_label) + """</para></td>
rml+="""<blockTable colWidths="400.0,100.0" style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
elif que.type in['single_textbox']:
@ -244,12 +244,12 @@ class survey_analysis(report_rml):
matrix_ans.append(col.title)
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in matrix_ans:
rml+="""<td><para style="response">""" + to_xml(mat_col) + """</para></td>"""
rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml+="""<td><para style="response">Rating Average</para></td>
<td><para style="response">Response Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer">""" + to_xml(ans.answer) + """</para></td>"""
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
res_count = 0
rating_weight_sum = 0
for mat_col in range(1, len(matrix_ans)):
@ -281,7 +281,7 @@ class survey_analysis(report_rml):
elif que.type in['matrix_of_drop_down_menus']:
for column in que.column_heading_ids:
rml += """<blockTable colWidths="500" style="Table1"><tr>
<td><para style="answer">""" + to_xml(column.title) + """</para></td></tr></blockTable>"""
<td><para style="answer">""" + to_xml(tools.ustr(column.title)) + """</para></td></tr></blockTable>"""
menu_choices = column.menu_choice.split('\n')
cols_widhts = []
cols_widhts.append(200)
@ -291,7 +291,7 @@ class survey_analysis(report_rml):
rml +="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>
<td><para style="response"></para></td>"""
for menu in menu_choices:
rml += """<td><para style="response">""" + to_xml(menu) + """</para></td>"""
rml += """<td><para style="response">""" + to_xml(tools.ustr(menu)) + """</para></td>"""
rml += """<td><para style="response">Response Count</para></td></tr>"""
cr.execute("select count(id), sra.answer_id from survey_response_answer sra \
where sra.answer='%s' group by sra.answer_id " % (column.title))
@ -300,7 +300,7 @@ class survey_analysis(report_rml):
where sra.answer='%s' group by sra.value_choice ,sra.answer_id, sra.answer" % (column.title))
calc_percantage = cr.dictfetchall()
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer_right">""" + to_xml(ans.answer) + """</para></td>"""
rml+="""<tr><td><para style="answer_right">""" + tto_xml(tools.ustr(ans.answer)) + """</para></td>"""
for mat_col in range(0, len(menu_choices)):
calc = 0
response = 0
@ -339,7 +339,7 @@ class survey_analysis(report_rml):
per = 0.00
if len(tot_res):
per = round((float(total) / len(tot_res)),2)
rml+="""<tr><td><para style="answer">""" + to_xml(ans.answer) + """</para></td>
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
<td> <para style="Standard"> </para></td>
<td> <para style="answer">""" + tools.ustr(per) +"""</para></td>
<td><para style="answer">""" + tools.ustr(total) + """</para></td>

View File

@ -132,216 +132,222 @@ class survey_browse_response(report_rml):
surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response')
surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line')
surv_obj = pooler.get_pool(cr.dbname).get('survey')
for response in surv_resp_obj.browse(cr,uid, surv_resp_obj.search(cr,uid, [('survey_id','=',ids[0])])):
for survey in surv_obj.browse(cr, uid, ids):
if survey.question_prefix:
prefix = survey.question_prefix + " : "
for id in ids:
for survey in surv_obj.browse(cr, uid, [id]):
if context.has_key('response_id'):
s_id = [int(context['response_id'])]
else:
prefix = ''
rml += """<blockTable colWidths="230.0,150.0,120.0" style="Table_heading">
<tr>
<td>
<para style="terp_tblheader_General_Centre">Survey Title </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Response Create Date </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Respose By </para>
</td>
</tr>
</blockTable>
<blockTable colWidths="230.0,150.0,120.0" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(survey.title) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + to_xml(response.date_create) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + to_xml(response.user_id.name) + """</para>
</td>
</tr>
</blockTable>"""
for page in survey.page_ids:
rml += """<para style="P2"></para>
<blockTable colWidths="500" style="Table4">
<tr>
<td><para style="page">Page :- """ + to_xml(page.title) + """</para></td>
</tr>
</blockTable>"""
for que in page.question_ids:
rml += """<para style="P2"></para>
<blockTable colWidths="500" style="Table5">
<tr>
<td><para style="question">""" + tools.ustr(prefix) + to_xml(que.question) + """</para></td>
</tr>
</blockTable>"""
answer = surv_resp_line_obj.browse(cr,uid, surv_resp_line_obj.search(cr, uid, [('question_id','=',que.id),('response_id','=',response.id)]))
if que.type in ['descriptive_text']:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(que.descriptive_text) + """</para></td> </tr>
s_id = surv_resp_obj.search(cr,uid, [('survey_id','=',[survey.id])])
for response in surv_resp_obj.browse(cr,uid,s_id): #surv_resp_obj.search(cr,uid, [('survey_id','=',ids[0])])
if survey.question_prefix:
prefix = survey.question_prefix + " : "
else:
prefix = ''
rml += """<blockTable colWidths="230.0,150.0,120.0" style="Table_heading">
<tr>
<td>
<para style="terp_tblheader_General_Centre">Survey Title </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Response Create Date </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Respose By </para>
</td>
</tr>
</blockTable>
<blockTable colWidths="230.0,150.0,120.0" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + to_xml(response.date_create) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + to_xml(response.user_id.name) + """</para>
</td>
</tr>
</blockTable>"""
elif que.type in ['table']:
if len(answer) and answer[0].state == "done":
col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading')
cols_widhts = []
for col in range(0, len(que.column_heading_ids)):
cols_widhts.append(float(500 / (len(que.column_heading_ids))))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = []
rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
rml +="""<td> <para style="terp_tblheader_Details">""" + col.title +"""</para></td>"""
rml += """</tr></blockTable>"""
for row in range(0, que.no_of_rows):
rml +="""<blockTable colWidths=" """ + str(colWidths) + """ " style="Table51"><tr>"""
table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id),('name','=',row)]))
for column in matrix_ans:
value = """<font color="white"> </font>"""
for col in table_data:
if column == col.column_id.title:
value = col.value
rml += """<td> <para style="terp_default_9">""" + value +"""</para></td>"""
for page in survey.page_ids:
rml += """<para style="P2"></para>
<blockTable colWidths="500" style="Table4">
<tr>
<td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td>
</tr>
</blockTable>"""
for que in page.question_ids:
rml += """<para style="P2"></para>
<blockTable colWidths="500" style="Table5">
<tr>
<td><para style="question">""" + to_xml(tools.ustr(prefix)) + to_xml(to_xml(que.question)) + """</para></td>
</tr>
</blockTable>"""
answer = surv_resp_line_obj.browse(cr,uid, surv_resp_line_obj.search(cr, uid, [('question_id','=',que.id),('response_id','=',response.id)]))
if que.type in ['descriptive_text']:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr>
</blockTable>"""
elif que.type in ['table']:
if len(answer) and answer[0].state == "done":
col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading')
cols_widhts = []
for col in range(0, len(que.column_heading_ids)):
cols_widhts.append(float(500 / (len(que.column_heading_ids))))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = []
rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
rml +="""<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>"""
rml += """</tr></blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
if len(answer) and answer[0].state == "done":
for ans in answer[0].response_answer_ids:
for row in range(0, que.no_of_rows):
rml +="""<blockTable colWidths=" """ + str(colWidths) + """ " style="Table51"><tr>"""
table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id),('name','=',row)]))
for column in matrix_ans:
value = """<font color="white"> </font>"""
for col in table_data:
if column == col.column_id.title:
value = col.value
rml += """<td> <para style="terp_default_9">""" + to_xml(tools.ustr(value)) +"""</para></td>"""
rml += """</tr></blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(ans.answer_id.answer) + """</para></td></tr>
</blockTable>"""
if que.comment_field_type:
rml+="""<blockTable colWidths="500" style="Table1"><tr>
<td><para style="answer">""" + tools.ustr(answer[0].comment) + """</para></td></tr></blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['multiple_textboxes','date','date_and_time','numerical_textboxes']:
if len(answer) and answer[0].state == "done":
for ans in answer[0].response_answer_ids:
rml +="""<blockTable colWidths="200,300" style="Table1">
<tr> <td> <para style="response">""" + to_xml(ans.answer_id.answer) + """</para></td>
<td> <para style="response">""" + to_xml(ans.answer) + """</para></td></tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['single_textbox']:
if len(answer) and answer[0].state == "done":
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(answer[0].single_text) + """</para></td></tr>
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['comment']:
if len(answer) and answer[0].state == "done":
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(answer[0].comment) + """</para></td></tr>
elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
if len(answer) and answer[0].state == "done":
for ans in answer[0].response_answer_ids:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(ans.answer_id.answer)) + """</para></td></tr>
</blockTable>"""
if que.comment_field_type:
if answer[0].comment:
rml+="""<blockTable colWidths="500" style="Table1"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','matrix_of_drop_down_menus']:
if len(answer) and answer[0].state == "done":
if que.comment_column:
pass
cols_widhts = []
cols_widhts.append(200)
len_col_heading = len(que.column_heading_ids)
for col in range(0, len_col_heading):
cols_widhts.append(float(300 / len_col_heading))
tmp=0.0
sum = 0.0
i = 0
if que.comment_column:
for col in cols_widhts:
if i==0:
cols_widhts[i] = cols_widhts[i]/2.0
tmp = cols_widhts[i]
sum += col
i+=1
cols_widhts.append(round(tmp,2))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = ['',]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
len_matrix = len(matrix_ans)
if que.comment_column:
matrix_ans.append(que.column_name)
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in matrix_ans:
rml+="""<td><para style="response">""" + to_xml(mat_col) + """</para></td>"""
rml +="""</tr>"""
rml+="""</blockTable>"""
i=0
for ans in que.answer_choice_ids:
if i%2!=0:
style='ans_tbl_white'
else:
style='ans_tbl_gainsboro'
i+=1
rml+="""<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
<tr><td><para style="response">""" + to_xml(ans.answer) + """</para></td>"""
comment_value = ""
for mat_col in range(1, len_matrix):
value = """"""
for res_ans in answer[0].response_answer_ids:
if res_ans.answer_id.id == ans.id and res_ans.answer == matrix_ans[mat_col]:
comment_value = to_xml(tools.ustr(res_ans.comment_field))
if que.type in ['matrix_of_drop_down_menus']:
value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/>
<fill color="gray"/>
<circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/>
</illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration>
<fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/>
<rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration>"""
break
else:
if que.type in ['matrix_of_drop_down_menus']:
value = """"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration><fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>"""
rml+= """<td>""" + value + """</td>"""
elif que.type in ['multiple_textboxes','date','date_and_time','numerical_textboxes']:
if len(answer) and answer[0].state == "done":
for ans in answer[0].response_answer_ids:
rml +="""<blockTable colWidths="200,300" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(ans.answer_id.answer)) + """</para></td>
<td> <para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td></tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['single_textbox']:
if len(answer) and answer[0].state == "done":
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['comment']:
if len(answer) and answer[0].state == "done":
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','matrix_of_drop_down_menus']:
if len(answer) and answer[0].state == "done":
if que.comment_column:
if comment_value=='False':
comment_value = ''
rml+= """<td><para style="response">"""+ comment_value + """</para></td>"""
rml+=""" </tr></blockTable>"""
if que.comment_field_type:
rml+="""<blockTable colWidths="500" style="Table1"><tr>
<td><para style="answer">""" + tools.ustr(answer[0].comment) + """</para></td></tr></blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
rml += """<pageBreak/>"""
pass
cols_widhts = []
cols_widhts.append(200)
len_col_heading = len(que.column_heading_ids)
for col in range(0, len_col_heading):
cols_widhts.append(float(300 / len_col_heading))
tmp=0.0
sum = 0.0
i = 0
if que.comment_column:
for col in cols_widhts:
if i==0:
cols_widhts[i] = cols_widhts[i]/2.0
tmp = cols_widhts[i]
sum += col
i+=1
cols_widhts.append(round(tmp,2))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = ['',]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
len_matrix = len(matrix_ans)
if que.comment_column:
matrix_ans.append(que.column_name)
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in matrix_ans:
rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml +="""</tr>"""
rml+="""</blockTable>"""
i=0
for ans in que.answer_choice_ids:
if i%2!=0:
style='ans_tbl_white'
else:
style='ans_tbl_gainsboro'
i+=1
rml+="""<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
<tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
comment_value = ""
for mat_col in range(1, len_matrix):
value = """"""
for res_ans in answer[0].response_answer_ids:
if res_ans.answer_id.id == ans.id and res_ans.answer == matrix_ans[mat_col]:
comment_value = to_xml(tools.ustr(res_ans.comment_field))
if que.type in ['matrix_of_drop_down_menus']:
value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/>
<fill color="gray"/>
<circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/>
</illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration>
<fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/>
<rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration>"""
break
else:
if que.type in ['matrix_of_drop_down_menus']:
value = """"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration><fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>"""
rml+= """<td>""" + value + """</td>"""
if que.comment_column:
if comment_value=='False':
comment_value = ''
rml+= """<td><para style="response">"""+ to_xml(tools.ustr(comment_value)) + """</para></td>"""
rml+=""" </tr></blockTable>"""
if que.comment_field_type:
rml+="""<blockTable colWidths="500" style="Table1"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
rml += """<pageBreak/>"""
rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]

View File

@ -142,21 +142,21 @@ class survey_form(report_rml):
if datas.has_key('form') and datas['form']['survey_title']:
rml += """
<blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl">
<tr><td><para style="title">""" + to_xml(survey.title) + """</para><para style="P2"><font></font></para></td></tr>
<tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
seq = 0
for page in survey.page_ids:
seq+=1
rml += """
<blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl">
<tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + tools.ustr(page.title) + """</para></td></tr>
<tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para></td></tr>
</blockTable>"""
for que in page.question_ids:
cols_widhts=[]
rml +="""
<para style="P2"><font></font></para>
<blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
<tr><td><para style="question">""" + tools.ustr(prefix) + tools.ustr(que.question) + """</para></td></tr>
<tr><td><para style="question">""" + to_xml(tools.ustr(prefix)) + to_xml(tools.ustr(que.question)) + """</para></td></tr>
</blockTable>
<para style="P2"><font></font></para>"""
if que.type in ['descriptive_text']:
@ -246,14 +246,14 @@ class survey_form(report_rml):
if col.title not in matrix_ans:
matrix_ans.append(col.title)
if que.comment_column:
matrix_ans.append(tools.ustr(que.column_name))
matrix_ans.append(to_xml(tools.ustr(que.column_name)))
rml+="""
<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
<tr>"""
for mat_col in matrix_ans:
rml+="""
<td><para style="response">""" + to_xml(mat_col) + """</para></td>"""
<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml+="""</tr></blockTable>"""
i=0
for ans in que.answer_choice_ids:
@ -346,7 +346,7 @@ class survey_form(report_rml):
colWidths = colWidths+'cm'
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table4"><tr>"""
for col in que.column_heading_ids:
rml+="""<td><para style="terp_tblheader_Details">""" + tools.ustr(col.title) + """</para></td>"""
rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>"""
rml+="""</tr></blockTable>
<blockTable colWidths=" """ + colWidths + """ " style="Table5">"""
for r in range(0,que.no_of_rows):

View File

@ -30,6 +30,7 @@ from lxml import etree
from tools import to_xml
import tools
from mx.DateTime import *
import netsvc
class survey(osv.osv):
_name = 'survey'
@ -795,6 +796,34 @@ class survey_question_wiz(osv.osv_memory):
else:
if not context.has_key('active'):
survey_obj.write(cr, uid, survey_id, {'tot_comp_survey' : sur_rec['tot_comp_survey'] + 1})
surv_name_wiz = self.pool.get('survey.name.wiz')
user_obj = self.pool.get('res.users')
survey_data = self.pool.get('survey').browse(cr, uid, int(context['survey_id']))
response_id = surv_name_wiz.read(cr,uid,context['sur_name_id'])['response']
context.update({'response_id':response_id})
report = self.create_report(cr, uid, [int(context.get('survey_id',False))], 'report.survey.browse.response', survey_data.title,context)
attachments = []
file = open("/tmp/" + survey_data.title + ".pdf")
file_data = ""
while 1:
line = file.readline()
file_data += line
if not line:
break
attachments.append((survey_data.title + ".pdf",file_data))
user_email = False
resp_email = False
if user_obj.browse(cr, uid, uid).address_id.id:
cr.execute("select email from res_partner_address where id =%d" % user_obj.browse(cr, uid, uid).address_id.id)
user_email = cr.fetchone()[0]
resp_id = survey_data.responsible_id.address_id
if resp_id:
cr.execute("select email from res_partner_address where id =%d" % resp_id.id)
resp_email = cr.fetchone()[0]
if user_email and resp_email:
mail = "Hello " + survey_data.responsible_id.name + ",\n\n " + str(user_obj.browse(cr, uid, uid).name) + " Give Response Of " + survey_data.title + " Survey.\n\n Thanks,"
tools.email_send(user_email, [resp_email], "Survey Response Of " + str(user_obj.browse(cr, uid, uid).name) , mail, attach = attachments)
xml_form = etree.Element('form', {'string': _('Complete Survey Response')})
etree.SubElement(xml_form, 'separator', {'string': 'Complete Survey', 'colspan': "4"})
etree.SubElement(xml_form, 'label', {'string': 'Thanks for your response'})
@ -806,6 +835,21 @@ class survey_question_wiz(osv.osv_memory):
result['context'] = context
return result
def create_report(self, cr, uid, res_ids, report_name=False, file_name=False, context=None):
if not report_name or not res_ids:
return (False, Exception('Report name and Resources ids are required !!!'))
try:
ret_file_name = '/tmp/'+file_name+'.pdf'
service = netsvc.LocalService(report_name);
(result, format) = service.create(cr, uid, res_ids, {}, context)
fp = open(ret_file_name, 'wb+');
fp.write(result);
fp.close();
except Exception,e:
print 'Exception in create report:',e
return (False, str(e))
return (True, ret_file_name)
def default_get(self, cr, uid, fields_list, context=None):
value = {}
for field in fields_list:

View File

@ -212,7 +212,7 @@
<field name="page_id" ref="survey_page_Contracts" />
<field name="type">multiple_choice_only_one_ans</field>
<field name="comment_field_type">text</field>
<field name="comment_label">Never... Why?</field>
<field name="comment_label">Why?</field>
<field name="in_visible_single_text">1</field>
<field eval="2" name="sequence"/>
</record>
@ -226,9 +226,12 @@
<field name="question_id" ref="survey_question_contract_customers" />
<field name="sequence" eval="2"/>
</record>
<record id="survey_answer_never" model="survey.answer">
<field name="answer">Never... </field>
<field name="question_id" ref="survey_question_contract_customers" />
<field name="sequence" eval="2"/>
</record>
<record id="survey_question_contract_customers" model="survey.question">
<field name="make_comment_field">True</field>
<field name="make_comment_field_err_msg">Please enter a comment.</field>
<field eval="True" name="is_require_answer"/>
</record>
@ -767,8 +770,6 @@
<field name="sequence" eval="2"/>
</record>
<record id="survey_question_odoo_continue_using_odoo" model="survey.question">
<field name="make_comment_field">True</field>
<field name="make_comment_field_err_msg">Please enter a comment.</field>
<field eval="True" name="is_require_answer"/>
</record>
@ -985,12 +986,12 @@
<field name="page_id" ref="survey_page_odoo_the_offer" />
<field name="type">multiple_choice_only_one_ans</field>
<field name="comment_field_type">text</field>
<field name="comment_label">Yes, I plan to use (GB) :</field>
<field name="comment_label">Comment</field>
<field name="in_visible_single_text">1</field>
<field name="sequence" eval="2"/>
</record>
<record id="survey_answer_YES" model="survey.answer">
<field name="answer">YES</field>
<field name="answer">Yes, I plan to use (GB)</field>
<field name="question_id" ref="survey_question_odoo_dms" />
<field name="sequence" eval="1"/>
</record>
@ -999,10 +1000,7 @@
<field name="question_id" ref="survey_question_odoo_dms" />
<field name="sequence" eval="2"/>
</record>
<record id="survey_question_odoo_dms" model="survey.question">
<field name="make_comment_field">True</field>
<field name="make_comment_field_err_msg">Please enter a comment.</field>
<field eval="True" name="is_require_answer"/>
</record>

View File

@ -79,7 +79,7 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<!-- group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<group colspan="4" attrs="{'invisible':[('comment_field_type','!=','char'),('comment_field_type','!=','text')]}">
<field name="make_comment_field"/>
<group colspan="4" attrs="{'invisible':[('make_comment_field','!=',True)]}">
@ -87,7 +87,7 @@
<field name="make_comment_field_err_msg" nolabel="1"/>
</group>
</group>
</group>
</group-->
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
@ -315,7 +315,7 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<!--group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<group colspan="4" attrs="{'invisible':[('comment_field_type','!=','char'),('comment_field_type','!=','text')]}">
<field name="make_comment_field"/>
<group colspan="4" attrs="{'invisible':[('make_comment_field','!=',True)]}">
@ -323,7 +323,7 @@
<field name="make_comment_field_err_msg" nolabel="1"/>
</group>
</group>
</group>
</group-->
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
@ -499,7 +499,7 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<!--group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<group colspan="4" attrs="{'invisible':[('comment_field_type','!=','char'),('comment_field_type','!=','text')]}">
<field name="make_comment_field"/>
<group colspan="4" attrs="{'invisible':[('make_comment_field','!=',True)]}">
@ -507,7 +507,7 @@
<field name="make_comment_field_err_msg" nolabel="1"/>
</group>
</group>
</group>
</group-->
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
@ -636,7 +636,7 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<!--group colspan="4" attrs="{'invisible':[('type','!=','multiple_choice_only_one_ans'), ('type','!=','multiple_choice_multiple_ans')]}">
<group colspan="4" attrs="{'invisible':[('comment_field_type','!=','char'),('comment_field_type','!=','text')]}">
<field name="make_comment_field"/>
<group colspan="4" attrs="{'invisible':[('make_comment_field','!=',True)]}">
@ -644,7 +644,7 @@
<field name="make_comment_field_err_msg" nolabel="1"/>
</group>
</group>
</group>
</group-->
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_multi_ans'),('type','!=','matrix_of_choices_only_one_ans'),('type','!=','matrix_of_drop_down_menus'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">