You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.3 KiB
31 lines
1.3 KiB
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models
|
|
from odoo.addons.survey.models.survey import dict_keys_startswith
|
|
|
|
|
|
class SurveyQuestion(models.Model):
|
|
_inherit = 'survey.question'
|
|
|
|
matrix_subtype = fields.Selection(selection_add=[('custom', 'Custom Matrix')])
|
|
|
|
@api.multi
|
|
def validate_matrix(self, post, answer_tag):
|
|
self.ensure_one()
|
|
errors = {}
|
|
if self.constr_mandatory:
|
|
lines_number = len(self.labels_ids_2)
|
|
answer_candidates = dict_keys_startswith(post, answer_tag)
|
|
answer_candidates.pop(("%s_%s" % (answer_tag, 'comment')), '').strip()
|
|
# Number of lines that have been answered
|
|
if self.matrix_subtype == 'simple':
|
|
answer_number = len(answer_candidates)
|
|
elif self.matrix_subtype == 'multiple':
|
|
answer_number = len({sk.rsplit('_', 1)[0] for sk in answer_candidates})
|
|
elif self.matrix_subtype == 'custom':
|
|
answer_number = len({sk.rsplit('_', 1)[0] for sk in answer_candidates})
|
|
else:
|
|
raise RuntimeError("Invalid matrix subtype")
|
|
# Validate that each line has been answered
|
|
if answer_number != lines_number:
|
|
errors.update({answer_tag: self.constr_error_msg})
|
|
return errors
|