[FIX] website_event(_questions): correctly parse frontend question answers

When user register to an event from website, they can answer questions
specific to a given registration or to all registrations. However they
are not correctly parsed and not saved.

Task 2188857
PR #44545

X-original-commit: e27d9b5c4f234f6ce64456c2f52e7cfb0331332f
This commit is contained in:
Debauche Stéphane
2020-02-18 15:59:12 +00:00
committed by Thibault Delavallée
parent 9b55dfcc35
commit 3721f49d4e
3 changed files with 49 additions and 7 deletions
-1
View File
@@ -296,7 +296,6 @@ class WebsiteEventController(http.Controller):
{'1-name': 'r', '1-email': 'r@r.com', '1-phone': '', '1-event_ticket_id': '1'}
"""
registration_fields = request.env['event.registration']._fields
registrations = {}
global_values = {}
for key, value in form_details.items():
@@ -9,10 +9,20 @@ class WebsiteEvent(WebsiteEventController):
def _process_attendees_form(self, event, form_details):
''' Process data posted from the attendee details form. '''
registrations = super(WebsiteEvent, self)._process_attendees_form(event, form_details)
for registration in registrations:
answer_ids = []
for key, value in registration.items():
if key.startswith('answer_ids-'):
answer_ids.append([4, int(value)])
registration['answer_ids'] = answer_ids
registration['answer_ids'] = []
general_answer_ids = []
for key, value in form_details.items():
if 'answer_ids' in key:
index = int(key.split('-')[0])
if not index:
general_answer_ids.append([4, int(value)])
else:
registrations[index-1]['answer_ids'].append([4, int(value)])
for registration in registrations:
registration['answer_ids'].extend(general_answer_ids)
return registrations
@@ -3,9 +3,11 @@
from datetime import datetime, timedelta
from odoo.addons.website_event_questions.tests.common import TestEventQuestionCommon
from odoo.fields import Datetime as FieldsDatetime
from odoo.tests.common import users
from odoo.addons.website.tools import MockRequest
from odoo.addons.website_event_questions.controllers.main import WebsiteEvent
from odoo.addons.website_event_questions.tests.common import TestEventQuestionCommon
class TestEventData(TestEventQuestionCommon):
@@ -29,3 +31,34 @@ class TestEventData(TestEventQuestionCommon):
self.assertEqual(
set(event.general_question_ids.mapped('answer_ids.name')),
set(['Q2-Answer1', 'Q2-Answer2']))
def test_process_attendees_form(self):
event = self.env['event.event'].create({
'name': 'Event Update Type',
'event_type_id': self.event_type_complex.with_user(self.env.user).id,
'date_begin': FieldsDatetime.to_string(datetime.today() + timedelta(days=1)),
'date_end': FieldsDatetime.to_string(datetime.today() + timedelta(days=15)),
})
form_details = {
'1-name': 'Pixis',
'1-email': 'pixis@gmail.com',
'1-phone': '+32444444444',
'1-event_ticket_id': '2',
'1-answer_ids-8': '5',
'2-name': 'Geluchat',
'2-email': 'geluchat@gmail.com',
'2-phone': '+32777777777',
'2-event_ticket_id': '3',
'2-answer_ids-8': '9',
'0-answer_ids-3': '7',
'0-answer_ids-4': '1',
}
with MockRequest(self.env):
registrations = WebsiteEvent()._process_attendees_form(event, form_details)
self.assertEqual(registrations, [
{'name': 'Pixis', 'email': 'pixis@gmail.com', 'phone': '+32444444444', 'event_ticket_id': 2, 'answer_ids': [[4, 5], [4, 7], [4, 1]]},
{'name': 'Geluchat', 'email': 'geluchat@gmail.com', 'phone': '+32777777777', 'event_ticket_id': 3, 'answer_ids': [[4, 9], [4, 7], [4, 1]]}
])