diff --git a/addons/survey/__openerp__.py b/addons/survey/__openerp__.py index 6882690782a..0504cfe35d7 100644 --- a/addons/survey/__openerp__.py +++ b/addons/survey/__openerp__.py @@ -38,7 +38,6 @@ user name and password for the invitation of the survey. 'data': [ 'survey_report.xml', 'survey_data.xml', - 'wizard/survey_selection.xml', 'wizard/survey_answer.xml', 'security/survey_security.xml', 'security/ir.model.access.csv', @@ -48,6 +47,7 @@ user name and password for the invitation of the survey. 'wizard/survey_browse_answer.xml', 'wizard/survey_print.xml', 'wizard/survey_email_compose_message.xml', + #'wizard/survey_selection.xml', ], 'demo': ['survey_demo.xml'], 'test': [ diff --git a/addons/survey/report/survey_analysis_report.py b/addons/survey/report/survey_analysis_report.py index f7f08df3d65..03e03478f00 100644 --- a/addons/survey/report/survey_analysis_report.py +++ b/addons/survey/report/survey_analysis_report.py @@ -239,16 +239,16 @@ class survey_analysis(report_rml): rml += """""" if que.is_comment_require: -# if que.make_comment_field: -# cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,)) -# tot_res = cr.fetchone()[0] -# tot_avg = 0.00 -# if que.tot_resp: -# tot_avg = round(float(tot_res * 100)/ que.tot_resp,2) -# rml+="""""" +to_xml(tools.ustr(que.comment_label)) + """ -# """ + str(tot_avg) + """% -# """ + tools.ustr(tot_res) + """""" -# else: + # if que.make_comment_field: + # cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,)) + # tot_res = cr.fetchone()[0] + # tot_avg = 0.00 + # if que.tot_resp: + # tot_avg = round(float(tot_res * 100)/ que.tot_resp,2) + # rml+="""""" +to_xml(tools.ustr(que.comment_label)) + """ + # """ + str(tot_avg) + """% + # """ + tools.ustr(tot_res) + """""" + # else: cr.execute("select count(id) from survey_response_line where question_id = %s and comment != ''", (que.id,)) tot_res = cr.fetchone()[0] rml += """""" + to_xml(tools.ustr(que.comment_label)) + """ @@ -304,7 +304,7 @@ class survey_analysis(report_rml): cr.execute("select count(sra.answer_id),sqc.rating_weight from survey_response_line sr, survey_response_answer sra ,\ survey_question_column_heading sqc where sr.id = sra.response_id and \ sqc.question_id = sr.question_id and sra.answer_id = %s and sqc.title ='%s'\ -+ group by sra.answer_id,sqc.rating_weight", (ans.id,matrix_ans[mat_col][1])) + group by sra.answer_id,sqc.rating_weight", (ans.id,matrix_ans[mat_col][1])) col_weight = cr.fetchone() if not col_weight: diff --git a/addons/survey/survey.py b/addons/survey/survey.py index 2a065e146d2..8f429deeed3 100644 --- a/addons/survey/survey.py +++ b/addons/survey/survey.py @@ -173,6 +173,23 @@ class survey(osv.osv): } return report + def print_statistics(self, cr, uid, ids, context=None): + """ + Print Survey Statistics in pdf format. + """ + return { + 'type': 'ir.actions.report.xml', + 'report_name': 'survey.analysis', + 'datas': { + 'model': 'survey.print.statistics', + 'ids': [], + 'form': { + 'id': None, + 'survey_ids': ids + }, + }, + } + def _check_valid(self, cr, uid, ids, context=None): sur_browse = self.browse(cr, uid, ids[0], context=context) if not sur_browse.page_ids: @@ -182,14 +199,15 @@ class survey(osv.osv): self._check_valid(cr, uid, ids, context=context) id = ids[0] - context.update({'active': False, 'survey_id': id}) + survey = self.browse(cr, uid, id, context=context) + context.update({'edit': False, 'survey_id': id, 'survey_token': survey.token}) return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'survey.question.wiz', 'type': 'ir.actions.act_window', 'target': 'inline', - 'name': self.browse(cr, uid, id, context=context).title, + 'name': survey.title, 'context': context } @@ -197,7 +215,6 @@ class survey(osv.osv): id = ids[0] context.update({ 'survey_id': id, - 'active': True, 'edit': True, 'ir_actions_act_window_target': 'new', }) @@ -392,18 +409,18 @@ class survey_question(osv.osv): } _defaults = { 'sequence': 1, - 'type': 'multiple_choice_multiple_ans', - 'req_error_msg': 'This question requires an answer.', + 'type': lambda s, cr, uid, c: _('multiple_choice_multiple_ans'), + 'req_error_msg': lambda s, cr, uid, c: _('This question requires an answer.'), 'required_type': 'at least', 'req_ans': 1, 'comment_field_type': 'char', - 'comment_label': 'Other (please specify)', + 'comment_label': lambda s, cr, uid, c: _('Other (please specify)'), 'comment_valid_type': 'do_not_validate', - 'comment_valid_err_msg': 'The comment you entered is in an invalid format.', + 'comment_valid_err_msg': lambda s, cr, uid, c: _('The comment you entered is in an invalid format.'), 'validation_type': 'do_not_validate', - 'validation_valid_err_msg': 'The comment you entered is in an invalid format.', - 'numeric_required_sum_err_msg': 'The choices need to add up to [enter sum here].', - 'make_comment_field_err_msg': 'Please enter a comment.', + 'validation_valid_err_msg': lambda s, cr, uid, c: _('The comment you entered is in an invalid format.'), + 'numeric_required_sum_err_msg': lambda s, cr, uid, c: _('The choices need to add up to [enter sum here].'), + 'make_comment_field_err_msg': lambda s, cr, uid, c: _('Please enter a comment.'), 'in_visible_answer_type': 1 } diff --git a/addons/survey/survey_view.xml b/addons/survey/survey_view.xml index 91de8466317..ccd7257efff 100644 --- a/addons/survey/survey_view.xml +++ b/addons/survey/survey_view.xml @@ -6,7 +6,9 @@ - + + + @@ -227,9 +229,9 @@ - + string="Fill in survey" type="object" icon="gtk-execute" context="{'survey_id': active_id}" attrs="{'invisible':[('state','!=','open')]}"/> + + @@ -294,8 +296,8 @@ Edit Survey Collect responses - Answer Survey - Analyze responses + Fill in survey + Print Statistics diff --git a/addons/survey/wizard/survey_answer.py b/addons/survey/wizard/survey_answer.py index 6b246b0ff37..bc5e3214b47 100644 --- a/addons/survey/wizard/survey_answer.py +++ b/addons/survey/wizard/survey_answer.py @@ -38,7 +38,7 @@ class survey_question_wiz(osv.osv_memory): 'name': fields.integer('Number'), } - def _view_field_multiple_choice_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_choice_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): selection = [] for ans in que_rec.answer_choice_ids: selection.append((tools.ustr(ans.id), ans.answer)) @@ -46,14 +46,14 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_selection"}) fields[tools.ustr(que.id) + "_selection"] = {'type': 'selection', 'selection': selection, 'string': "Answer"} - def _view_field_multiple_choice_multiple_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_choice_multiple_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): # TODO convert selection field into radio input xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'boolean', 'string': ans.answer} - def _view_field_matrix_of_choices_only_multi_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_matrix_of_choices_only_multi_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): que_col_head = self.pool.get('survey.question.column.heading') xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids) + 1), 'colspan': '4'}) @@ -66,7 +66,7 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id), 'nolabel': "1"}) fields[tools.ustr(que.id) + "_" + tools.ustr(row.id) + "_" + tools.ustr(col.id)] = {'type': 'boolean', 'string': col.title} - def _view_field_multiple_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) type = "char" if que_rec.is_validation_require: @@ -80,38 +80,38 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': str(type), 'string': ans.answer} - def _view_field_numerical_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_numerical_textboxes(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_numeric"] = {'type': 'integer', 'string': ans.answer} - def _view_field_date(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_date(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'date', 'string': ans.answer} - def _view_field_date_and_time(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_date_and_time(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'width': "300", 'colspan': '1', 'name': tools.ustr(que.id) + "_" + tools.ustr(ans.id)}) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id)] = {'type': 'datetime', 'string': ans.answer} - def _view_field_descriptive_text(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_descriptive_text(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): if que_rec.descriptive_text: for que_test in que_rec.descriptive_text.split('\n'): etree.SubElement(xml_group, 'label', {'string': to_xml(tools.ustr(que_test)), 'align': "0.0"}) - def _view_field_single_textbox(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_single_textbox(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_single", 'nolabel': "1", 'colspan': "4"}) fields[tools.ustr(que.id) + "_single"] = {'type': 'char', 'size': 255, 'string': "single_textbox", 'views': {}} - def _view_field_comment(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_comment(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_comment", 'nolabel': "1", 'colspan': "4"}) fields[tools.ustr(que.id) + "_comment"] = {'type': 'text', 'string': "Comment/Eassy Box", 'views': {}} - def _view_field_table(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_table(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): xml_group = etree.SubElement(xml_group, 'group', {'col': str(len(que_rec.column_heading_ids)), 'colspan': '4'}) for col in que_rec.column_heading_ids: etree.SubElement(xml_group, 'separator', {'string': tools.ustr(col.title), 'colspan': '1'}) @@ -120,7 +120,7 @@ class survey_question_wiz(osv.osv_memory): etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row), 'nolabel': "1"}) fields[tools.ustr(que.id) + "_table_" + tools.ustr(col.id) + "_" + tools.ustr(row)] = {'type': 'char', 'size': 255, 'views': {}} - def _view_field_multiple_textboxes_diff_type(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_multiple_textboxes_diff_type(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): xml_group = etree.SubElement(xml_group, 'group', {'col': '4', 'colspan': '4'}) for ans in que_rec.answer_choice_ids: if ans.type == "email": @@ -140,7 +140,7 @@ class survey_question_wiz(osv.osv_memory): selection.append((item, item)) fields[tools.ustr(que.id) + "_" + tools.ustr(ans.id) + "_multi"] = {'type': 'selection', 'selection': selection, 'string': ans.answer} - def _view_field_matrix_of_choices_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_matrix_of_choices_only_one_ans(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): if que_rec.comment_column: col = "4" colspan = "4" @@ -159,10 +159,10 @@ class survey_question_wiz(osv.osv_memory): fields[tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"] = {'type': 'char', 'size': 255, 'string': tools.ustr(que_rec.column_name), 'views': {}} etree.SubElement(xml_group, 'field', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_commentcolumn_" + tools.ustr(row.id) + "_field"}) - def _view_field_rating_scale(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_rating_scale(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): self._view_field_matrix_of_choices_only_one_ans(xml_group, fields, readonly, que, que_rec) - def _view_field_postprocessing(self, cr, uid, xml_group, fields, readonly, que, que_rec): + def _view_field_postprocessing(self, cr, uid, xml_group, fields, readonly, que, que_rec, context=None): # after matrix of choices 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', {'readonly': str(readonly), 'name': tools.ustr(que.id) + "_otherfield", 'colspan': "4"}) @@ -210,12 +210,22 @@ class survey_question_wiz(osv.osv_memory): if not survey_id: raise osv.except_osv(_('Warning!'), _("You do not have access to this survey.")) - survey_browse = self.pool.get('survey').browse(cr, uid, survey_id, context=context) + survey_obj = self.pool.get('survey') + survey_browse = survey_obj.browse(cr, uid, survey_id, context=context) user_browse = self.pool.get('res.users').browse(cr, uid, uid, context=context) pid = user_browse.partner_id.id model_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'group_anonymous') anonymous = model_id and model_id[1] in [x.id for x in user_browse.groups_id] + # to do: check if context.get('edit') is allow + if context.get('edit'): + try: + survey_obj.check_access_rights(cr, uid, 'write') + survey_obj.check_access_rule(cr, uid, [survey_id], 'write', context=context) + except except_orm, e: + context['edit'] = False + + # check open and sign in if not context.get('edit') and survey_browse.state != "open": raise osv.except_osv(_('Warning!'), _("You cannot answer because the survey is not open.")) if anonymous and survey_browse.sign_in: @@ -343,7 +353,7 @@ class survey_question_wiz(osv.osv_memory): # have acces to this survey if not check_token['error_message']: - active = context.get('active', False) + active = context.get('edit', False) if sur_name_read.page == "next" or sur_name_rec.page_no == -1: if total_pages > sur_name_rec.page_no + 1: @@ -415,9 +425,9 @@ class survey_question_wiz(osv.osv_memory): xml_group = etree.SubElement(xml_form, 'group', {'col': '1', 'colspan': '4'}) # rendering different views - getattr(self, "_view_field_%s" % que_rec.type)(cr, uid, xml_group, fields, readonly, que, que_rec) + getattr(self, "_view_field_%s" % que_rec.type)(cr, uid, xml_group, fields, readonly, que, que_rec, context=context) 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', 'rating_scale'] and que_rec.is_comment_require: - self._view_field_postprocessing(cr, uid, xml_group, fields, readonly, que, que_rec) + self._view_field_postprocessing(cr, uid, xml_group, fields, readonly, que, que_rec, context=context) xml_footer = etree.SubElement(xml_form, 'footer', {'col': '8', 'colspan': '1', 'width': "100%"}) @@ -547,7 +557,7 @@ class survey_question_wiz(osv.osv_memory): else: if not context.get('sur_name_id'): return value - if context.get('active', False): + if context.get('edit', False): return value surv_name_wiz = self.pool.get('survey.name.wiz') @@ -570,7 +580,7 @@ class survey_question_wiz(osv.osv_memory): return False survey_question_wiz_id = super(survey_question_wiz, self).create(cr, uid, {'name': vals.get('name')}, context=context) - if context.get('active', False): + if context.get('edit', False): return survey_question_wiz_id for key, val in vals.items(): diff --git a/addons/survey/wizard/survey_browse_answer.xml b/addons/survey/wizard/survey_browse_answer.xml index cb50eb955bb..78888909644 100644 --- a/addons/survey/wizard/survey_browse_answer.xml +++ b/addons/survey/wizard/survey_browse_answer.xml @@ -38,5 +38,9 @@ action="action_browse_survey_response" parent="base.next_id_10" groups="base.group_tool_manager" icon="STOCK_PRINT_PREVIEW"/> + + diff --git a/addons/survey/wizard/survey_email_compose_message.xml b/addons/survey/wizard/survey_email_compose_message.xml index ee5b5caee54..2a05d056f25 100644 --- a/addons/survey/wizard/survey_email_compose_message.xml +++ b/addons/survey/wizard/survey_email_compose_message.xml @@ -18,7 +18,7 @@ Thank you for choosing us! - ]]> +]]> diff --git a/addons/survey/wizard/survey_print_answer.xml b/addons/survey/wizard/survey_print_answer.xml index c2363695292..53c66c3bd7f 100644 --- a/addons/survey/wizard/survey_print_answer.xml +++ b/addons/survey/wizard/survey_print_answer.xml @@ -41,5 +41,8 @@ + + diff --git a/addons/survey/wizard/survey_print_statistics.py b/addons/survey/wizard/survey_print_statistics.py index f2e25eb8d53..869359a04d4 100644 --- a/addons/survey/wizard/survey_print_statistics.py +++ b/addons/survey/wizard/survey_print_statistics.py @@ -39,6 +39,7 @@ class survey_print_statistics(osv.osv_memory): res = res and res[0] or {} datas['form'] = res datas['model'] = 'survey.print.statistics' + print datas return { 'type': 'ir.actions.report.xml', 'report_name': 'survey.analysis', diff --git a/addons/survey/wizard/survey_print_statistics.xml b/addons/survey/wizard/survey_print_statistics.xml index 97d976b98f6..65ab466de6c 100644 --- a/addons/survey/wizard/survey_print_statistics.xml +++ b/addons/survey/wizard/survey_print_statistics.xml @@ -33,5 +33,8 @@ + + diff --git a/addons/survey/wizard/survey_selection.xml b/addons/survey/wizard/survey_selection.xml index 41feba775c6..ada093b7a08 100644 --- a/addons/survey/wizard/survey_selection.xml +++ b/addons/survey/wizard/survey_selection.xml @@ -5,7 +5,7 @@ Display Survey List --> - + + + +
Thank you for choosing us!