[IMP] survey: improve user answers model and display in backend

PURPOSE

Perform a back2basics review of survey to improve daily use, new user
onboarding and labelling.

SPECIFICATIONS

Order answer lines following question order.

Display section in answer lines form view to better understand question and
answer organization.

Add a correct flag on answer lines and display it in user input embedded
view in order to know which line are correct.

LINKS

Task 2039068
PR #36229
This commit is contained in:
Jitendra Prajapati
2019-08-29 15:36:48 +00:00
committed by Thibault Delavallée
parent 0636347099
commit ee5649cdff
2 changed files with 15 additions and 1 deletions
+11
View File
@@ -199,12 +199,14 @@ class SurveyUserInputLine(models.Model):
_name = 'survey.user_input_line'
_description = 'Survey User Input Line'
_rec_name = 'user_input_id'
_order = 'question_sequence,id'
# survey data
user_input_id = fields.Many2one('survey.user_input', string='User Input', ondelete='cascade', required=True)
survey_id = fields.Many2one(related='user_input_id.survey_id', string='Survey', store=True, readonly=False)
question_id = fields.Many2one('survey.question', string='Question', ondelete='cascade', required=True)
page_id = fields.Many2one(related='question_id.page_id', string="Section", readonly=False)
question_sequence = fields.Integer('Sequence', related='question_id.sequence', store=True)
# answer
skipped = fields.Boolean('Skipped')
answer_type = fields.Selection([
@@ -222,6 +224,15 @@ class SurveyUserInputLine(models.Model):
value_suggested = fields.Many2one('survey.label', string="Suggested answer")
value_suggested_row = fields.Many2one('survey.label', 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')
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
else:
answer.answer_is_correct = False
@api.constrains('skipped', 'answer_type')
def _answered_or_skipped(self):
+4 -1
View File
@@ -66,11 +66,14 @@
</group>
<field name="user_input_line_ids" mode="tree" attrs="{'readonly': False}">
<tree>
<field name="question_sequence" invisible="1"/>
<field name="question_id"/>
<field name="page_id"/>
<field name="answer_type"/>
<field name="skipped"/>
<field name="create_date"/>
<field name="answer_score" groups="base.group_no_one"/>
<field name="answer_is_correct"/>
<field name="answer_score"/>
</tree>
</field>
</sheet>