Odoo modules related to surveys
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

  1. # -*- coding: utf-8 -*-
  2. from odoo import api, fields, models
  3. from odoo.addons.survey.models.survey import dict_keys_startswith
  4. class SurveyQuestion(models.Model):
  5. _inherit = 'survey.question'
  6. matrix_subtype = fields.Selection(selection_add=[('custom', 'Custom Matrix')])
  7. @api.multi
  8. def validate_matrix(self, post, answer_tag):
  9. self.ensure_one()
  10. errors = {}
  11. if self.constr_mandatory:
  12. lines_number = len(self.labels_ids_2)
  13. answer_candidates = dict_keys_startswith(post, answer_tag)
  14. answer_candidates.pop(("%s_%s" % (answer_tag, 'comment')), '').strip()
  15. # Number of lines that have been answered
  16. if self.matrix_subtype == 'simple':
  17. answer_number = len(answer_candidates)
  18. elif self.matrix_subtype == 'multiple':
  19. answer_number = len({sk.rsplit('_', 1)[0] for sk in answer_candidates})
  20. elif self.matrix_subtype == 'custom':
  21. answer_number = len({sk.rsplit('_', 1)[0] for sk in answer_candidates})
  22. else:
  23. raise RuntimeError("Invalid matrix subtype")
  24. # Validate that each line has been answered
  25. if answer_number != lines_number:
  26. errors.update({answer_tag: self.constr_error_msg})
  27. return errors