diff --git a/addons/survey/data/survey.user_input.line.csv b/addons/survey/data/survey.user_input.line.csv index e15921b834771d59b9c8f61ce727612672b89f74..9b172c56c47f8752b47408b847fcdac4c3d0c79c 100644 --- a/addons/survey/data/survey.user_input.line.csv +++ b/addons/survey/data/survey.user_input.line.csv @@ -1,4 +1,4 @@ -id,user_input_id:id,question_id:id,skipped,answer_type,value_text,value_number,value_date,value_free_text,value_suggested:id,value_suggested_row:id +id,user_input_id:id,question_id:id,skipped,answer_type,value_text,value_number,value_date,value_free_text,suggested_answer_id:id,matrix_row_id:id survey_answer_1_p1_q1,survey_answer_1,survey_feedback_p1_q1,False,text,Brussels,,,,, survey_answer_1_p1_q2,survey_answer_1,survey_feedback_p1_q2,False,date,,,1980-01-11,,, survey_answer_1_p1_q3,survey_answer_1,survey_feedback_p1_q3,False,suggestion,,,,,survey_feedback_p1_q3_sug3, diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index 693ebe920db01fe472846b747cc5a82c82ef6556..fa70857abc51e0c2785f296ba33bf23e7124304a 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -571,9 +571,9 @@ class Survey(models.Model): if row_id == 0: choice.append(answer_id) else: - domain_filter.extend(['|', ('value_suggested_row.id', '=', row_id), ('value_suggested.id', '=', answer_id)]) + domain_filter.extend(['|', ('matrix_row_id.id', '=', row_id), ('suggested_answer_id.id', '=', answer_id)]) if choice: - domain_filter.insert(0, ('value_suggested.id', 'in', choice)) + domain_filter.insert(0, ('suggested_answer_id.id', 'in', choice)) else: domain_filter = domain_filter[1:] input_lines = self.env['survey.user_input.line'].search(domain_filter) @@ -622,8 +622,8 @@ class Survey(models.Model): comments = [] answers = OrderedDict((label.id, {'text': label.value, 'count': 0, 'answer_id': label.id, 'answer_score': label.answer_score}) for label in question.suggested_answer_ids) for input_line in input_lines: - if input_line.answer_type == 'suggestion' and answers.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters): - answers[input_line.value_suggested.id]['count'] += 1 + if input_line.answer_type == 'suggestion' and answers.get(input_line.suggested_answer_id.id) and (not(current_filters) or input_line.user_input_id.id in current_filters): + answers[input_line.suggested_answer_id.id]['count'] += 1 if input_line.answer_type == 'text' and (not(current_filters) or input_line.user_input_id.id in current_filters): comments.append(input_line) result_summary = {'answers': list(answers.values()), 'comments': comments} @@ -639,8 +639,8 @@ class Survey(models.Model): for cell in product(rows, answers): res[cell] = 0 for input_line in input_lines: - if input_line.answer_type == 'suggestion' and (not(current_filters) or input_line.user_input_id.id in current_filters) and input_line.value_suggested_row: - res[(input_line.value_suggested_row.id, input_line.value_suggested.id)] += 1 + if input_line.answer_type == 'suggestion' and (not(current_filters) or input_line.user_input_id.id in current_filters) and input_line.matrix_row_id: + res[(input_line.matrix_row_id.id, input_line.suggested_answer_id.id)] += 1 if input_line.answer_type == 'text' and (not(current_filters) or input_line.user_input_id.id in current_filters): comments.append(input_line) result_summary = {'answers': answers, 'rows': rows, 'result': res, 'comments': comments} @@ -699,7 +699,7 @@ class Survey(models.Model): question_answer_correct = question.suggested_answer_ids.filtered(lambda answer: answer.is_correct) for user_answer in user_answers: user_answer_lines_question = user_answer.user_input_line_ids.filtered(lambda line: line.question_id == question) - user_answer_correct = user_answer_lines_question.filtered(lambda line: line.answer_is_correct and not line.skipped).mapped('value_suggested') + user_answer_correct = user_answer_lines_question.filtered(lambda line: line.answer_is_correct and not line.skipped).mapped('suggested_answer_id') user_answer_incorrect = user_answer_lines_question.filtered(lambda line: not line.answer_is_correct and not line.skipped) if user_answer_correct == question_answer_correct: diff --git a/addons/survey/models/survey_user.py b/addons/survey/models/survey_user.py index b6ccda6539bf5233163db95efe4c8c35b486a561..ec13fbda55f656511482292a1c54dff2da88a036 100644 --- a/addons/survey/models/survey_user.py +++ b/addons/survey/models/survey_user.py @@ -196,16 +196,16 @@ class SurveyUserInputLine(models.Model): value_date = fields.Date('Date answer') value_datetime = fields.Datetime('Datetime answer') value_free_text = fields.Text('Free Text answer') - value_suggested = fields.Many2one('survey.question.answer', string="Suggested answer") - value_suggested_row = fields.Many2one('survey.question.answer', string="Row answer") + suggested_answer_id = fields.Many2one('survey.question.answer', string="Suggested answer") + matrix_row_id = fields.Many2one('survey.question.answer', string="Row answer") answer_score = fields.Float('Score') answer_is_correct = fields.Boolean('Correct', compute='_compute_answer_is_correct') - @api.depends('value_suggested', 'question_id') + @api.depends('suggested_answer_id', 'question_id') def _compute_answer_is_correct(self): for answer in self: - if answer.value_suggested and answer.question_id.question_type in ['simple_choice', 'multiple_choice']: - answer.answer_is_correct = answer.value_suggested.is_correct + if answer.suggested_answer_id and answer.question_id.question_type in ['simple_choice', 'multiple_choice']: + answer.answer_is_correct = answer.suggested_answer_id.is_correct else: answer.answer_is_correct = False @@ -223,7 +223,7 @@ class SurveyUserInputLine(models.Model): 'number': (bool(uil.value_number) or uil.value_number == 0), 'date': bool(uil.value_date), 'free_text': bool(uil.value_free_text), - 'suggestion': bool(uil.value_suggested) + 'suggestion': bool(uil.suggested_answer_id) } if not fields_type.get(uil.answer_type, True): raise ValidationError(_('The answer must be in the right type')) @@ -231,22 +231,22 @@ class SurveyUserInputLine(models.Model): @api.model_create_multi def create(self, vals_list): for vals in vals_list: - value_suggested = vals.get('value_suggested') - if value_suggested: - vals.update({'answer_score': self.env['survey.question.answer'].browse(int(value_suggested)).answer_score}) + suggested_answer_id = vals.get('suggested_answer_id') + if suggested_answer_id: + vals.update({'answer_score': self.env['survey.question.answer'].browse(int(suggested_answer_id)).answer_score}) return super(SurveyUserInputLine, self).create(vals_list) def write(self, vals): - value_suggested = vals.get('value_suggested') - if value_suggested: - vals.update({'answer_score': self.env['survey.question.answer'].browse(int(value_suggested)).answer_score}) + suggested_answer_id = vals.get('suggested_answer_id') + if suggested_answer_id: + vals.update({'answer_score': self.env['survey.question.answer'].browse(int(suggested_answer_id)).answer_score}) return super(SurveyUserInputLine, self).write(vals) def _get_save_line_values(self, answer, answer_type): if not answer or (isinstance(answer, str) and not answer.strip()): return {'answer_type': None, 'skipped': True} if answer_type == 'suggestion': - return {'answer_type': answer_type, 'value_suggested': answer} + return {'answer_type': answer_type, 'suggested_answer_id': answer} value = float(answer) if answer_type == 'number' else answer return {'answer_type': answer_type, 'value_' + answer_type: value} @@ -310,7 +310,7 @@ class SurveyUserInputLine(models.Model): vals_list.append(vals.copy()) if comment: - vals.update({'answer_type': 'text', 'value_text': comment, 'skipped': False, 'value_suggested': False}) + vals.update({'answer_type': 'text', 'value_text': comment, 'skipped': False, 'suggested_answer_id': False}) vals_list.append(vals.copy()) old_answers.sudo().unlink() @@ -324,11 +324,11 @@ class SurveyUserInputLine(models.Model): for row_key, row_answer in answers.items(): for answer in row_answer: - vals.update({'answer_type': 'suggestion', 'value_suggested': answer, 'value_suggested_row': row_key}) + vals.update({'answer_type': 'suggestion', 'suggested_answer_id': answer, 'matrix_row_id': row_key}) vals_list.append(vals.copy()) if comment: - vals.update({'answer_type': 'text', 'value_text': comment, 'skipped': False, 'value_suggested': False}) + vals.update({'answer_type': 'text', 'value_text': comment, 'skipped': False, 'suggested_answer_id': False}) vals_list.append(vals.copy()) old_answers.sudo().unlink() diff --git a/addons/survey/tests/common.py b/addons/survey/tests/common.py index 539d57aaa59ee58663088e05eb66b303615ac5de..7dcdf9ca52169fff7d497e32c9739c0f24350fc4 100644 --- a/addons/survey/tests/common.py +++ b/addons/survey/tests/common.py @@ -26,9 +26,9 @@ class TestSurveyCommon(common.SavepointCase): 'textbox': ('text', 'value_text'), 'numerical_box': ('number', 'value_number'), 'date': ('date', 'value_date'), - 'simple_choice': ('suggestion', 'value_suggested'), # TDE: still unclear - 'multiple_choice': ('suggestion', 'value_suggested'), # TDE: still unclear - 'matrix': ('suggestion', ('value_suggested', 'value_suggested_row')), # TDE: still unclear + 'simple_choice': ('suggestion', 'suggested_answer_id'), # TDE: still unclear + 'multiple_choice': ('suggestion', 'suggested_answer_id'), # TDE: still unclear + 'matrix': ('suggestion', ('suggested_answer_id', 'matrix_row_id')), # TDE: still unclear } """ Create test data: a survey with some pre-defined questions and various test users for ACL """ diff --git a/addons/survey/tests/test_survey.py b/addons/survey/tests/test_survey.py index fc79ae5c053473e1036540a2ba215dd2ff070531..0ac4776b9671430d00ccb1f462a92c791e9059ce 100644 --- a/addons/survey/tests/test_survey.py +++ b/addons/survey/tests/test_survey.py @@ -131,8 +131,8 @@ class TestSurveyInternals(common.TestSurveyCommon): answer = self._add_answer(self.survey, False, email='public@example.com') self._add_answer_line( question, answer, random.choice(question.suggested_answer_ids.ids), - answer_type='suggestion', answer_fname='value_suggested') - lines = [line.value_suggested.id for line in question.user_input_line_ids] + answer_type='suggestion', answer_fname='suggested_answer_id') + lines = [line.suggested_answer_id.id for line in question.user_input_line_ids] answers = [{'text': label.value, 'count': lines.count(label.id), 'answer_id': label.id, 'answer_score': label.answer_score} for label in question.suggested_answer_ids] prp_result = self.env['survey.survey'].prepare_result(question)['answers'] self.assertItemsEqual(prp_result, answers) @@ -148,9 +148,9 @@ class TestSurveyInternals(common.TestSurveyCommon): answer = self._add_answer(self.survey, False, email='public@example.com') self._add_answer_line( question, answer, random.choice(question.suggested_answer_ids.ids), - answer_type='suggestion', answer_fname='value_suggested', value_suggested_row=random.choice(question.matrix_row_ids.ids) + answer_type='suggestion', answer_fname='suggested_answer_id', matrix_row_id=random.choice(question.matrix_row_ids.ids) ) - lines = [(line.value_suggested_row.id, line.value_suggested.id) for line in question.user_input_line_ids] + lines = [(line.matrix_row_id.id, line.suggested_answer_id.id) for line in question.user_input_line_ids] res = {} for i in product(question.matrix_row_ids.ids, question.suggested_answer_ids.ids): res[i] = lines.count((i)) diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index a4e046745ceb3b6b99902d26fcec18505911798d..bc59d0c1bf77016c7ac01e7b2f1df6ca8c75cf8a 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -232,7 +232,7 @@ </template> <template id="question_simple_choice" name="Question: simple choice"> - <t t-set="answer_line" t-value="answer_lines.filtered(lambda line: line.value_suggested)"/> + <t t-set="answer_line" t-value="answer_lines.filtered(lambda line: line.suggested_answer_id)"/> <t t-set="comment_line" t-value="answer_lines.filtered(lambda line: line.value_text)"/> <div t-if="question.display_mode == 'dropdown'" class="o_survey_form_choice o_survey_question_simple_choice_dropdown row" t-att-data-name="question.id" @@ -243,7 +243,7 @@ t-att-selected="not answer_line and (not comment_line or not question.comment_count_as_answer) and 'selected' or None">Choose...</option> <t t-foreach='question.suggested_answer_ids' t-as='label'> <option t-att-value='label.id' - t-att-selected="answer_line and answer_line.value_suggested == label and 'selected' or None"><t t-esc='label.value'/></option> + t-att-selected="answer_line and answer_line.suggested_answer_id == label and 'selected' or None"><t t-esc='label.value'/></option> </t> <t t-if='question.comments_allowed and question.comment_count_as_answer'> <option class="o_survey_js_form_other_comment" value="-1" @@ -268,7 +268,7 @@ <div t-foreach='question.suggested_answer_ids' t-as='label' t-attf-class="col-lg-#{question.column_nb}"> <label t-att-class="' bg-success ' if quizz_correction and label.answer_score > 0.0 else None"> <input type="radio" t-att-value='label.id' class="o_survey_form_choice_item" - t-att-checked="answer_line and answer_line.value_suggested.id == label.id and 'checked' or None"/> + t-att-checked="answer_line and answer_line.suggested_answer_id.id == label.id and 'checked' or None"/> <span t-field='label.value'/> </label> </div> @@ -294,7 +294,7 @@ t-att-data-name="question.id" t-att-data-question-type="question.question_type"> <div t-foreach='question.suggested_answer_ids' t-as='label' t-attf-class="col-lg-#{question.column_nb}"> - <t t-set="answer_line" t-value="answer_lines.filtered(lambda line: line.value_suggested == label)"/> + <t t-set="answer_line" t-value="answer_lines.filtered(lambda line: line.suggested_answer_id == label)"/> <label t-att-class="' bg-success ' if quizz_correction and label.answer_score > 0.0 else None"> <input type="checkbox" t-att-value='label.id' class="o_survey_form_choice_item" t-att-checked="'checked' if answer_line else None"/> @@ -333,7 +333,7 @@ <tr t-foreach="question.matrix_row_ids" t-as="row_label"> <th><span t-field="row_label.value" /></th> <td t-foreach="question.suggested_answer_ids" t-as="col_label"> - <t t-set="answer" t-value="answer_lines.filtered(lambda line: line.value_suggested == col_label and line.value_suggested_row == row_label)"/> + <t t-set="answer" t-value="answer_lines.filtered(lambda line: line.suggested_answer_id == col_label and line.matrix_row_id == row_label)"/> <input t-att-type="'checkbox' if question.matrix_subtype == 'multiple' else 'radio'" t-att-name="'%s_%s' % (question_id, row_label.id)" t-att-value='col_label.id' t-att-checked="'checked' if answer else None" diff --git a/addons/survey/views/survey_user_views.xml b/addons/survey/views/survey_user_views.xml index c2252f458714e3dcadda476b4e17726be33c608f..95bb8e57ca6ef61b31b35d762a7147da6870ad74 100644 --- a/addons/survey/views/survey_user_views.xml +++ b/addons/survey/views/survey_user_views.xml @@ -167,8 +167,8 @@ <field name="value_date" colspan='2' attrs="{'invisible': [('answer_type','!=','date')]}"/> <field name="value_datetime" colspan='2' attrs="{'invisible': [('answer_type','!=','datetime')]}"/> <field name="value_free_text" colspan='2' attrs="{'invisible': [('answer_type','!=','free_text')]}"/> - <field name="value_suggested_row" colspan='2' /> - <field name="value_suggested" colspan='2' attrs="{'invisible': [('answer_type','!=','suggestion')]}"/> + <field name="matrix_row_id" colspan='2' /> + <field name="suggested_answer_id" colspan='2' attrs="{'invisible': [('answer_type','!=','suggestion')]}"/> </group> </sheet> </form> diff --git a/addons/website_slides_survey/data/survey.user_input.line.csv b/addons/website_slides_survey/data/survey.user_input.line.csv index ac1b3a1d3753abad67bccb6b7e9828d05621e03c..315c6740f01dcab9610e314f357de769be764bea 100644 --- a/addons/website_slides_survey/data/survey.user_input.line.csv +++ b/addons/website_slides_survey/data/survey.user_input.line.csv @@ -1,4 +1,4 @@ -id,user_input_id:id,question_id:id,skipped,answer_type,value_text,value_number,value_date,value_free_text,value_suggested:id,value_suggested_row:id +id,user_input_id:id,question_id:id,skipped,answer_type,value_text,value_number,value_date,value_free_text,suggested_answer_id:id,matrix_row_id:id furniture_certification_answer_1_p1_q1,furniture_certification_answer_1,furniture_certification_page_1_question_1,False,suggestion,,,,,furniture_certification_page_1_question_1_choice_2, furniture_certification_answer_1_p1_q2_1,furniture_certification_answer_1,furniture_certification_page_1_question_2,False,suggestion,,,,,furniture_certification_page_1_question_2_choice_1, furniture_certification_answer_1_p1_q2_2,furniture_certification_answer_1,furniture_certification_page_1_question_2,False,suggestion,,,,,furniture_certification_page_1_question_2_choice_3, diff --git a/addons/website_slides_survey/tests/test_course_certification_failure.py b/addons/website_slides_survey/tests/test_course_certification_failure.py index 1487fb2eea0fe58050b73dfd3c119d092008e757..f8c6a4011cd3c787a81e50c11b486f451d4fe40e 100644 --- a/addons/website_slides_survey/tests/test_course_certification_failure.py +++ b/addons/website_slides_survey/tests/test_course_certification_failure.py @@ -116,7 +116,7 @@ class TestCourseCertificationFailureFlow(TestSurveyCommon): 'question_id': question.id, 'answer_type': 'suggestion', 'answer_score': 1 if good_answers else 0, - 'value_suggested': question.suggested_answer_ids[1 if good_answers else 0].id + 'suggested_answer_id': question.suggested_answer_ids[1 if good_answers else 0].id }) for question in questions ] })