diff --git a/addons/survey/report/survey_browse_response.py b/addons/survey/report/survey_browse_response.py index 0a9104495b0..7192a6faeb3 100644 --- a/addons/survey/report/survey_browse_response.py +++ b/addons/survey/report/survey_browse_response.py @@ -143,12 +143,13 @@ class survey_browse_response(report_rml): 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 survey in surv_obj.browse(cr, uid, [response.survey_id.id]): status = "Not Finished" if response.state == "done": status = "Finished" - rml += """ + rml += """ Survey Title @@ -164,7 +165,7 @@ class survey_browse_response(report_rml): - + """ + to_xml(tools.ustr(survey.title)) + """ @@ -239,25 +240,100 @@ class survey_browse_response(report_rml): """ 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: - rml +=""" - """ + to_xml(tools.ustr(ans.answer_id.answer)) + """ - """ - if que.comment_field_type: - if answer[0].comment: - rml+=""" + 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)))) + + def divide_list(lst, n): + return [lst[i::n] for i in range(n)] + + 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)): + 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]!='': + if que.type == 'multiple_choice_multiple_ans': + if divide[div] in ans_list: + rml += """ + + + + + """ + divide[div] + """""" + else: + rml+=""" + + + + + + """ + divide[div] + """""" + else: + if divide[div] in ans_list: + rml += """ + + + + + """ + divide[div] + """""" + else: + rml+=""" + + + + + + """ + divide[div] + """""" + else: + rml+=""" + + """ + rml+="""""" + if que.is_comment_require and answer[0].comment: + rml+=""" """ + to_xml(tools.ustr(answer[0].comment)) + """""" + else: 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": + answer_list = {} for ans in answer[0].response_answer_ids: - rml +=""" - """ + to_xml(tools.ustr(ans.answer_id.answer)) + """ - """ + to_xml(tools.ustr(ans.answer)) + """ - """ + 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])) + """ + """ + else: + rml +=""" + """ + to_xml(tools.ustr(que_ans.answer)) + """ + + """ else: rml +=""" No Response diff --git a/addons/survey/survey.py b/addons/survey/survey.py index abd0bc68ea2..808f900dcd4 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -269,16 +269,26 @@ class survey_question(osv.osv): } def on_change_type(self, cr, uid, ids, type, context=None): + val = {} + val['is_require_answer'] = False + val['is_comment_require'] = False + val['is_validation_require'] = False + val['comment_column'] = False if type in ['multiple_textboxes_diff_type']: - return {'value': {'in_visible_answer_type':False}} + val['in_visible_answer_type'] = False + return {'value': val} if type in ['rating_scale']: - return {'value': {'in_visible_rating_weight':False,'in_visible_menu_choice':True}} + val.update({'in_visible_rating_weight':False,'in_visible_menu_choice':True}) + return {'value': val} elif type in ['matrix_of_drop_down_menus']: - return {'value': {'in_visible_rating_weight':True,'in_visible_menu_choice':False}} + val.update({'in_visible_rating_weight':True,'in_visible_menu_choice':False}) + return {'value': val} elif type in ['single_textbox']: - return {'value': {'in_visible_rating_weight':True,'in_visible_menu_choice':True}} + val.update({'in_visible_rating_weight':True,'in_visible_menu_choice':True}) + return {'value': val} else: - return {'value': {'in_visible_rating_weight':True,'in_visible_menu_choice':True,'in_visible_answer_type':True}} + val.update({'in_visible_rating_weight':True,'in_visible_menu_choice':True,'in_visible_answer_type':True}) + return {'value': val} def write(self, cr, uid, ids, vals, context=None): questions = self.read(cr,uid, ids, ['answer_choice_ids', 'type', 'required_type','req_ans', 'minimum_req_ans', 'maximum_req_ans', 'column_heading_ids']) @@ -474,7 +484,8 @@ class survey_answer(osv.osv): 'sequence' : fields.integer('Sequence'), 'response' : fields.function(_calc_response_avg, method=True, string="#Response", multi='sums'), 'average' : fields.function(_calc_response_avg, method=True, string="#Avg", multi='sums'), - 'type' : fields.selection([('char','Character'),('date','Date'),('datetime','Date & Time'),('integer','Integer'),('float','Float')], "Type of Answer",required=1), + 'type' : fields.selection([('char','Character'),('date','Date'),('datetime','Date & Time'),('integer','Integer'),('float','Float'),('selection','Selection'),('email','Email Address')], "Type of Answer",required=1), + 'menu_choice' : fields.text('Menu Choices'), 'in_visible_answer_type':fields.boolean('Is Answer Type Invisible??') } _defaults = { @@ -702,7 +713,10 @@ class survey_question_wiz(osv.osv_memory): fields = {} pag_rec = page_obj.read(cr, uid, p_id) xml_form = etree.Element('form', {'string': _(tools.ustr(pag_rec['title']))}) - etree.SubElement(xml_form, 'label', {'string': to_xml(tools.ustr(pag_rec['note'] or '')), 'align': '0.0', 'colspan':'4'}) + xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) + if pag_rec['note']: + for que_test in pag_rec['note'].split('\n'): + etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align':"0.0"}) que_ids = pag_rec['question_ids'] qu_no = 0 for que in que_ids: @@ -832,12 +846,21 @@ class survey_question_wiz(osv.osv_memory): elif que_rec['type'] == 'multiple_textboxes_diff_type': xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in ans_ids: - etree.SubElement(xml_group, 'field', {'width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"}) - if ans['type'] == "char" : + if ans['type'] == "email" : fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type':'char', 'size':255, 'string':ans['answer']} + etree.SubElement(xml_group, 'field', {'widget':'email','width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"}) else: - fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type': str(ans['type']), 'string':ans['answer']} - + etree.SubElement(xml_group, 'field', {'width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"}) + if ans['type'] == "char" : + fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type':'char', 'size':255, 'string':ans['answer']} + elif ans['type'] in ['integer','float','date','datetime']: + fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type': str(ans['type']), 'string':ans['answer']} + else: + selection = [] + if ans['menu_choice']: + for item in ans['menu_choice'].split('\n'): + if item and not item.strip() == '': selection.append((item ,item)) + fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type':'selection', 'selection' : selection, 'string':ans['answer']} if que_rec['type'] in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale'] and que_rec['is_comment_require']: if que_rec['type'] in ['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans'] and que_rec['comment_field_type'] in ['char','text'] and que_rec['make_comment_field']: etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_otherfield", 'colspan':"4"}) @@ -1031,10 +1054,10 @@ class survey_question_wiz(osv.osv_memory): comment_value = True else: error = False - if que_rec['comment_valid_type'] == 'must_be_specific_length': + if que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_specific_length': if (not val1 and que_rec['comment_minimum_no']) or len(val1) < que_rec['comment_minimum_no'] or len(val1) > que_rec['comment_maximum_no']: error = True - elif que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: error = False try: if que_rec['comment_valid_type'] == 'must_be_whole_number': @@ -1051,7 +1074,7 @@ class survey_question_wiz(osv.osv_memory): error = True except: error = True - elif que_rec['comment_valid_type'] == 'must_be_email_address': + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_email_address': import re if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None: error = True @@ -1067,10 +1090,10 @@ class survey_question_wiz(osv.osv_memory): select_count += 1 elif val1 and key1.split('_')[0] == que_id and (key1.split('_')[1] == "single" or (len(key1.split('_')) > 2 and key1.split('_')[2] == 'multi')): error = False - if que_rec['validation_type'] == 'must_be_specific_length': + if que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_specific_length': if (not val1 and que_rec['validation_minimum_no']) or len(val1) < que_rec['validation_minimum_no'] or len(val1) > que_rec['validation_maximum_no']: error = True - elif que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: + elif que_rec['is_validation_require'] and que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: error = False try: if que_rec['validation_type'] == 'must_be_whole_number': @@ -1087,7 +1110,7 @@ class survey_question_wiz(osv.osv_memory): error = True except: error = True - elif que_rec['validation_type'] == 'must_be_email_address': + elif que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_email_address': import re if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val1) == None: error = True @@ -1213,10 +1236,10 @@ class survey_question_wiz(osv.osv_memory): comment_value = True else: error = False - if que_rec['comment_valid_type'] == 'must_be_specific_length': + if que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_specific_length': if (not val and que_rec['comment_minimum_no']) or len(val) < que_rec['comment_minimum_no'] or len(val) > que_rec['comment_maximum_no']: error = True - elif que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: try: if que_rec['comment_valid_type'] == 'must_be_whole_number': value = int(val) @@ -1232,7 +1255,7 @@ class survey_question_wiz(osv.osv_memory): error = True except: error = True - elif que_rec['comment_valid_type'] == 'must_be_email_address': + elif que_rec['is_comment_require'] and que_rec['comment_valid_type'] == 'must_be_email_address': import re if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None: error = True @@ -1246,10 +1269,10 @@ class survey_question_wiz(osv.osv_memory): select_count += 1 elif val and (key.split('_')[1] == "single" or (len(key.split('_')) > 2 and key.split('_')[2] == 'multi')): error = False - if que_rec['validation_type'] == 'must_be_specific_length': + if que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_specific_length': if (not val and que_rec['validation_minimum_no']) or len(val) < que_rec['validation_minimum_no'] or len(val) > que_rec['validation_maximum_no']: error = True - elif que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: + elif que_rec['is_validation_require'] and que_rec['validation_type'] in ['must_be_whole_number', 'must_be_decimal_number', 'must_be_date']: error = False try: if que_rec['validation_type'] == 'must_be_whole_number': @@ -1266,7 +1289,7 @@ class survey_question_wiz(osv.osv_memory): error = True except Exception ,e: error = True - elif que_rec['validation_type'] == 'must_be_email_address': + elif que_rec['is_validation_require'] and que_rec['validation_type'] == 'must_be_email_address': import re if re.match("^[a-zA-Z0-9._%-+]+@[a-zA-Z0-9._%-]+.[a-zA-Z]{2,6}$", val) == None: error = True diff --git a/addons/survey/survey_demo.xml b/addons/survey/survey_demo.xml index 702a32a8b76..38784e23ce5 100644 --- a/addons/survey/survey_demo.xml +++ b/addons/survey/survey_demo.xml @@ -2720,7 +2720,7 @@ Email address - char + email diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 7e8760d6318..3536685ea0a 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -94,14 +94,15 @@ - - - - - - + + + + + + + @@ -353,15 +354,16 @@ - - - - - - + + + + + + + @@ -548,15 +550,16 @@ - - - - - - + + + + + + + @@ -713,15 +716,16 @@ - - - - - - + + + + + + + @@ -809,7 +813,11 @@ - + + + + +