From 9069425fd4bd0d2f0a63ec61f3fdc71a906657d0 Mon Sep 17 00:00:00 2001 From: apa-tiny Date: Tue, 9 Feb 2010 12:59:37 +0530 Subject: [PATCH] [IMP]:survey-(Ref-YSA) -Improved survey browse response report with print option. bzr revid: apa@tinyerp.com-20100209072937-80cjw1q7lqhx5dnj --- .../survey/report/survey_browse_response.py | 444 ++++++++++-------- addons/survey/wizard/wizard_browse_answer.py | 25 +- 2 files changed, 265 insertions(+), 204 deletions(-) diff --git a/addons/survey/report/survey_browse_response.py b/addons/survey/report/survey_browse_response.py index 986fb0ccb2f..6e423cb53c1 100644 --- a/addons/survey/report/survey_browse_response.py +++ b/addons/survey/report/survey_browse_response.py @@ -28,13 +28,61 @@ import time class survey_browse_response(report_rml): def create(self, cr, uid, ids, datas, context): - rml =""" - + + + + + + + + + + + + + + + @@ -46,7 +94,7 @@ class survey_browse_response(report_rml): - + @@ -91,22 +139,25 @@ class survey_browse_response(report_rml): - - - - - + - - - - + + + + + + + + + + + @@ -123,107 +174,96 @@ class survey_browse_response(report_rml): - - + + + + + + - - Browse Responses - - - - - """ + """ surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response') if datas.has_key('form') and datas['form'].has_key('response_ids'): response_id = datas['form']['response_ids'][0][2] elif context.has_key('response_id'): response_id = [int(context['response_id'])] else: - response_id = surv_resp_obj.search(cr, uid, [('survey_id','in',ids)]) + response_id = surv_resp_obj.search(cr, uid, [('survey_id', 'in', ids)]) surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line') surv_obj = pooler.get_pool(cr.dbname).get('survey') surv_ans_obj = pooler.get_pool(cr.dbname).get('survey.answer') - for response in surv_resp_obj.browse(cr,uid, response_id): + for response in surv_resp_obj.browse(cr, uid, response_id): for survey in surv_obj.browse(cr, uid, [response.survey_id.id]): + tbl_width = float(_tbl_widths.replace('cm', '')) + colwidth = "4.6cm,5cm," + str(tbl_width - 16.4) +"cm,4cm,3cm" + rml += """ + + Response Create Date:- + """ + to_xml(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """ + + Response By:- + """ + to_xml(response.user_id.name) + """ + + """ status = "Not Finished" - if response.state == "done": - status = "Finished" - rml += """ - - - Survey Title - - - Response Create Date - - - Response By - - - Status - - - - - - - """ + to_xml(tools.ustr(survey.title)) + """ - - - """ + to_xml(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """ - - - """ + to_xml(response.user_id.name) + """ - - - """ + status + """ - - + if response.state == "done": status = "Finished" + colwidth = str(tbl_width - 7) + "cm," + colwidth += "7cm" + rml += """ + + """ + to_xml(tools.ustr(survey.title)) + """ + Status :- """ + to_xml(tools.ustr(status)) + """ + + """ + if survey.note: + rml += """ + """ + to_xml(tools.ustr(survey.note)) + """ """ for page in survey.page_ids: - rml += """ - - - Page :- """ + to_xml(tools.ustr(page.title)) + """ - - """ + rml += """ + Page :- """ + to_xml(tools.ustr(page.title)) + """ + """ if page.note: rml += """ - - - """ + to_xml(tools.ustr(page.note)) + """ - - """ + + """ + to_xml(tools.ustr(page.note)) + """ + """ for que in page.question_ids: rml += """ - - - Que : """ + to_xml(to_xml(que.question)) + """ - - """ - answer = surv_resp_line_obj.browse(cr,uid, surv_resp_line_obj.search(cr, uid, [('question_id','=',que.id),('response_id','=',response.id)])) + + Que : """ + to_xml(to_xml(que.question)) + """ + """ + 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 +=""" - """ + to_xml(tools.ustr(que.descriptive_text)) + """ - """ + rml +=""" + """ + to_xml(tools.ustr(que.descriptive_text)) + """ + """ 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)) + tbl_width = float(_tbl_widths.replace('cm', '')) + for i in range(0, len(que.column_heading_ids)): + cols_widhts.append(tbl_width / float(len(que.column_heading_ids))) + colWidths = "cm,".join(map(tools.ustr, cols_widhts)) + colWidths = colWidths + 'cm' matrix_ans = [] rml +="""""" for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append(col.title) - rml +=""" """ + to_xml(tools.ustr(col.title)) +"""""" + rml += """ """ + to_xml(tools.ustr(col.title)) +"""""" rml += """""" + i = 0 for row in range(0, que.no_of_rows): - rml +="""""" - table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id),('name','=',row)])) + if i%2!=0: + style='tbl_white' + else: + style='tbl_gainsboro' + i+=1 + rml += """""" + 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 = False for col in table_data: @@ -235,19 +275,15 @@ class survey_browse_response(report_rml): rml += """ """ rml += """""" else: - rml +=""" - No Response - """ + rml +=""" + No Response + """ elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']: if len(answer) and answer[0].state == "done": ans_list = [] for ans in answer[0].response_answer_ids: ans_list.append(to_xml(tools.ustr(ans.answer_id.answer))) - answer_choice=[] - _divide_columns_for_matrix = 20 - _display_ans_in_rows = 5 - _tbl_widths = 500 for ans in que['answer_choice_ids']: answer_choice.append(to_xml(tools.ustr((ans.answer)))) @@ -257,38 +293,35 @@ class survey_browse_response(report_rml): divide_list = divide_list(answer_choice,_display_ans_in_rows) for lst in divide_list: if que.type == 'multiple_choice_multiple_ans': - if len(lst)<>0 and len(lst)<>int(round(float(len(answer_choice))/_display_ans_in_rows,0)): + if len(lst) <> 0 and len(lst) <> int(round(float(len(answer_choice)) / _display_ans_in_rows, 0)): lst.append('') if not lst: del divide_list[divide_list.index(lst):] for divide in divide_list: - a = _divide_columns_for_matrix*len(divide) - b = float(_tbl_widths) - float(a) - cols_widhts=[] - for div in range(0,len(divide)): - cols_widhts.append(float(a/len(divide))) - cols_widhts.append(float(b/len(divide))) - colWidths = ",".join(map(tools.ustr, cols_widhts)) - rml+=""" - """ - for div in range(0,len(divide)): - if divide[div]!='': + a = _divide_columns_for_matrix * len(divide) + b = float(_tbl_widths.replace('cm', '')) - float(a) + cols_widhts = [] + for div in range(0, len(divide)): + cols_widhts.append(float(a / len(divide))) + cols_widhts.append(float(b / len(divide))) + colWidths = "cm,".join(map(tools.ustr, cols_widhts)) + colWidths = colWidths +'cm' + rml += """""" + for div in range(0, len(divide)): + if divide[div] != '': if que.type == 'multiple_choice_multiple_ans': if divide[div] in ans_list: rml += """ - - - - - """ + divide[div] + """""" + + + + + """ + divide[div] + """""" else: - rml+=""" - - + rml+=""" - - - """ + divide[div] + """""" + + """ + divide[div] + """""" else: if divide[div] in ans_list: rml += """ @@ -298,154 +331,162 @@ class survey_browse_response(report_rml): """ + divide[div] + """""" else: - rml+=""" - - - - - - """ + divide[div] + """""" + rml += """ + + + + + """ + divide[div] + """""" else: - rml+=""" - - """ - rml+="""""" + rml += """""" + rml += """""" if que.is_comment_require and answer[0].comment: - rml+=""" + rml += """ """ + to_xml(tools.ustr(answer[0].comment)) + """""" - else: - rml +=""" - No Response - """ + rml += """ + No Response + """ elif que.type in ['multiple_textboxes_diff_type','multiple_textboxes','date','date_and_time','numerical_textboxes','multiple_textboxes_diff_type']: if len(answer) and answer[0].state == "done": + cols_widhts = [] + cols_widhts.append(float(_tbl_widths.replace('cm',''))/2) + cols_widhts.append(float(_tbl_widths.replace('cm',''))/2) + colWidths = "cm,".join(map(tools.ustr, cols_widhts)) + colWidths = tools.ustr(colWidths) + 'cm' answer_list = {} for ans in answer[0].response_answer_ids: answer_list[ans.answer_id.answer] = ans.answer for que_ans in que['answer_choice_ids']: if que_ans.answer in answer_list: - rml +=""" - """ + to_xml(tools.ustr(que_ans.answer)) + """ - """ + to_xml(tools.ustr(answer_list[que_ans.answer])) + """ - """ + rml += """ + """ + to_xml(tools.ustr(que_ans.answer)) + """ + """ + to_xml(tools.ustr(answer_list[que_ans.answer])) + """ + """ else: - rml +=""" - """ + to_xml(tools.ustr(que_ans.answer)) + """ - - """ + rml += """ + """ + to_xml(tools.ustr(que_ans.answer)) + """ + + """ else: - rml +=""" - No Response - """ + rml += """ + No Response + """ elif que.type in ['single_textbox']: if len(answer) and answer[0].state == "done": - rml +=""" - """ + to_xml(tools.ustr(answer[0].single_text)) + """ - """ + rml += """ + """ + to_xml(tools.ustr(answer[0].single_text)) + """ + """ else: - rml +=""" - No Response - """ + rml += """ + No Response + """ elif que.type in ['comment']: if len(answer) and answer[0].state == "done": - rml +=""" - """ + to_xml(tools.ustr(answer[0].comment)) + """ - """ + rml += """ + """ + to_xml(tools.ustr(answer[0].comment)) + """ + """ else: - rml +=""" - No Response - """ - elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','matrix_of_drop_down_menus']: + rml += """ + No Response + """ + 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.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: + if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and 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 + if len(que.column_heading_ids): + cols_widhts.append(float(_tbl_widths.replace('cm','')) / float(2.0)) + for col in que.column_heading_ids: + cols_widhts.append(float((float(_tbl_widths.replace('cm','')) / float(2.0)) / len(que.column_heading_ids))) + else: + cols_widhts.append(float(_tbl_widths.replace('cm',''))) + tmp = 0.0 + sum = 0.0 i = 0 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: for col in cols_widhts: - if i==0: - cols_widhts[i] = cols_widhts[i]/2.0 + 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 = [(0,''),] + i += 1 + cols_widhts.append(round(tmp, 2)) + colWidths = "cm,".join(map(tools.ustr, cols_widhts)) + colWidths = colWidths + 'cm' + matrix_ans = [(0, ''),] for col in que.column_heading_ids: if col.title not in matrix_ans: - matrix_ans.append((col.id,col.title)) + matrix_ans.append((col.id, col.title)) len_matrix = len(matrix_ans) - if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: + if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column: matrix_ans.append(que.column_name) - rml+="""""" + rml += """""" for mat_col in range(0, len(matrix_ans)): rml+="""""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """""" rml +="""""" rml+="""""" i=0 for ans in que.answer_choice_ids: - if i%2!=0: - style='ans_tbl_white' + if i%2 != 0: + style = 'ans_tbl_white' else: - style='ans_tbl_gainsboro' - i+=1 - rml+=""" - """ + to_xml(tools.ustr(ans.answer)) + """""" + style = 'ans_tbl_gainsboro' + i += 1 + rml += """ + """ + to_xml(tools.ustr(ans.answer)) + """""" 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.column_id.id == matrix_ans[mat_col][0]: - comment_value = to_xml(tools.ustr(res_ans.comment_field)) + comment_value = to_xml(tools.ustr(res_ans.comment_field)) if que.type in ['matrix_of_drop_down_menus']: value = """""" + to_xml(tools.ustr(res_ans.value_choice)) + """""" - elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: + elif que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']: value = """ - - - - """ + + + + """ elif que.type in ['matrix_of_choices_only_multi_ans']: value = """ - - - - - """ + + + + + """ 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 = """ - - """ + + """ elif que.type in ['matrix_of_choices_only_multi_ans']: value = """ - - """ + + """ rml+= """""" + value + """""" if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: - if comment_value=='False': + if comment_value == 'False': comment_value = '' - rml+= """"""+ to_xml(tools.ustr(comment_value)) + """""" - rml+=""" """ + rml += """""" + to_xml(tools.ustr(comment_value)) + """""" + rml += """""" if que.is_comment_require: - rml+=""" + rml += """ """ + to_xml(tools.ustr(answer[0].comment or '')) + """""" else: - rml +=""" - No Response - """ - - rml += """""" + rml += """ + No Response + """ + if datas.has_key('form') and not datas['form']['without_pagebreak']: + rml += """""" + elif not datas.has_key('form'): + rml += """""" + else: + rml += """""" rml += """""" report_type = datas.get('report_type', 'pdf') create_doc = self.generators[report_type] @@ -455,4 +496,3 @@ class survey_browse_response(report_rml): survey_browse_response('report.survey.browse.response', 'survey','','') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/survey/wizard/wizard_browse_answer.py b/addons/survey/wizard/wizard_browse_answer.py index 00b56268a1a..6a81edce627 100644 --- a/addons/survey/wizard/wizard_browse_answer.py +++ b/addons/survey/wizard/wizard_browse_answer.py @@ -30,11 +30,32 @@ from tools.translate import _ _survey_form = '''
- + + + + + + + ''' _survey_fields = { - 'response_ids': {'string': 'Survey', 'type': 'many2many', 'relation': 'survey.response'}, + 'response_ids': {'string': 'Survey', 'type': 'many2many', 'relation': 'survey.response','required':'1'}, + 'orientation':{ + 'string':"Orientation", + 'type':'selection', + 'selection':[('vertical','Portrait(Vertical)'), + ('horizontal','Landscape(Horizontal)')], + 'default': lambda *a:'vertical'}, + 'paper_size':{ + 'string':"Paper Size", + 'type':'selection', + 'selection':[('letter','Letter (8.5" x 11")'), + ('legal','Legal (8.5" x 14")'), + ('a4','A4 (210mm x 297mm)')], + 'default': lambda *a:'letter'}, + 'page_number': {'string':'Include Page Numbers', 'type':'boolean', 'default':lambda *a: 0}, + 'without_pagebreak': {'string':'Print Without Page Breaks', 'type':'boolean', 'default':lambda *a: 0}, } class browse_answer_wizard(wizard.interface):