diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_event_questions/controllers/main.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_event_questions/controllers/main.py')
| -rw-r--r-- | addons/website_event_questions/controllers/main.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/addons/website_event_questions/controllers/main.py b/addons/website_event_questions/controllers/main.py new file mode 100644 index 00000000..885866ab --- /dev/null +++ b/addons/website_event_questions/controllers/main.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.http import request + +from odoo.addons.website_event.controllers.main import WebsiteEventController + + +class WebsiteEvent(WebsiteEventController): + + def _process_attendees_form(self, event, form_details): + """ Process data posted from the attendee details form. + Extracts question answers: + - For both questions asked 'once_per_order' and questions asked to every attendee + - For questions of type 'simple_choice', extracting the suggested answer id + - For questions of type 'text_box', extracting the text answer of the attendee. """ + registrations = super(WebsiteEvent, self)._process_attendees_form(event, form_details) + + for registration in registrations: + registration['registration_answer_ids'] = [] + + general_answer_ids = [] + for key, value in form_details.items(): + if 'question_answer' in key and value: + dummy, registration_index, question_id = key.split('-') + question_sudo = request.env['event.question'].browse(int(question_id)) + answer_values = None + if question_sudo.question_type == 'simple_choice': + answer_values = { + 'question_id': int(question_id), + 'value_answer_id': int(value) + } + elif question_sudo.question_type == 'text_box': + answer_values = { + 'question_id': int(question_id), + 'value_text_box': value + } + + if answer_values and not int(registration_index): + general_answer_ids.append((0, 0, answer_values)) + elif answer_values: + registrations[int(registration_index) - 1]['registration_answer_ids'].append((0, 0, answer_values)) + + for registration in registrations: + registration['registration_answer_ids'].extend(general_answer_ids) + + return registrations |
