# -*- encoding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## import openerp from openerp import tools from openerp.report.interface import report_rml from openerp.tools import to_xml class survey_form(report_rml): def create(self, cr, uid, ids, datas, context): _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 _pageSize = ('29.7cm','21.1cm') if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('21.6cm','27.9cm') elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('21.6cm','35.6cm') elif datas['form'].get('paper_size','') == 'a4': _pageSize = ('21.1cm','29.7cm') elif datas.has_key('form') and datas['form'].get('orientation','') == 'horizontal': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('27.9cm','21.6cm') elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('35.6cm','21.6cm') elif datas['form'].get('paper_size','') == 'a4': _pageSize = ('29.7cm','21.1cm') _frame_width = tools.ustr(_pageSize[0]) _frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm' _tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm' rml=""" """ surv_obj = openerp.registry(cr.dbname)['survey'] for survey in surv_obj.browse(cr,uid,ids): rml += """ """ + to_xml(tools.ustr(survey.title)) + """ """ if survey.note: rml += """ """ + to_xml(tools.ustr(survey.note)) + """ """ seq = 0 for page in survey.page_ids: seq += 1 rml += """ """+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """ """ if page.note: rml += """ """ + to_xml(tools.ustr(page.note or '')) + """ """ for que in page.question_ids: cols_widhts = [] rml += """ """ + to_xml(tools.ustr(que.question)) + """ """ if que.type in ['descriptive_text']: cols_widhts.append(float(_tbl_widths.replace('cm',''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths + 'cm' rml += """ """ + to_xml(tools.ustr(que.descriptive_text)) + """ """ elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']: answer = [] for ans in que.answer_choice_ids: answer.append(to_xml(tools.ustr((ans.answer)))) def divide_list(lst, n): return [lst[i::n] for i in range(n)] divide_list = divide_list(answer,_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))/_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.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': rml += """ """ + divide[div] + """""" else: rml += """ """ + divide[div] + """""" else: rml += """ """ rml += """ """ elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']: 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.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 = "cm,".join(map(tools.ustr, cols_widhts)) colWidths = colWidths+'cm' matrix_ans = ['',] for col in que.column_heading_ids: if col.title not in matrix_ans: matrix_ans.append(col.title) if que.comment_column: matrix_ans.append(to_xml(tools.ustr(que.column_name))) rml+="""""" for mat_col in matrix_ans: rml += """""" + to_xml(tools.ustr(mat_col)) + """""" rml += """""" 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 += """ """ + to_xml(tools.ustr(ans.answer)) + """""" rec_width = float((sum-tmp)*10+100) value = "" if que.type in ['matrix_of_drop_down_menus']: value = """ """ elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: value = """ """ else: value = """ """ for mat_col in range(1,len(matrix_ans)): if matrix_ans[mat_col] == que.column_name: if mat_col == 1: rml += """ """ + to_xml(tools.ustr(que.column_name)) + """""" else: rml += """""" else: rml += """""" + value + """""" rml += """""" elif que.type in ['multiple_textboxes', 'numerical_textboxes', 'date_and_time','date','multiple_textboxes_diff_type']: 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' for ans in que.answer_choice_ids: rml += """ """ + to_xml(tools.ustr(ans.answer)) + """ """ elif que.type in ['comment']: cols_widhts.append(float(_tbl_widths.replace('cm',''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) rml += """ """ elif que.type in ['single_textbox']: cols_widhts.append(float(_tbl_widths.replace('cm',''))) colWidths = "cm,".join(map(tools.ustr, cols_widhts)) rml += """ """ elif que.type in ['table']: 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' rml += """""" for col in que.column_heading_ids: rml+="""""" + to_xml(tools.ustr(col.title)) + """""" rml += """""" i = 0 for r in range(0,que.no_of_rows): if i%2 != 0: style = 'tbl_white' else: style = 'tbl_gainsboro' i += 1 rml += """""" for c in que.column_heading_ids: rml += """ """ rml += """""" 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] pdf = create_doc(rml, title=self.title) return (pdf, report_type) survey_form('report.survey.form', 'survey','','') # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: