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.

39 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. from odoo import models, fields, api, _
  3. from werkzeug.datastructures import FileStorage
  4. TYPES = [
  5. ("free_text", _("Multiple Lines Text Box")),
  6. ("textbox", _("Single Line Text Box")),
  7. ("numerical_box", _("Numerical Value")),
  8. ("date", _("Date")),
  9. ("upload_file", _("Attachment (img/pdf)")),
  10. ("simple_choice", _("Multiple choice: only one answer")),
  11. ("multiple_choice", _("Multiple choice: multiple answers allowed")),
  12. ("matrix", _("Matrix")),
  13. ]
  14. class SurveyQuestion(models.Model):
  15. _inherit = "survey.question"
  16. # question_attachment = fields.Binary(string="Joined attachment")
  17. type = fields.Selection(selection=TYPES)
  18. @api.multi
  19. def validate_upload_file(self, post, answer_tag):
  20. self.ensure_one()
  21. errors = {}
  22. # Empty answer to mandatory question
  23. if self.constr_mandatory and not isinstance(post[answer_tag], FileStorage):
  24. errors.update({answer_tag: self.constr_error_msg})
  25. # Bad file type
  26. if (
  27. isinstance(post[answer_tag], FileStorage)
  28. and post[answer_tag].content_type != "application/pdf"
  29. and "image/" not in post[answer_tag].content_type
  30. ):
  31. errors.update(
  32. {answer_tag: _("The file you joined is not an image nor a PDF file.")}
  33. )
  34. return errors