[IMP]:survey:(REF-YSA)

* improved code

bzr revid: apa@tinyerp.com-20100204131848-z65w18sfs4jj9qnj
This commit is contained in:
apa-tiny 2010-02-04 18:48:48 +05:30
parent 42b2e2deef
commit 3c977386a2
1 changed files with 48 additions and 27 deletions

View File

@ -92,7 +92,10 @@ class survey(osv.osv):
def survey_cancel(self, cr, uid, ids, arg):
self.write(cr, uid, ids, { 'state' : 'cancel' })
return True
def copy(self, cr, uid, id, default=None,context={}):
raise osv.except_osv(_('Error !'),_('You cannot duplicate the resource!'))
survey()
class survey_history(osv.osv):
@ -129,7 +132,7 @@ class survey_page(osv.osv):
def default_get(self, cr, uid, fields, context={}):
data = super(survey_page, self).default_get(cr, uid, fields, context)
if context.has_key('line_order') and context['line_order']:
if len(context['line_order'][-1]) > 2 and context['line_order'][-1][2].has_key('sequence'):
if len(context['line_order'][-1]) > 2 and type(context['line_order'][-1][2]) == type({}) and context['line_order'][-1][2].has_key('sequence'):
data['sequence'] = context['line_order'][-1][2]['sequence'] + 1
if context.has_key('survey_id'):
data['survey_id'] = context['survey_id']
@ -150,6 +153,9 @@ class survey_page(osv.osv):
'context': context
}
def copy(self, cr, uid, id, default=None,context={}):
raise osv.except_osv(_('Error !'),_('You cannot duplicate the resource!'))
survey_page()
class survey_question(osv.osv):
@ -354,14 +360,14 @@ class survey_question(osv.osv):
raise osv.except_osv(_('Error !'),_("You must enter one or more column heading."))
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']:
if vals.has_key('answer_choice_ids') and 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']:
if vals.has_key('answer_choice_ids') or 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']:
if vals.has_key('answer_choice_ids') or 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"))
@ -392,7 +398,8 @@ class survey_question(osv.osv):
def default_get(self, cr, uid, fields, context={}):
data = super(survey_question, self).default_get(cr, uid, fields, context)
if context.has_key('line_order') and context['line_order']:
if len(context['line_order'][-1]) > 2 and context['line_order'][-1][2].has_key('sequence'):
if len(context['line_order'][-1]) > 2 and type(context['line_order'][-1][2]) == type({}) and context['line_order'][-1][2].has_key('sequence'):
data['sequence'] = context['line_order'][-1][2]['sequence'] + 1
if context.has_key('page_id'):
data['page_id']= context['page_id']
@ -479,7 +486,7 @@ class survey_answer(osv.osv):
def default_get(self, cr, uid, fields, context={}):
data = super(survey_answer, self).default_get(cr, uid, fields, context)
if context.has_key('line_order') and context['line_order']:
if len(context['line_order'][-1]) > 2 and context['line_order'][-1][2].has_key('sequence'):
if len(context['line_order'][-1]) > 2 and type(context['line_order'][-1][2]) == type({}) and context['line_order'][-1][2].has_key('sequence'):
data['sequence'] = context['line_order'][-1][2]['sequence'] + 1
return data
@ -499,6 +506,8 @@ class survey_response(osv.osv):
_defaults = {
'state' : lambda * a: "skip",
}
def copy(self, cr, uid, id, default=None,context={}):
raise osv.except_osv(_('Error !'),_('You cannot duplicate the resource!'))
survey_response()
@ -743,7 +752,7 @@ class survey_question_wiz(osv.osv_memory):
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_selection_" + tools.ustr(row['id']),'string':to_xml(tools.ustr(row['answer']))})
selection = [('','')]
for col in que_col_head.read(cr, uid, que_rec['column_heading_ids']):
selection.append((col['id'], col['title']))
selection.append((str(col['id']), col['title']))
fields[tools.ustr(que) + "_selection_" + tools.ustr(row['id'])] = {'type':'selection', 'selection' : selection, 'string': "Answer"}
if que_rec['comment_column']:
fields[tools.ustr(que) + "_commentcolumn_"+tools.ustr(row['id']) + "_field"] = {'type':'char', 'size' : 255, 'string':tools.ustr(que_rec['column_name']), 'views':{}}
@ -773,7 +782,7 @@ class survey_question_wiz(osv.osv_memory):
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_" + tools.ustr(row['id']) + "_" + tools.ustr(col['id']),'nolabel':'1'})
fields[tools.ustr(que) + "_" + tools.ustr(row['id']) + "_" + tools.ustr(col['id'])] = {'type':'selection', 'string': col['title'], 'selection':selection}
elif que_rec['type'] == 'multiple_textboxes':
xml_group = etree.SubElement(xml_group, 'group', {'col': '1', 'colspan': '4'})
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
type = "char"
if que_rec['is_validation_require']:
if que_rec['validation_type'] in ['must_be_whole_number']:
@ -783,25 +792,25 @@ class survey_question_wiz(osv.osv_memory):
elif que_rec['validation_type'] in ['must_be_date']:
type = "date"
for ans in ans_ids:
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"})
etree.SubElement(xml_group, 'field', {'width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"})
if type == "char" :
fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type':'char', 'size':255, 'string':ans['answer']}
else:
fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"] = {'type': str(type), 'string':ans['answer']}
elif que_rec['type'] == 'numerical_textboxes':
xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'})
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in ans_ids:
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_numeric"})
etree.SubElement(xml_group, 'field', {'width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_numeric"})
fields[tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_numeric"] = {'type':'integer', 'string':ans['answer']}
elif que_rec['type'] == 'date':
xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'})
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in ans_ids:
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_" + tools.ustr(ans['id'])})
etree.SubElement(xml_group, 'field', {'width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id'])})
fields[tools.ustr(que) + "_" + tools.ustr(ans['id'])] = {'type':'date', 'string':ans['answer']}
elif que_rec['type'] == 'date_and_time':
xml_group = etree.SubElement(xml_group, 'group', {'col': '2', 'colspan': '2'})
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in ans_ids:
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_" + tools.ustr(ans['id'])})
etree.SubElement(xml_group, 'field', {'width':"300",'colspan': '1','name': tools.ustr(que) + "_" + tools.ustr(ans['id'])})
fields[tools.ustr(que) + "_" + tools.ustr(ans['id'])] = {'type':'datetime', 'string':ans['answer']}
elif que_rec['type'] == 'descriptive_text':
for que_test in que_rec['descriptive_text'].split('\n'):
@ -821,9 +830,9 @@ class survey_question_wiz(osv.osv_memory):
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':{}}
elif que_rec['type'] == 'multiple_textboxes_diff_type':
xml_group = etree.SubElement(xml_group, 'group', {'col': '1', 'colspan': '4'})
xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'})
for ans in ans_ids:
etree.SubElement(xml_group, 'field', {'name': tools.ustr(que) + "_" + tools.ustr(ans['id']) + "_multi"})
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']}
else:
@ -1093,10 +1102,17 @@ class survey_question_wiz(osv.osv_memory):
sur_name_read['store_ans'][resp_id].update({key1:val1})
select_count += 1
elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) > 2 and key1.split('_')[2] == 'numeric':
ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'answer' : val1})
sur_name_read['store_ans'][resp_id].update({key1:val1})
select_count += 1
numeric_sum += int(val1)
if not val1=="0":
try:
numeric_sum += int(val1)
ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'answer' : val1})
sur_name_read['store_ans'][resp_id].update({key1:val1})
select_count += 1
except:
for res in resp_id_list:
sur_name_read['store_ans'].pop(res)
raise osv.except_osv(_('Error !'), _("'" + que_rec['question'] + "' \nPlease enter an integer value " ))
elif val1 and que_id == key1.split('_')[0] and len(key1.split('_')) == 3:
if type(val1) == type('') or type(val1) == type(u''):
ans_create_id = res_ans_obj.create(cr, uid, {'response_id':resp_id, 'answer_id':key1.split('_')[1], 'column_id' : key1.split('_')[2], 'value_choice' : val1})
@ -1264,11 +1280,16 @@ class survey_question_wiz(osv.osv_memory):
sur_name_read['store_ans'][update].update({key:val})
select_count += 1
elif val and len(key.split('_')) > 2 and key.split('_')[2] == 'numeric':
resp_obj.write(cr, uid, update, {'state': 'done'})
ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id':ans_id_len[1], 'answer' : val})
sur_name_read['store_ans'][update].update({key:val})
select_count += 1
numeric_sum += int(val)
if not val=="0":
try:
numeric_sum += int(val)
resp_obj.write(cr, uid, update, {'state': 'done'})
ans_create_id = res_ans_obj.create(cr, uid, {'response_id':update, 'answer_id':ans_id_len[1], 'answer' : val})
sur_name_read['store_ans'][update].update({key:val})
select_count += 1
except:
raise osv.except_osv(_('Error !'), _("'" + que_rec['question'] + "' \n Please enter an integer value " ))
elif val and len(key.split('_')) == 3:
resp_obj.write(cr, uid, update, {'state': 'done'})
if type(val) == type('') or type(val) == type(u''):