[IMP]:survey:(Ref-YSA)

- Improved browse response report.
- Added selection and email type in multiple textboxes with diff type.
- Solved bug of change question type then not work properly.

bzr revid: apa@tinyerp.com-20100205094802-nk9zp56x3njm90pv
This commit is contained in:
apa-tiny 2010-02-05 15:18:02 +05:30
parent 1e1ef3397c
commit c773eef8a9
4 changed files with 168 additions and 61 deletions

View File

@ -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 += """<blockTable colWidths="230.0,120.0,100.0,50" style="Table_heading">
rml += """<blockTable colWidths="210.0,120.0,100.0,70" style="Table_heading">
<tr>
<td>
<para style="terp_tblheader_General_Centre">Survey Title </para>
@ -164,7 +165,7 @@ class survey_browse_response(report_rml):
</td>
</tr>
</blockTable>
<blockTable colWidths="230.0,120.0,100.0,50" style="Table_head_2">
<blockTable colWidths="210.0,120.0,100.0,70" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
@ -239,25 +240,100 @@ class survey_browse_response(report_rml):
</blockTable>"""
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 +="""<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>
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+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1">
<tr>"""
for div in range(0,len(divide)):
if divide[div]!='':
if que.type == 'multiple_choice_multiple_ans':
if divide[div] in ans_list:
rml += """<td><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></td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml+="""
<td>
<illustration>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/>
</illustration>
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
if divide[div] in ans_list:
rml += """<td><illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/>
<circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration></td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml+="""
<td>
<illustration>
<circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/>
</illustration>
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml+="""
<td></td>
<td></td>"""
rml+="""</tr></blockTable>"""
if que.is_comment_require and 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>"""
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 +="""<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>"""
answer_list[ans.answer_id.answer] = ans.answer
for que_ans in que['answer_choice_ids']:
if que_ans.answer in answer_list:
rml +="""<blockTable colWidths="200,300" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
<td> <para style="response">""" + to_xml(tools.ustr(answer_list[que_ans.answer])) + """</para></td></tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="200,300" style="Table1">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
<td> <para style="response"></para></td></tr>
</blockTable>"""
else:
rml +="""<blockTable colWidths="500" style="Table1">
<tr> <td> <para style="response">No Response</para></td> </tr>

View File

@ -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

View File

@ -2720,7 +2720,7 @@
<field eval="0" name="in_visible_answer_type"/>
<field name="answer">Email address</field>
<field name="question_id" ref="survey_question_8_Community"/>
<field name="type">char</field>
<field name="type">email</field>
<field eval="4" name="sequence"/>
</record>
</data>

View File

@ -94,14 +94,15 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','single_textbox'), ('type','!=','multiple_textboxes')]}">
<separator string="Validation" colspan="4"/>
@ -353,15 +354,16 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','single_textbox'), ('type','!=','multiple_textboxes')]}">
<separator string="Validation" colspan="4"/>
<group colspan="4">
@ -548,15 +550,16 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','single_textbox'), ('type','!=','multiple_textboxes')]}">
<separator string="Validation" colspan="4"/>
<group colspan="4">
@ -713,15 +716,16 @@
<field name="comment_valid_err_msg" nolabel="1" colspan="4"/>
</group>
</group>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','matrix_of_choices_only_one_ans'),('type','!=','rating_scale')]}">
<field name="comment_column"/>
<group colspan="2" attrs="{'invisible':[('comment_column','!=',True)]}">
<field name="column_name" colspan="2"/>
</group>
</group>
<newline/>
<group attrs="{'invisible':[('type','!=','single_textbox'), ('type','!=','multiple_textboxes')]}">
<separator string="Validation" colspan="4"/>
<group colspan="4">
@ -809,7 +813,11 @@
<field name="sequence"/>
<field name="in_visible_answer_type" invisible="1"/>
<group colspan="4" attrs="{'invisible':[('in_visible_answer_type','=',True)]}">
<field name="type"/>
<field name="type" colspan="2"/>
<group colspan="4" attrs="{'invisible':[('type','!=','selection')]}">
<separator string="Menu Choices (each choice on separate by lines)" colspan="4"/>
<field name="menu_choice" colspan="4" nolabel="1"/>
</group>
</group>
</form>
</field>