Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions website_event_questions_multiple/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Questions on Events - Type multiple
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github
:target: https://github.com/OCA/event/tree/16.0/website_event_questions_multiple
:alt: OCA/event
Expand All @@ -28,7 +28,7 @@ Questions on Events - Type multiple

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to add new question type : Selection multiple which allows
This module allows to add new question type : Multiple Selection which allows
attendees to select multiple answers to a question.

**Table of contents**
Expand All @@ -39,7 +39,7 @@ attendees to select multiple answers to a question.
Configuration
=============

On an event, when creating a new question, you can select new type : Selection multiple
On an event, when creating a new question, you can select new type : Multiple Selection

Bug Tracker
===========
Expand All @@ -58,6 +58,7 @@ Authors
~~~~~~~

* Le Filament
* Odoo S.A.

Contributors
~~~~~~~~~~~~
Expand Down
9 changes: 7 additions & 2 deletions website_event_questions_multiple/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
"category": "Marketing",
"website": "https://github.com/OCA/event",
"development_status": "Production/Stable",
"author": "Le Filament, Odoo Community Association (OCA)",
"license": "AGPL-3",
"author": "Le Filament, Odoo Community Association (OCA), Odoo S.A.",
"license": "LGPL-3",
"application": False,
"depends": ["website_event_questions"],
"data": [
"templates/event_template.xml",
"views/event_questions_views.xml",
"views/event_registration_views.xml",
],
"assets": {
"web.assets_frontend": [
"website_event_questions_multiple/static/src/js/form_validation.esm.js"
],
},
"installable": True,
"auto_install": False,
}
89 changes: 71 additions & 18 deletions website_event_questions_multiple/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.exceptions import UserError
from odoo.http import request

from odoo.addons.website_event_questions.controllers.main import WebsiteEvent
Expand All @@ -11,33 +12,85 @@ def _process_attendees_form(self, event, form_details):
"""Process data posted from the attendee details form.
Extracts question answers:
- For questions of type 'multiple_choice', extracting the suggested answer id"""
registrations = super(WebsiteEvent, self)._process_attendees_form(
event, form_details
registrations = super()._process_attendees_form(event, form_details)

# list all question_multi_answer with is_mandatory_answer
mandatory_multiple_general_question_answer_count = {}
mandatory_multiple_specific_question_ids = set()
req_filter = (
lambda q: q.question_type == "multiple_choice" and q.is_mandatory_answer
)
for general_question in event.general_question_ids.filtered(req_filter):
mandatory_multiple_general_question_answer_count[general_question.id] = 0
for specific_question in event.specific_question_ids.filtered(req_filter):
mandatory_multiple_specific_question_ids.add(specific_question.id)

mandatory_multiple_specific_question_answer_count = [
{i: 0 for i in mandatory_multiple_specific_question_ids}
for j in range(len(registrations))
]

general_answer_ids = []
for key, _value in form_details.items():
if "question_multi_answer" in key:
dummy, registration_index, question_answer = key.split("-")
question_id, answer_id = question_answer.split("_")
question_sudo = request.env["event.question"].browse(int(question_id))
# test html input prefix
if key.startswith("question_multi_answer"):
_html_input_prefix, registration_index_str, question_answer = key.split(
"-"
)
registration_index = int(registration_index_str)
question_id_str, answer_id = question_answer.split("_")
question_id = int(question_id_str)
question_sudo = request.env["event.question"].browse(question_id)
answer_sudo = request.env["event.question.answer"].browse(
int(answer_id)
)
answer_values = None
if question_sudo.question_type == "multiple_choice":
answer_values = {
"question_id": int(question_id),
"value_text_box": answer_sudo.name,
}

if answer_values and not int(registration_index):
assert (
question_sudo.question_type == "multiple_choice"
) # otherwise, html is malformed
answer_values = {
"question_id": question_id,
"value_text_box": answer_sudo.name,
}
# question with null registration index are general
if registration_index == 0:
general_answer_ids.append((0, 0, answer_values))
elif answer_values:
registrations[int(registration_index) - 1][
"registration_answer_ids"
].append((0, 0, answer_values))
if question_sudo.is_mandatory_answer:
mandatory_multiple_general_question_answer_count[
question_id
] += 1
# question with registration index are specific to one registration
else:
rindex = registration_index - 1 # zero-based array ¹indexing
registrations[rindex]["registration_answer_ids"].append(
(0, 0, answer_values)
)
if question_sudo.is_mandatory_answer:
mandatory_multiple_specific_question_answer_count[rindex][
question_id
] += 1

# check that answers contain at least one for mandatory question
# general
for q, c in mandatory_multiple_general_question_answer_count.items():
if c == 0:
raise UserError(
"Question "
+ str(q)
+ " is mandatory but did not receive an answer."
)
# specific
for r, cc in enumerate(mandatory_multiple_specific_question_answer_count):
for q, c in cc.items():
if c == 0:
raise UserError(
"Question "
+ str(q)
+ " is mandatory but did not receive an answer in ticket number "
+ str(r)
+ "."
)

# append general question to all items
for registration in registrations:
registration["registration_answer_ids"].extend(general_answer_ids)

Expand Down
36 changes: 36 additions & 0 deletions website_event_questions_multiple/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_event_questions_multiple
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-03-06 11:52+0000\n"
"PO-Revision-Date: 2025-03-06 11:52+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: website_event_questions_multiple
#: model:ir.model,name:website_event_questions_multiple.model_event_question
msgid "Event Question"
msgstr "Question"

#. module: website_event_questions_multiple
#: model:ir.model.fields.selection,name:website_event_questions_multiple.selection__event_question__question_type__multiple_choice
msgid "Multiple Selection"
msgstr "Sélection multiple"

#. module: website_event_questions_multiple
#: model:ir.model.fields,field_description:website_event_questions_multiple.field_event_question__question_type
msgid "Question Type"
msgstr "Type de question"

#. module: website_event_questions_multiple
#: model_terms:ir.ui.view,arch_db:website_event_questions_multiple.registration_event_question
msgid "Please select at least one checkbox."
msgstr "Veuillez cocher au moins une case."
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ <h1 class="title">Questions on Events - Type multiple</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:de10ccad1e53385cb3c9aa56bc533e4cd053db148e2d5fec32a0a0e04ac0e690
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/event/tree/16.0/website_event_questions_multiple"><img alt="OCA/event" src="https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/event-16-0/event-16-0-website_event_questions_multiple"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/event&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to add new question type : Selection multiple which allows
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/event/tree/16.0/website_event_questions_multiple"><img alt="OCA/event" src="https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/event-16-0/event-16-0-website_event_questions_multiple"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/event&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to add new question type : Multiple Selection which allows
attendees to select multiple answers to a question.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -388,7 +388,7 @@ <h1 class="title">Questions on Events - Type multiple</h1>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>On an event, when creating a new question, you can select new type : Selection multiple</p>
<p>On an event, when creating a new question, you can select new type : Multiple Selection</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
Expand All @@ -404,6 +404,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<ul class="simple">
<li>Le Filament</li>
<li>Odoo S.A.</li>
</ul>
</div>
<div class="section" id="contributors">
Expand Down
Loading