From 607cbf63cf91f94d8796af4d05f63c26ca10ccb0 Mon Sep 17 00:00:00 2001 From: "Mayur Maheshwari (OpenERP)" Date: Thu, 11 Oct 2012 15:06:46 +0530 Subject: [PATCH] [IMP]survey : Improve warning message, set align of Professional Development Objectives separator and fix the trace back of create New Survey -> edit survey or -> test survey bzr revid: mma@tinyerp.com-20121011093646-b8lg30yc7d4xzvdo --- addons/survey/survey.py | 38 ++++++++++++++++++++++----- addons/survey/survey_view.xml | 4 +-- addons/survey/wizard/survey_answer.py | 1 + 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/addons/survey/survey.py b/addons/survey/survey.py index d01140092d4..57ff9c84559 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -163,10 +163,14 @@ class survey(osv.osv): 'context': context } def test_survey(self, cr, uid, ids, context=None): - sur_obj = self.read(cr, uid, ids,['title'], context=context) + sur_obj = self.read(cr, uid, ids,['title','page_ids'], context=context) for sur in sur_obj: name = sur['title'] - context.update({'active':True,'survey_id': ids[0]}) + pages = sur['page_ids'] + if not pages: + raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) + else: + context.update({'active':False,'survey_id': ids[0]}) return { 'view_type': 'form', 'view_mode': 'form', @@ -176,6 +180,26 @@ class survey(osv.osv): 'name': name, 'context': context } + + def edit_survey(self, cr, uid, ids, context=None): + sur_obj = self.read(cr, uid, ids,['title','page_ids'], context=context) + for sur in sur_obj: + name = sur['title'] + pages = sur['page_ids'] + if not pages: + raise osv.except_osv(_('Warning!'), _('This survey has no question defined. Please define the questions and answers first.')) + else: + context.update({'survey_id': ids[0]}) + return { + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'survey.question.wiz', + 'type': 'ir.actions.act_window', + 'target': 'new', + 'name': name, + 'context': context + } + survey() class survey_history(osv.osv): @@ -383,7 +407,7 @@ class survey_question(osv.osv): 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']) + 'req_ans', 'minimum_req_ans', 'maximum_req_ans', 'column_heading_ids', 'page_id', 'question']) for question in questions: col_len = len(question['column_heading_ids']) if vals.has_key('column_heading_ids'): @@ -401,7 +425,7 @@ class survey_question(osv.osv): if que_type in ['matrix_of_choices_only_one_ans', 'matrix_of_choices_only_multi_ans',\ 'matrix_of_drop_down_menus', 'rating_scale']: if not col_len: - raise osv.except_osv(_('Warning!'),_("You must enter one or more column headings.")) + raise osv.except_osv(_('Warning!'),_("You must enter one or more column headings for question %s of page %s.") % (question['question'], question['page_id'][1])) ans_len = len(question['answer_choice_ids']) if vals.has_key('answer_choice_ids'): @@ -413,7 +437,7 @@ class survey_question(osv.osv): if que_type not in ['descriptive_text', 'single_textbox', 'comment','table']: if not ans_len: - raise osv.except_osv(_('Warning!'),_("You must enter one or more Answers.")) + raise osv.except_osv(_('Warning!'),_("You must enter one or more Answers for question %s of page %s.") % (question['question'], question['page_id'][1])) req_type = "" if vals.has_key('required_type'): @@ -484,11 +508,11 @@ class survey_question(osv.osv): maximum_ans = 0 if vals.has_key('answer_choice_ids') and not len(vals['answer_choice_ids']): if vals.has_key('type') and vals['type'] not in ['descriptive_text', 'single_textbox', 'comment','table']: - raise osv.except_osv(_('Warning!'),_("You must enter one or more answers.")) + raise osv.except_osv(_('Warning!'),_("You must enter one or more answers for question %s.") % (vals['question'])) 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(_('Warning!'),_("You must enter one or more column heading.")) + raise osv.except_osv(_('Warning!'),_("You must enter one or more column heading for question %s.")% (vals['question'])) 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']: diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 0247a205700..ce0e4bfdd91 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -31,8 +31,8 @@