[REF] survey: rename survey.question type field to question_type
Purpose of this commit is to rename type column to something matching the the real business use of the field. That way it is easier to find and grep in the code. It also lessens potential conflicts with type build-in python function. It also lessens conflicts when using the field in JS as type is a build-in attribute. Renaming type column is a long-living issue. We choose to do it at the beginning of the v13 development to catch errors as soon as possible. This commit is linked to task ID 1896245. It is also a subpart of community PR #27599.
This commit is contained in:
committed by
Thibault Delavallée
parent
77e5e8b7ff
commit
b70ccc45bd
@@ -20,13 +20,13 @@
|
||||
<field name="page_id" ref="recruitment_1" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">From which university will you graduate?</field>
|
||||
<field name="type">textbox</field>
|
||||
<field name="question_type">textbox</field>
|
||||
</record>
|
||||
<record id="recruitment_1_2" model="survey.question">
|
||||
<field name="page_id" ref="recruitment_1" />
|
||||
<field name="sequence">2</field>
|
||||
<field name="question">What is your gender?</field>
|
||||
<field name="type">simple_choice</field>
|
||||
<field name="question_type">simple_choice</field>
|
||||
<field name="display_mode">dropdown</field>
|
||||
</record>
|
||||
<record id="recruitment_1_2_1" model="survey.label">
|
||||
@@ -43,7 +43,7 @@
|
||||
<field name="page_id" ref="recruitment_1" />
|
||||
<field name="sequence">3</field>
|
||||
<field name="question">What age group do you belong to?</field>
|
||||
<field name="type">simple_choice</field>
|
||||
<field name="question_type">simple_choice</field>
|
||||
<field name="display_mode">columns</field>
|
||||
<field name="column_nb">4</field>
|
||||
</record>
|
||||
@@ -99,25 +99,25 @@
|
||||
<field name="page_id" ref="recruitment_2" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">Knowledge</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<record id="recruitment_2_2" model="survey.question">
|
||||
<field name="page_id" ref="recruitment_2" />
|
||||
<field name="sequence">2</field>
|
||||
<field name="question">Education</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<record id="recruitment_2_3" model="survey.question">
|
||||
<field name="page_id" ref="recruitment_2" />
|
||||
<field name="sequence">3</field>
|
||||
<field name="question">Experience</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<record id="recruitment_2_4" model="survey.question">
|
||||
<field name="page_id" ref="recruitment_2" />
|
||||
<field name="sequence">4</field>
|
||||
<field name="question">Activities</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<!-- Page 3 -->
|
||||
<record id="recruitment_3" model="survey.page">
|
||||
@@ -130,7 +130,7 @@
|
||||
<field name="page_id" ref="recruitment_3" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">Rate the Importance</field>
|
||||
<field name="type">matrix</field>
|
||||
<field name="question_type">matrix</field>
|
||||
<field name="matrix_subtype">simple</field>
|
||||
</record>
|
||||
<record id="rcol_3_1_1" model="survey.label">
|
||||
|
||||
@@ -166,9 +166,9 @@ class Survey(http.Controller):
|
||||
answer_value = None
|
||||
if answer.answer_type == 'free_text':
|
||||
answer_value = answer.value_free_text
|
||||
elif answer.answer_type == 'text' and answer.question_id.type == 'textbox':
|
||||
elif answer.answer_type == 'text' and answer.question_id.question_type == 'textbox':
|
||||
answer_value = answer.value_text
|
||||
elif answer.answer_type == 'text' and answer.question_id.type != 'textbox':
|
||||
elif answer.answer_type == 'text' and answer.question_id.question_type != 'textbox':
|
||||
# here come comment answers for matrices, simple choice and multiple choice
|
||||
answer_tag = "%s_%s" % (answer_tag, 'comment')
|
||||
answer_value = answer.value_text
|
||||
@@ -363,13 +363,13 @@ class Survey(http.Controller):
|
||||
current_filters = current_filters if current_filters else []
|
||||
Survey = request.env['survey.survey']
|
||||
result = []
|
||||
if question.type == 'multiple_choice':
|
||||
if question.question_type == 'multiple_choice':
|
||||
result.append({'key': ustr(question.question),
|
||||
'values': Survey.prepare_result(question, current_filters)['answers']
|
||||
})
|
||||
if question.type == 'simple_choice':
|
||||
if question.question_type == 'simple_choice':
|
||||
result = Survey.prepare_result(question, current_filters)['answers']
|
||||
if question.type == 'matrix':
|
||||
if question.question_type == 'matrix':
|
||||
data = Survey.prepare_result(question, current_filters)
|
||||
for answer in data['answers']:
|
||||
values = []
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<field name="page_id" ref="feedback_1" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">Are you using Odoo on a daily basis?</field>
|
||||
<field name="type">simple_choice</field>
|
||||
<field name="question_type">simple_choice</field>
|
||||
<field name="display_mode">dropdown</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -49,7 +49,7 @@
|
||||
<field name="page_id" ref="feedback_1" />
|
||||
<field name="sequence">2</field>
|
||||
<field name="question">Which modules are you using/testing?</field>
|
||||
<field name="type">multiple_choice</field>
|
||||
<field name="question_type">multiple_choice</field>
|
||||
<field name="column_nb">4</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -95,7 +95,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">What do you think about the documentation available on doc.odoo.com?</field>
|
||||
<field name="type">matrix</field>
|
||||
<field name="question_type">matrix</field>
|
||||
<field name="matrix_subtype">simple</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -148,7 +148,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">2</field>
|
||||
<field name="question">What do you think about the process views of Odoo, available in the web client ?</field>
|
||||
<field name="type">matrix</field>
|
||||
<field name="question_type">matrix</field>
|
||||
<field name="matrix_subtype">simple</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -201,13 +201,13 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">3</field>
|
||||
<field name="question">Do you have suggestions on how to improve the process view ?</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<record model="survey.question" id="feedback_2_4">
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">4</field>
|
||||
<field name="question">What do you think about the structure of the menus?</field>
|
||||
<field name="type">multiple_choice</field>
|
||||
<field name="question_type">multiple_choice</field>
|
||||
<field name="column_nb">4</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -230,7 +230,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">5</field>
|
||||
<field name="question">What do you think about the groups of users?</field>
|
||||
<field name="type">matrix</field>
|
||||
<field name="question_type">matrix</field>
|
||||
<field name="matrix_subtype">simple</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -283,7 +283,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">6</field>
|
||||
<field name="question">What do you think about the structure of the menus?</field>
|
||||
<field name="type">simple_choice</field>
|
||||
<field name="question_type">simple_choice</field>
|
||||
<field name="display_mode">columns</field>
|
||||
<field name="column_nb">4</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
@@ -307,7 +307,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_2" />
|
||||
<field name="sequence">7</field>
|
||||
<field name="question">What do you think about configuration wizards?</field>
|
||||
<field name="type">matrix</field>
|
||||
<field name="question_type">matrix</field>
|
||||
<field name="matrix_subtype">simple</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -362,7 +362,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_3" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">How do you contribute or plan to contribute to Odoo?</field>
|
||||
<field name="type">multiple_choice</field>
|
||||
<field name="question_type">multiple_choice</field>
|
||||
<field name="column_nb">6</field>
|
||||
<field name="constr_mandatory" eval="True" />
|
||||
</record>
|
||||
@@ -395,13 +395,13 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_3" />
|
||||
<field name="sequence">2</field>
|
||||
<field name="question">Do you have a proposition to help people to contribute?</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<record model="survey.question" id="feedback_3_3">
|
||||
<field name="page_id" ref="feedback_3" />
|
||||
<field name="sequence">3</field>
|
||||
<field name="question">Do you have a proposition to attract new contributors?</field>
|
||||
<field name="type">free_text</field>
|
||||
<field name="question_type">free_text</field>
|
||||
</record>
|
||||
<!-- Page 4 -->
|
||||
<record model="survey.page" id="feedback_4">
|
||||
@@ -414,7 +414,7 @@ what have been your difficulties.</p></field>
|
||||
<field name="page_id" ref="feedback_4" />
|
||||
<field name="sequence">1</field>
|
||||
<field name="question">Where do you develop your new features?</field>
|
||||
<field name="type">multiple_choice</field>
|
||||
<field name="question_type">multiple_choice</field>
|
||||
<field name="column_nb">6</field>
|
||||
</record>
|
||||
<record model="survey.label" id="choice_4_1_1">
|
||||
|
||||
@@ -226,7 +226,7 @@ class Survey(models.Model):
|
||||
result_summary = {}
|
||||
|
||||
# Calculate and return statistics for choice
|
||||
if question.type in ['simple_choice', 'multiple_choice']:
|
||||
if question.question_type in ['simple_choice', 'multiple_choice']:
|
||||
comments = []
|
||||
answers = OrderedDict((label.id, {'text': label.value, 'count': 0, 'answer_id': label.id}) for label in question.labels_ids)
|
||||
for input_line in question.user_input_line_ids:
|
||||
@@ -237,7 +237,7 @@ class Survey(models.Model):
|
||||
result_summary = {'answers': list(answers.values()), 'comments': comments}
|
||||
|
||||
# Calculate and return statistics for matrix
|
||||
if question.type == 'matrix':
|
||||
if question.question_type == 'matrix':
|
||||
rows = OrderedDict()
|
||||
answers = OrderedDict()
|
||||
res = dict()
|
||||
@@ -254,14 +254,14 @@ class Survey(models.Model):
|
||||
result_summary = {'answers': answers, 'rows': rows, 'result': res, 'comments': comments}
|
||||
|
||||
# Calculate and return statistics for free_text, textbox, date
|
||||
if question.type in ['free_text', 'textbox', 'date']:
|
||||
if question.question_type in ['free_text', 'textbox', 'date']:
|
||||
result_summary = []
|
||||
for input_line in question.user_input_line_ids:
|
||||
if not(current_filters) or input_line.user_input_id.id in current_filters:
|
||||
result_summary.append(input_line)
|
||||
|
||||
# Calculate and return statistics for numerical_box
|
||||
if question.type == 'numerical_box':
|
||||
if question.question_type == 'numerical_box':
|
||||
result_summary = {'input_lines': []}
|
||||
all_inputs = []
|
||||
for input_line in question.user_input_line_ids:
|
||||
@@ -434,14 +434,14 @@ class SurveyQuestion(models.Model):
|
||||
oldname='descriptive_text')
|
||||
|
||||
# Answer
|
||||
type = fields.Selection([
|
||||
question_type = fields.Selection([
|
||||
('free_text', 'Multiple Lines Text Box'),
|
||||
('textbox', 'Single Line Text Box'),
|
||||
('numerical_box', 'Numerical Value'),
|
||||
('date', 'Date'),
|
||||
('simple_choice', 'Multiple choice: only one answer'),
|
||||
('multiple_choice', 'Multiple choice: multiple answers allowed'),
|
||||
('matrix', 'Matrix')], string='Type of Question', default='free_text', required=True)
|
||||
('matrix', 'Matrix')], string='Type of Question', default='free_text', required=True, oldname='type')
|
||||
matrix_subtype = fields.Selection([('simple', 'One choice per row'),
|
||||
('multiple', 'Multiple choices per row')], string='Matrix Type', default='simple')
|
||||
labels_ids = fields.One2many('survey.label', 'question_id', string='Types of answers', oldname='answer_choice_ids', copy=True)
|
||||
@@ -509,9 +509,9 @@ class SurveyQuestion(models.Model):
|
||||
""" Validate question, depending on question type and parameters """
|
||||
self.ensure_one()
|
||||
try:
|
||||
checker = getattr(self, 'validate_' + self.type)
|
||||
checker = getattr(self, 'validate_' + self.question_type)
|
||||
except AttributeError:
|
||||
_logger.warning(self.type + ": This type of question has no validation method")
|
||||
_logger.warning(self.question_type + ": This type of question has no validation method")
|
||||
return {}
|
||||
else:
|
||||
return checker(post, answer_tag)
|
||||
@@ -846,9 +846,9 @@ class SurveyUserInputLine(models.Model):
|
||||
overwritten (in order to maintain data consistency).
|
||||
"""
|
||||
try:
|
||||
saver = getattr(self, 'save_line_' + question.type)
|
||||
saver = getattr(self, 'save_line_' + question.question_type)
|
||||
except AttributeError:
|
||||
_logger.error(question.type + ": This type of question has no saving function")
|
||||
_logger.error(question.question_type + ": This type of question has no saving function")
|
||||
return False
|
||||
else:
|
||||
saver(user_input_id, question, post, answer_tag)
|
||||
|
||||
@@ -43,8 +43,8 @@ class TestSurvey(TransactionCase):
|
||||
self.assertEqual(question.question, "Q0", msg="Title of the Question is somehow modified.")
|
||||
|
||||
def test_01_question_type_validation_save_line_function(self):
|
||||
for (question_type, text) in self.env['survey.question']._fields['type'].selection:
|
||||
# Each question ype must have validation function.
|
||||
for (question_type, text) in self.env['survey.question']._fields['question_type'].selection:
|
||||
# Each question type must have validation function.
|
||||
self.assertTrue(hasattr(self.env['survey.question'], 'validate_' + question_type), msg="Question must have a validation method in\
|
||||
the form of 'validate_' followed by the name of the type.")
|
||||
|
||||
@@ -53,24 +53,24 @@ class TestSurvey(TransactionCase):
|
||||
the form of 'save_line_' followed by the name of the type.")
|
||||
|
||||
def test_02_question_answer_required(self):
|
||||
for (question_type, text) in self.env['survey.question']._fields['type'].selection:
|
||||
for (question_type, text) in self.env['survey.question']._fields['question_type'].selection:
|
||||
# Blank value of field is not accepted for mandatory questions.
|
||||
if question_type == 'multiple_choice':
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'multiple_choice',
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'multiple_choice',
|
||||
'constr_mandatory': True, 'constr_error_msg': 'Error',
|
||||
'labels_ids': [(0, 0, {'value': "MChoice0", "quizz_mark": 0}), (0, 0, {'value': "MChoice1", "quizz_mark": 0})]})
|
||||
|
||||
elif question_type == 'matrix':
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'matrix', 'matrix_subtype': 'simple',
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'matrix', 'matrix_subtype': 'simple',
|
||||
'constr_mandatory': True, 'constr_error_msg': 'Error',
|
||||
'labels_ids': [(0, 0, {'value': "Column0", "quizz_mark": 0}), (0, 0, {'value': "Column1", "quizz_mark": 0})],
|
||||
'labels_ids_2': [(0, 0, {'value': "Row0", "quizz_mark": 0}), (0, 0, {'value': "Row1", "quizz_mark": 0})]})
|
||||
|
||||
else:
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': question_type, 'constr_mandatory': True, 'constr_error_msg': 'Error'})
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': question_type, 'constr_mandatory': True, 'constr_error_msg': 'Error'})
|
||||
answer_tag = '%s_%s_%s' % (self.survey1.id, self.page1.id, question.id)
|
||||
self.assertDictEqual({answer_tag: "Error"}, question.validate_question({answer_tag: ''}, answer_tag),
|
||||
msg=("Validation function for type %s is unable to generate error if it is mandatory and answer is blank." % question_type))
|
||||
@@ -78,9 +78,9 @@ class TestSurvey(TransactionCase):
|
||||
def test_03_question_textbox(self):
|
||||
questions = [
|
||||
self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'textbox', 'validation_email': True}),
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'textbox', 'validation_email': True}),
|
||||
self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q1', 'type': 'textbox', 'validation_required': True,
|
||||
'page_id': self.page1.id, 'question': 'Q1', 'question_type': 'textbox', 'validation_required': True,
|
||||
'validation_length_min': 2, 'validation_length_max': 8, 'validation_error_msg': "Error"})]
|
||||
|
||||
results = [('test @ testcom', _('This answer must be an email address')), ('t', 'Error')]
|
||||
@@ -91,7 +91,7 @@ class TestSurvey(TransactionCase):
|
||||
|
||||
def test_04_question_numerical_box(self):
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'numerical_box', 'validation_required': True,
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'numerical_box', 'validation_required': True,
|
||||
'validation_min_float_value': 2.1, 'validation_max_float_value': 3.0, 'validation_error_msg': "Error"})
|
||||
answer_tag = '%s_%s_%s' % (self.survey1.id, self.page1.id, question.id)
|
||||
results = [('aaa', _('This is not a number')), ('4.5', 'Error'), ('0.1', 'Error')]
|
||||
@@ -101,7 +101,7 @@ class TestSurvey(TransactionCase):
|
||||
|
||||
def test_05_question_date(self):
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'date', 'validation_required': True,
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'date', 'validation_required': True,
|
||||
'validation_min_date': '2015-03-20', 'validation_max_date': '2015-03-25', 'validation_error_msg': "Error"})
|
||||
answer_tag = '%s_%s_%s' % (self.survey1.id, self.page1.id, question.id)
|
||||
results = [('2015-55-10', _('This is not a date')), ('2015-03-19', 'Error'), ('2015-03-26', 'Error')]
|
||||
@@ -113,7 +113,7 @@ class TestSurvey(TransactionCase):
|
||||
# Case-1: Executing action with correct data.
|
||||
correct_survey = self.env['survey.survey'].sudo(self.survey_manager).create({
|
||||
'title': "S0", 'stage_id': self.env['survey.stage'].search([('sequence', '=', 1)]).id,
|
||||
'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'type': 'free_text'})]})]})
|
||||
'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'question_type': 'free_text'})]})]})
|
||||
action = correct_survey.action_send_survey()
|
||||
template = self.env.ref('survey.email_template_survey', raise_if_not_found=False)
|
||||
|
||||
@@ -143,7 +143,7 @@ class TestSurvey(TransactionCase):
|
||||
'title': "Test survey"}),
|
||||
self.env['survey.survey'].sudo(self.survey_manager).create({ # Closed Survey.
|
||||
'title': "S0", 'stage_id': self.env['survey.stage'].search([('closed', '=', True)]).id, # Getting Closed stage id.
|
||||
'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'type': 'free_text'})]})]})]
|
||||
'page_ids': [(0, 0, {'title': "P0", 'question_ids': [(0, 0, {'question': "Q0", 'question_type': 'free_text'})]})]})]
|
||||
for survey in surveys:
|
||||
self.assertRaises(UserError, survey.action_send_survey)
|
||||
|
||||
@@ -215,7 +215,7 @@ class TestSurvey(TransactionCase):
|
||||
|
||||
def test_10_survey_result_simple_multiple_choice(self):
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'simple_choice',
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'simple_choice',
|
||||
'labels_ids': [(0, 0, {'value': "Choice0", 'quizz_mark': 0}), (0, 0, {'value': "Choice1", 'quizz_mark': 0})]})
|
||||
for i in range(3):
|
||||
self.env['survey.user_input'].sudo(self.user_public).create({'survey_id': self.survey1.id, 'user_input_line_ids': [(0, 0, {
|
||||
@@ -229,7 +229,7 @@ class TestSurvey(TransactionCase):
|
||||
|
||||
def test_11_survey_result_matrix(self):
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'type': 'matrix', 'matrix_subtype': 'simple',
|
||||
'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'matrix', 'matrix_subtype': 'simple',
|
||||
'labels_ids': [(0, 0, {'value': "Column0", "quizz_mark": 0}), (0, 0, {'value': "Column1", "quizz_mark": 0})],
|
||||
'labels_ids_2': [(0, 0, {'value': "Row0", "quizz_mark": 0}), (0, 0, {'value': "Row1", "quizz_mark": 0})]})
|
||||
for i in range(3):
|
||||
@@ -243,7 +243,7 @@ class TestSurvey(TransactionCase):
|
||||
self.assertEqual(self.env['survey.survey'].prepare_result(question)['result'], res, msg="Statistics of matrix type questions are different from expectations")
|
||||
|
||||
def test_12_survey_result_numeric_box(self):
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'type': 'numerical_box'})
|
||||
question = self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'numerical_box'})
|
||||
num = [float(n) for n in random.sample(range(1, 100), 3)]
|
||||
nsum = sum(num)
|
||||
for i in range(3):
|
||||
@@ -257,7 +257,7 @@ class TestSurvey(TransactionCase):
|
||||
self.assertEqual(result[key], exresult[key], msg="Statistics of numeric box type questions are different from expectations")
|
||||
|
||||
def test_13_survey_actions(self):
|
||||
self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'type': 'numerical_box'})
|
||||
self.env['survey.question'].sudo(self.survey_manager).create({'page_id': self.page1.id, 'question': 'Q0', 'question_type': 'numerical_box'})
|
||||
|
||||
actions = {
|
||||
'start': {'method': 'public', 'token': '/test', 'text': 'Start'},
|
||||
|
||||
@@ -37,11 +37,11 @@
|
||||
<h4>
|
||||
<b>Question </b>
|
||||
<span t-field='question.question'></span>
|
||||
<t t-if="question.type == 'matrix'">
|
||||
<t t-if="question.question_type == 'matrix'">
|
||||
<small><span class="badge badge-secondary">Matrix: <span t-field='question.matrix_subtype'/></span></small>
|
||||
</t>
|
||||
<t t-if="question.type in ['simple_choice', 'multiple_choice']">
|
||||
<small><span t-field='question.type' class="badge badge-secondary"></span></small>
|
||||
<t t-if="question.question_type in ['simple_choice', 'multiple_choice']">
|
||||
<small><span t-field='question.question_type' class="badge badge-secondary"></span></small>
|
||||
</t>
|
||||
<span class="float-right">
|
||||
<span class="badge badge-success"><span t-esc="input_summary['answered']"></span> Answered</span>
|
||||
@@ -52,16 +52,16 @@
|
||||
<t t-if="question.description">
|
||||
<div class="text-muted oe_no_empty" t-field="question.description" />
|
||||
</t>
|
||||
<t t-if="question.type in ['textbox', 'free_text', 'date']">
|
||||
<t t-if="question.question_type in ['textbox', 'free_text', 'date']">
|
||||
<t t-call="survey.result_text"></t>
|
||||
</t>
|
||||
<t t-if="question.type in ['simple_choice', 'multiple_choice']">
|
||||
<t t-if="question.question_type in ['simple_choice', 'multiple_choice']">
|
||||
<t t-call="survey.result_choice"></t>
|
||||
</t>
|
||||
<t t-if="question.type == 'matrix'">
|
||||
<t t-if="question.question_type == 'matrix'">
|
||||
<t t-call="survey.result_matrix"></t>
|
||||
</t>
|
||||
<t t-if="question.type == 'numerical_box'">
|
||||
<t t-if="question.question_type == 'numerical_box'">
|
||||
<t t-call="survey.result_number"></t>
|
||||
</t>
|
||||
</t>
|
||||
@@ -88,17 +88,17 @@
|
||||
<t t-set="text_result" t-value="prepare_result"/>
|
||||
<tr t-foreach="text_result" t-as="user_input">
|
||||
<td><a t-att-href="'%s/%s' % (user_input.user_input_id.print_url, user_input.user_input_id.token)"><t t-esc="user_input_index + 1"></t></a></td>
|
||||
<t t-if="question.type == 'free_text'">
|
||||
<t t-if="question.question_type == 'free_text'">
|
||||
<td>
|
||||
<a t-att-href="'%s/%s' % (user_input.user_input_id.print_url, user_input.user_input_id.token)" t-field="user_input.value_free_text"></a><br/>
|
||||
</td>
|
||||
</t>
|
||||
<t t-if="question.type == 'textbox'">
|
||||
<t t-if="question.question_type == 'textbox'">
|
||||
<td>
|
||||
<a t-att-href="'%s/%s' % (user_input.user_input_id.print_url, user_input.user_input_id.token)" t-field="user_input.value_text"></a><br/>
|
||||
</td>
|
||||
</t>
|
||||
<t t-if="question.type == 'date'">
|
||||
<t t-if="question.question_type == 'date'">
|
||||
<td>
|
||||
<a t-att-href="'%s/%s' % (user_input.user_input_id.print_url, user_input.user_input_id.token)" t-field="user_input.value_date"></a><br/>
|
||||
</td>
|
||||
@@ -136,12 +136,12 @@
|
||||
<div>
|
||||
<!-- Tabs -->
|
||||
<ul class="nav nav-tabs d-print-none" role="tablist">
|
||||
<li class="nav-item" t-if="question.type != 'simple_choice'">
|
||||
<li class="nav-item" t-if="question.question_type != 'simple_choice'">
|
||||
<a t-att-href="'#graph_question_%d' % question.id" t-att-aria-controls="'graph_question_%d' % question.id" class="nav-link active" data-toggle="tab" role="tab">
|
||||
<i class="fa fa-bar-chart-o"></i> Graph
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item" t-if="question.type == 'simple_choice'">
|
||||
<li class="nav-item" t-if="question.question_type == 'simple_choice'">
|
||||
<a t-att-href="'#graph_question_%d' % question.id" t-att-aria-controls="'graph_question_%d' % question.id" class="nav-link active" data-toggle="tab" role="tab">
|
||||
<i class="fa fa-bar-chart-o"></i> Pie Chart
|
||||
</a>
|
||||
@@ -153,11 +153,11 @@
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active survey_graph" t-if="question.type != 'simple_choice'" t-att-id="'graph_question_%d' % question.id" t-att-data-question_id="question.id" data-graph_type="bar" t-att-graph-data="graph_data">
|
||||
<div role="tabpanel" class="tab-pane active survey_graph" t-if="question.question_type != 'simple_choice'" t-att-id="'graph_question_%d' % question.id" t-att-data-question_id="question.id" data-graph_type="bar" t-att-graph-data="graph_data">
|
||||
<!-- svg element for drawing bar chart -->
|
||||
<svg style="height:20em"></svg>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane active survey_graph" t-if="question.type == 'simple_choice'" t-att-id="'graph_question_%d' % question.id" t-att-data-question_id="question.id" data-graph_type="pie" t-att-graph-data="graph_data">
|
||||
<div role="tabpanel" class="tab-pane active survey_graph" t-if="question.question_type == 'simple_choice'" t-att-id="'graph_question_%d' % question.id" t-att-data-question_id="question.id" data-graph_type="pie" t-att-graph-data="graph_data">
|
||||
<!-- svg element for drawing pie chart -->
|
||||
<svg style="height:20em"></svg>
|
||||
</div>
|
||||
|
||||
@@ -190,13 +190,13 @@
|
||||
<span t-if="question.constr_mandatory" class="text-danger">*</span>
|
||||
</h2>
|
||||
<div t-field='question.description' class="text-muted oe_no_empty"/>
|
||||
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
|
||||
<t t-if="question.type == 'textbox'"><t t-call="survey.textbox"/></t>
|
||||
<t t-if="question.type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
|
||||
<t t-if="question.type == 'date'"><t t-call="survey.date"/></t>
|
||||
<t t-if="question.type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
|
||||
<t t-if="question.type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
|
||||
<t t-if="question.type == 'matrix'"><t t-call="survey.matrix"/></t>
|
||||
<t t-if="question.question_type == 'free_text'"><t t-call="survey.free_text"/></t>
|
||||
<t t-if="question.question_type == 'textbox'"><t t-call="survey.textbox"/></t>
|
||||
<t t-if="question.question_type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
|
||||
<t t-if="question.question_type == 'date'"><t t-call="survey.date"/></t>
|
||||
<t t-if="question.question_type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
|
||||
<t t-if="question.question_type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
|
||||
<t t-if="question.question_type == 'matrix'"><t t-call="survey.matrix"/></t>
|
||||
<div class="js_errzone alert alert-danger" style="display:none;" role="alert"></div>
|
||||
</div>
|
||||
</t>
|
||||
@@ -356,13 +356,13 @@
|
||||
<span t-if="quizz_correction" class="badge badge-pill" t-att-data-score-question="question.id"></span>
|
||||
</h2>
|
||||
<t t-if="question.description"><div class="text-muted oe_no_empty" t-field='question.description'/></t>
|
||||
<t t-if="question.type == 'free_text'"><t t-call="survey.free_text"/></t>
|
||||
<t t-if="question.type == 'textbox'"><t t-call="survey.textbox"/></t>
|
||||
<t t-if="question.type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
|
||||
<t t-if="question.type == 'date'"><t t-call="survey.date"/></t>
|
||||
<t t-if="question.type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
|
||||
<t t-if="question.type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
|
||||
<t t-if="question.type == 'matrix'"><t t-call="survey.matrix"/></t>
|
||||
<t t-if="question.question_type == 'free_text'"><t t-call="survey.free_text"/></t>
|
||||
<t t-if="question.question_type == 'textbox'"><t t-call="survey.textbox"/></t>
|
||||
<t t-if="question.question_type == 'numerical_box'"><t t-call="survey.numerical_box"/></t>
|
||||
<t t-if="question.question_type == 'date'"><t t-call="survey.date"/></t>
|
||||
<t t-if="question.question_type == 'simple_choice'"><t t-call="survey.simple_choice"/></t>
|
||||
<t t-if="question.question_type == 'multiple_choice'"><t t-call="survey.multiple_choice"/></t>
|
||||
<t t-if="question.question_type == 'matrix'"><t t-call="survey.matrix"/></t>
|
||||
<div class="js_errzone alert alert-danger" style="display:none;" role="alert"></div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
@@ -337,7 +337,7 @@
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="question"/>
|
||||
<field name="type"/>
|
||||
<field name="question_type"/>
|
||||
<field name="constr_mandatory"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -406,42 +406,42 @@
|
||||
</div>
|
||||
<group>
|
||||
<group>
|
||||
<field name="type" widget="radio" />
|
||||
<field name="question_type" widget="radio" />
|
||||
</group>
|
||||
<group>
|
||||
<div class="col-lg-6 offset-lg-3 o_preview_questions">
|
||||
<!-- Multiple Lines Text Zone -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'free_text')]}">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'free_text')]}">
|
||||
<i class="fa fa-align-justify fa-4x" role="img" aria-label="Multiple lines" title="Multiple Lines"/>
|
||||
</div>
|
||||
<!-- Single Line Text Zone -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'textbox')]}">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'textbox')]}">
|
||||
<i class="fa fa-minus fa-4x" role="img" aria-label="Single Line" title="Single Line"/>
|
||||
</div>
|
||||
<!-- Numerical Value -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'numerical_box')]}">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'numerical_box')]}">
|
||||
<i class="fa fa-2x" role="img" aria-label="Numeric" title="Numeric">123..</i>
|
||||
</div>
|
||||
<!-- Date and Time -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'date')]}">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'date')]}">
|
||||
<p class="o_datetime">YYYY-MM-DD
|
||||
<i class="fa fa-calendar fa-2x" role="img" aria-label="Calendar" title="Calendar"/>
|
||||
</p>
|
||||
</div>
|
||||
<!-- Multiple choice: only one answer -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'simple_choice')]}" role="img" aria-label="Multiple choice with one answer" title="Multiple choice with one answer">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'simple_choice')]}" role="img" aria-label="Multiple choice with one answer" title="Multiple choice with one answer">
|
||||
<div class="row"><i class="fa fa-circle-o fa-lg"/> answer</div>
|
||||
<div class="row"><i class="fa fa-dot-circle-o fa-lg"/> answer</div>
|
||||
<div class="row"><i class="fa fa-circle-o fa-lg"/> answer</div>
|
||||
</div>
|
||||
<!-- Multiple choice: multiple answers allowed -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'multiple_choice')]}" role="img" aria-label="Multiple choice with multiple answers" title="Multiple choice with multiple answers">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'multiple_choice')]}" role="img" aria-label="Multiple choice with multiple answers" title="Multiple choice with multiple answers">
|
||||
<div class="row"><i class="fa fa-square-o fa-lg"/> answer</div>
|
||||
<div class="row"><i class="fa fa-check-square-o fa-lg"/> answer</div>
|
||||
<div class="row"><i class="fa fa-square-o fa-lg"/> answer</div>
|
||||
</div>
|
||||
<!-- Matrix -->
|
||||
<div attrs="{'invisible': [('type', '!=', 'matrix')]}">
|
||||
<div attrs="{'invisible': [('question_type', '!=', 'matrix')]}">
|
||||
<div class="row o_matrix_head">
|
||||
<div class="col-lg-3"></div>
|
||||
<div class="col-lg-3">ans</div>
|
||||
@@ -472,10 +472,10 @@
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Answers">
|
||||
<field name="validation_email" attrs="{'invisible': [('type', '!=', 'textbox')]}"/>
|
||||
<label for="validation_email" attrs="{'invisible': [('type', '!=', 'textbox')]}"/>
|
||||
<field name="validation_email" attrs="{'invisible': [('question_type', '!=', 'textbox')]}"/>
|
||||
<label for="validation_email" attrs="{'invisible': [('question_type', '!=', 'textbox')]}"/>
|
||||
<separator />
|
||||
<field name="labels_ids" string="Type of answers" context="{'default_question_id': active_id}" attrs="{'invisible': [('type', 'not in', ['simple_choice', 'multiple_choice', 'matrix'])]}">
|
||||
<field name="labels_ids" string="Type of answers" context="{'default_question_id': active_id}" attrs="{'invisible': [('question_type', 'not in', ['simple_choice', 'multiple_choice', 'matrix'])]}">
|
||||
<tree editable="bottom">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="value" string="Choices"/>
|
||||
@@ -483,8 +483,8 @@
|
||||
</tree>
|
||||
</field>
|
||||
<separator />
|
||||
<label for="labels_ids_2" attrs="{'invisible': [('type', '!=', 'matrix')]}" />
|
||||
<field name="labels_ids_2" context="{'default_question_id_2': active_id}" attrs="{'invisible': [('type', '!=', 'matrix')]}">
|
||||
<label for="labels_ids_2" attrs="{'invisible': [('question_type', '!=', 'matrix')]}" />
|
||||
<field name="labels_ids_2" context="{'default_question_id_2': active_id}" attrs="{'invisible': [('question_type', '!=', 'matrix')]}">
|
||||
<tree editable="bottom">
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="value" string="Rows"/>
|
||||
@@ -497,32 +497,32 @@
|
||||
<field name="constr_mandatory" string="Mandatory Answer"/>
|
||||
<field name="constr_error_msg" attrs="{'invisible': [('constr_mandatory', '=', False)]}"/>
|
||||
</group>
|
||||
<div colspan="2" attrs="{'invisible': [('type', 'not in', ['textbox', 'numerical_box', 'date'])]}">
|
||||
<div colspan="2" attrs="{'invisible': [('question_type', 'not in', ['textbox', 'numerical_box', 'date'])]}">
|
||||
<group>
|
||||
<field name="validation_required" attrs="{'invisible': [('validation_email', '=', True), ('type', '=', 'textbox')]}"/>
|
||||
<field name="validation_required" attrs="{'invisible': [('validation_email', '=', True), ('question_type', '=', 'textbox')]}"/>
|
||||
</group>
|
||||
<group col="4" attrs="{'invisible': [('validation_required', '=', False)]}">
|
||||
<field name="validation_length_min" attrs="{'invisible': [('type', '!=', 'textbox')]}"/>
|
||||
<field name="validation_length_max" attrs="{'invisible': [('type', '!=', 'textbox')]}"/>
|
||||
<field name="validation_min_float_value" attrs="{'invisible': [('type', '!=', 'numerical_box')]}"/>
|
||||
<field name="validation_max_float_value" attrs="{'invisible': [('type', '!=', 'numerical_box')]}"/>
|
||||
<field name="validation_min_date" attrs="{'invisible': [('type', '!=', 'date')]}"/>
|
||||
<field name="validation_max_date" attrs="{'invisible': [('type', '!=', 'date')]}"/>
|
||||
<field name="validation_length_min" attrs="{'invisible': [('question_type', '!=', 'textbox')]}"/>
|
||||
<field name="validation_length_max" attrs="{'invisible': [('question_type', '!=', 'textbox')]}"/>
|
||||
<field name="validation_min_float_value" attrs="{'invisible': [('question_type', '!=', 'numerical_box')]}"/>
|
||||
<field name="validation_max_float_value" attrs="{'invisible': [('question_type', '!=', 'numerical_box')]}"/>
|
||||
<field name="validation_min_date" attrs="{'invisible': [('question_type', '!=', 'date')]}"/>
|
||||
<field name="validation_max_date" attrs="{'invisible': [('question_type', '!=', 'date')]}"/>
|
||||
<field name="validation_error_msg" colspan="4"/>
|
||||
</group>
|
||||
</div>
|
||||
<group>
|
||||
<field name="matrix_subtype" attrs="{'invisible':[('type','not in',['matrix'])]}"/>
|
||||
<field name="matrix_subtype" attrs="{'invisible':[('question_type','not in',['matrix'])]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group string="Display mode" attrs="{'invisible':[('type','not in',['simple_choice', 'multiple_choice'])]}">
|
||||
<field name="display_mode" string="Format" attrs="{'invisible':[('type','not in',['simple_choice'])],'required':[('type','=','simple_choice')]}"/>
|
||||
<field name="column_nb" string="Number of columns" attrs="{'invisible':[('display_mode','=','dropdown'), ('type','=','simple_choice')]}"/>
|
||||
<group string="Display mode" attrs="{'invisible':[('question_type','not in',['simple_choice', 'multiple_choice'])]}">
|
||||
<field name="display_mode" string="Format" attrs="{'invisible':[('question_type','not in',['simple_choice'])],'required':[('question_type','=','simple_choice')]}"/>
|
||||
<field name="column_nb" string="Number of columns" attrs="{'invisible':[('display_mode','=','dropdown'), ('question_type','=','simple_choice')]}"/>
|
||||
</group>
|
||||
<group string="Allow Comments" attrs="{'invisible':[('type','not in',['simple_choice','multiple_choice', 'matrix'])]}">
|
||||
<group string="Allow Comments" attrs="{'invisible':[('question_type','not in',['simple_choice','multiple_choice', 'matrix'])]}">
|
||||
<field name='comments_allowed' />
|
||||
<field name='comments_message' attrs="{'invisible': [('comments_allowed', '=', False)]}"/>
|
||||
<field name='comment_count_as_answer' attrs="{'invisible': ['|', ('comments_allowed', '=', False), ('type', 'in', ['matrix'])]}" />
|
||||
<field name='comment_count_as_answer' attrs="{'invisible': ['|', ('comments_allowed', '=', False), ('question_type', 'in', ['matrix'])]}" />
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
@@ -539,7 +539,7 @@
|
||||
<field name="question"/>
|
||||
<field name="page_id"/>
|
||||
<field name="survey_id"/>
|
||||
<field name="type"/>
|
||||
<field name="question_type"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -551,10 +551,10 @@
|
||||
<field name="question" string="Question"/>
|
||||
<field name="survey_id" string="Survey"/>
|
||||
<field name="page_id" string="Page"/>
|
||||
<field name="type" string="Type"/>
|
||||
<field name="question_type" string="Type"/>
|
||||
<group expand="1" string="Group By">
|
||||
<filter name="group_by_page" string="Page" domain="[]" context="{'group_by':'page_id'}"/>
|
||||
<filter name="group_by_type" string="Type" domain="[]" context="{'group_by':'type'}"/>
|
||||
<filter name="group_by_type" string="Type" domain="[]" context="{'group_by':'question_type'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user