[IMP] Survey:-Improvement in view and code. ref-YSA

bzr revid: apa@tinyerp.com-20100127135523-kra22c2hy0w97o67
This commit is contained in:
apa-tiny 2010-01-27 19:25:23 +05:30
parent cb5b75b569
commit f88791536c
8 changed files with 872 additions and 770 deletions

View File

@ -100,10 +100,6 @@ class survey_analysis(report_rml):
</para>"""
surv_obj = pooler.get_pool(cr.dbname).get('survey')
for survey in surv_obj.browse(cr, uid, ids):
if survey.question_prefix:
prefix = survey.question_prefix + " : "
else:
prefix = ''
rml += """<blockTable colWidths="280.0,100.0,120.0" style="Table_heading">
<tr>
<td>
@ -139,7 +135,7 @@ class survey_analysis(report_rml):
for que in page.question_ids:
rml +="""<blockTable colWidths="500" style="Table5">
<tr>
<td><para style="question">""" + to_xml(tools.ustr(prefix)) + to_xml(tools.ustr(que.question)) + """</para></td>
<td><para style="question">Que : """ + to_xml(tools.ustr(que.question)) + """</para></td>
</tr>
</blockTable>"""
cols_widhts = []

View File

@ -131,224 +131,222 @@ class survey_browse_response(report_rml):
</para>
"""
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)])
surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line')
surv_obj = pooler.get_pool(cr.dbname).get('survey')
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:
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(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """</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:
for response in surv_resp_obj.browse(cr,uid, response_id):
for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
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(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """</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(tools.ustr(page.title)) + """</para></td>
</tr>
</blockTable>"""
for que in page.question_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>"""
<blockTable colWidths="500" style="Table5">
<tr>
<td><para style="question">Que : """ + 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>"""
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>"""
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:
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:
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:
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>"""
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>
<tr> <td> <para style="response">""" + to_xml(tools.ustr(ans.answer_id.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 ['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:
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:
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>
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(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>"""
rml += """<pageBreak/>"""
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:
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

@ -135,10 +135,6 @@ class survey_form(report_rml):
<story>"""
surv_obj = pooler.get_pool(cr.dbname).get('survey')
for survey in surv_obj.browse(cr,uid,ids):
if survey.question_prefix:
prefix = survey.question_prefix + " : "
else:
prefix = ''
if datas.has_key('form') and datas['form']['survey_title']:
rml += """
<blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl">
@ -156,7 +152,7 @@ class survey_form(report_rml):
rml +="""
<para style="P2"><font></font></para>
<blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
<tr><td><para style="question">""" + to_xml(tools.ustr(prefix)) + to_xml(tools.ustr(que.question)) + """</para></td></tr>
<tr><td><para style="question">Que : """ + to_xml(tools.ustr(que.question)) + """</para></td></tr>
</blockTable>
<para style="P2"><font></font></para>"""
if que.type in ['descriptive_text']:

View File

@ -32,10 +32,25 @@ import tools
from mx.DateTime import *
import netsvc
class survey_type(osv.osv):
_name = 'survey.type'
_description = 'Survey Type'
_columns = {
'name' : fields.char("Name", size=128, required=1),
'code' : fields.char("Code", size=64),
}
survey_type()
class survey(osv.osv):
_name = 'survey'
_description = 'Survey'
_rec_name = 'title'
def default_get(self, cr, uid, fields, context={}):
data = super(survey, self).default_get(cr, uid, fields, context)
data['responsible_id'] = uid
return data
_columns = {
'title' : fields.char('Survey Title', size=128, required=1),
'page_ids' : fields.one2many('survey.page', 'survey_id', 'Page'),
@ -51,14 +66,15 @@ class survey(osv.osv):
'note' : fields.text('Description', size=128),
'history' : fields.one2many('survey.history', 'survey_id', 'History Lines', readonly=True),
'users': fields.many2many('res.users', 'survey_users_rel', 'sid', 'uid', 'Users'),
'question_prefix' : fields.char('Question Prefix', size=128),
'send_response' : fields.boolean('E-mail Notification on Response'),
'type' : fields.many2one('survey.type', 'Type')
}
_defaults = {
'state' : lambda * a: "draft",
'tot_start_survey' : lambda * a: 0,
'tot_comp_survey' : lambda * a: 0,
'send_response' : lambda * a: 1,
'response_user' : lambda * a:1,
}
def survey_draft(self, cr, uid, ids, arg):
@ -154,14 +170,14 @@ class survey_question(osv.osv):
for id in ids1:
val[id] = 0
return val
_columns = {
'page_id' : fields.many2one('survey.page', 'Survey Page', ondelete='cascade', required=1),
'question' : fields.char('Question', size=128, required=1),
'answer_choice_ids' : fields.one2many('survey.answer', 'question_id', 'Answer'),
'response_ids' : fields.one2many('survey.response.line', 'question_id', 'Response', readonly=1),
'is_require_answer' : fields.boolean('Required Answer'),
'required_type' : fields.selection([('',''), ('all','All'), ('at least','At Least'), ('at most','At Most'), ('exactly','Exactly'), ('a range','A Range')], 'Respondent must answer'),
'is_require_answer' : fields.boolean('Require Answer to Question (optional)'),
'required_type' : fields.selection([('all','All'), ('at least','At Least'), ('at most','At Most'), ('exactly','Exactly'), ('a range','A Range')], 'Respondent must answer'),
'req_ans' : fields.integer('#Required Answer'),
'maximum_req_ans' : fields.integer('Maximum Required Answer'),
'minimum_req_ans' : fields.integer('Minimum Required Answer'),
@ -183,8 +199,9 @@ class survey_question(osv.osv):
('date_and_time','Date and Time'),('descriptive_text','Descriptive Text'),
('table','Table'),
], 'Question Type', required=1,),
'is_comment_require' : fields.boolean('Add Comment Field (optional)'),
'comment_label' : fields.char('Field Label', size = 255),
'comment_field_type' : fields.selection([('',''),('char', 'Single Line Of Text'), ('text', 'Paragraph of Text')], 'Comment Field Type'),
'comment_field_type' : fields.selection([('char', 'Single Line Of Text'), ('text', 'Paragraph of Text')], 'Comment Field Type'),
'comment_valid_type' : fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''),
('must_be_specific_length', 'Must Be Specific Length'),
('must_be_whole_number', 'Must Be A Whole Number'),
@ -201,6 +218,7 @@ class survey_question(osv.osv):
'comment_valid_err_msg' : fields.text('Error message'),
'make_comment_field' : fields.boolean('Make Comment Field an Answer Choice'),
'make_comment_field_err_msg' : fields.text('Error message'),
'is_validation_require' : fields.boolean('Validate Text (optional)'),
'validation_type' : fields.selection([('do_not_validate', '''Don't Validate Comment Text.'''),\
('must_be_specific_length', 'Must Be Specific Length'),\
('must_be_whole_number', 'Must Be A Whole Number'),\
@ -228,8 +246,10 @@ class survey_question(osv.osv):
'sequence' : lambda * a: 1,
'type' : lambda * a: 'multiple_choice_multiple_ans',
'req_error_msg' : lambda * a: 'This question requires an answer.',
'required_type' : lambda * a: '',
'comment_label' : lambda * a: 'Other',
'required_type' : lambda * a: 'at least',
'req_ans' : lambda * a: 1,
'comment_field_type' : lambda * a: 'char',
'comment_label' : lambda * a: 'Other (please specify)',
'comment_valid_type' : lambda * a: 'do_not_validate',
'comment_valid_err_msg' : lambda * a : 'The comment you entered is in an invalid format.',
'validation_type' : lambda * a: 'do_not_validate',
@ -280,34 +300,35 @@ class survey_question(osv.osv):
req_type = vals['required_type']
else:
req_type = question['required_type']
if req_type in ['at least', 'at most', 'exactly']:
if vals.has_key('req_ans'):
if not vals['req_ans'] or vals['req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
else:
if not question['req_ans'] or question['req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
if req_type == 'a range':
minimum_ans = 0
maximum_ans = 0
if vals.has_key('minimum_req_ans'):
minimum_ans = vals['minimum_req_ans']
if not vals['minimum_req_ans'] or vals['minimum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
else:
minimum_ans = question['minimum_req_ans']
if not question['minimum_req_ans'] or question['minimum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
if vals.has_key('maximum_req_ans'):
maximum_ans = vals['maximum_req_ans']
if not vals['maximum_req_ans'] or vals['maximum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
else:
maximum_ans = question['maximum_req_ans']
if not question['maximum_req_ans'] or question['maximum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
if maximum_ans <= minimum_ans:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer is greater than Minimum Required Answer"))
if que_type in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time']:
if req_type in ['at least', 'at most', 'exactly']:
if vals.has_key('req_ans'):
if not vals['req_ans'] or vals['req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
else:
if not question['req_ans'] or question['req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
if req_type == 'a range':
minimum_ans = 0
maximum_ans = 0
if vals.has_key('minimum_req_ans'):
minimum_ans = vals['minimum_req_ans']
if not vals['minimum_req_ans'] or vals['minimum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
else:
minimum_ans = question['minimum_req_ans']
if not question['minimum_req_ans'] or question['minimum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
if vals.has_key('maximum_req_ans'):
maximum_ans = vals['maximum_req_ans']
if not vals['maximum_req_ans'] or vals['maximum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
else:
maximum_ans = question['maximum_req_ans']
if not question['maximum_req_ans'] or question['maximum_req_ans'] > ans_len:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (ans_len + 1))
if maximum_ans <= minimum_ans:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer is greater than Minimum Required Answer"))
if question['type'] == 'matrix_of_drop_down_menus' and vals.has_key('column_heading_ids'):
for col in vals['column_heading_ids']:
if col[2].has_key('menu_choice') and not col[2]['menu_choice']:
@ -325,18 +346,19 @@ class survey_question(osv.osv):
if vals.has_key('column_heading_ids') and not len(vals['column_heading_ids']):
if vals.has_key('type') and vals['type'] in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale']:
raise osv.except_osv(_('Error !'),_("You must enter one or more column heading."))
if vals.has_key('required_type') and vals['required_type'] in ['at least', 'at most', 'exactly']:
if vals['req_ans'] > len(vals['answer_choice_ids']) or not vals['req_ans']:
raise osv.except_osv(_('Error !'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1))
if vals.has_key('required_type') and vals['required_type'] == 'a range':
minimum_ans = vals['minimum_req_ans']
maximum_ans = vals['maximum_req_ans']
if vals['minimum_req_ans'] > len(vals['answer_choice_ids']) or not vals['minimum_req_ans']:
raise osv.except_osv(_('Error !'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1))
if vals['maximum_req_ans'] > len(vals['answer_choice_ids']) or not vals['maximum_req_ans']:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1))
if maximum_ans <= minimum_ans:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer is greater than Minimum Required Answer"))
if vals['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans', 'matrix_of_drop_down_menus', 'rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time']:
if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] in ['at least', 'at most', 'exactly']:
if vals['req_ans'] > len(vals['answer_choice_ids']) or not vals['req_ans']:
raise osv.except_osv(_('Error !'),_("#Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1))
if vals.has_key('is_require_answer') and vals.has_key('required_type') and vals['required_type'] == 'a range':
minimum_ans = vals['minimum_req_ans']
maximum_ans = vals['maximum_req_ans']
if vals['minimum_req_ans'] > len(vals['answer_choice_ids']) or not vals['minimum_req_ans']:
raise osv.except_osv(_('Error !'),_("Minimum Required Answer you entered is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1))
if vals['maximum_req_ans'] > len(vals['answer_choice_ids']) or not vals['maximum_req_ans']:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer you entered for your maximum is greater than the number of answer. Please use a number that is smaller than %d.") % (len(vals['answer_choice_ids'])+1))
if maximum_ans <= minimum_ans:
raise osv.except_osv(_('Error !'),_("Maximum Required Answer is greater than Minimum Required Answer"))
if vals['type'] == 'matrix_of_drop_down_menus':
for col in vals['column_heading_ids']:
if not col[2]['menu_choice']:
@ -524,6 +546,12 @@ survey_response_answer()
class survey_name_wiz(osv.osv_memory):
_name = 'survey.name.wiz'
def default_get(self, cr, uid, fields, context={}):
data = super(survey_name_wiz, self).default_get(cr, uid, fields, context)
if context.has_key('survey_id'):
data['survey_id'] = context['survey_id']
return data
def _get_survey(self, cr, uid, context=None):
surv_obj = self.pool.get("survey")
result = []
@ -651,7 +679,7 @@ class survey_question_wiz(osv.osv_memory):
que_rec = que_obj.read(cr, uid, que)
descriptive_text = ""
separator_string = tools.ustr(qu_no) + "." + tools.ustr(que_rec['question'])
if not context.has_key('active') and (que_rec['is_require_answer'] or que_rec['required_type'] != ''):
if not context.has_key('active') and que_rec['is_require_answer']:
star='*'
else:
star=''
@ -755,7 +783,7 @@ class survey_question_wiz(osv.osv_memory):
for col in que_col_head.read(cr, uid, que_rec['column_heading_ids']):
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_table_" + tools.ustr(col['id']) +"_"+ tools.ustr(row), 'nolabel':"1"})
fields[tools.ustr(que) + "_table_" + tools.ustr(col['id']) +"_"+ tools.ustr(row)] = {'type':'char','size':255,'views':{}}
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']:
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"})
fields[tools.ustr(que) + "_otherfield"] = {'type':'boolean', 'string':que_rec['comment_label'], 'views':{}}
@ -944,14 +972,14 @@ class survey_question_wiz(osv.osv_memory):
else:
error = False
if que_rec['comment_valid_type'] == 'must_be_specific_length':
if (not val1 and que_rec['validation_minimum_no']) or len(val1) < que_rec['validation_maximum_no'] or len(val1) > que_rec['comment_maximum_no']:
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']:
error = False
try:
if que_rec['comment_valid_type'] == 'must_be_whole_number':
value = int(val1)
if value < que_rec['validation_minimum_no'] or value > que_rec['validation_maximum_no']:
if value < que_rec['comment_minimum_no'] or value > que_rec['comment_maximum_no']:
error = True
elif que_rec['comment_valid_type'] == 'must_be_decimal_number':
value = float(val1)
@ -1057,7 +1085,7 @@ class survey_question_wiz(osv.osv_memory):
sur_name_read['store_ans'].pop(res)
surv_name_wiz.write(cr, uid, [context['sur_name_id']], {'response' :0})
raise osv.except_osv(_('Error re !'), _("'" + que_rec['question'] + "' " + tools.ustr(que_rec['numeric_required_sum_err_msg'])))
if que_rec['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['required_type']:
if que_rec['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']:
if matrix_list:
if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \
(que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \
@ -1228,7 +1256,7 @@ class survey_question_wiz(osv.osv_memory):
raise osv.except_osv(_('Error re !'), _("'" + que_rec['question'] + "' " + tools.ustr(que_rec['numeric_required_sum_err_msg'])))
if not select_count:
resp_obj.write(cr, uid, update, {'state': 'skip'})
if que_rec['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['required_type']:
if que_rec['type'] in ['multiple_choice_multiple_ans','matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus','rating_scale','multiple_textboxes','numerical_textboxes','date','date_and_time'] and que_rec['is_require_answer']:
if matrix_list:
if (que_rec['required_type'] == 'all' and len(list(set(matrix_list))) < len(que_rec['answer_choice_ids'])) or \
(que_rec['required_type'] == 'at least' and len(list(set(matrix_list))) < que_rec['req_ans']) or \

View File

@ -18,6 +18,5 @@
name="survey.browse.response"
rml=""
string="Browse Response"/>
</data>
</openerp>

File diff suppressed because it is too large Load Diff

View File

@ -8,5 +8,8 @@
<wizard string="Print Survey" id="wizard_print_survey"
model="survey" name="wizard.print.survey"/>
<wizard string="Browse Answer" id="wizard_browse_answer"
model="survey.response" name="wizard.browse.answer"/>
</data>
</openerp>

View File

@ -22,5 +22,6 @@
import wizard_survey
import wizard_print_survey
import wizard_browse_answer
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: