summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorDebauche Stéphane <std@odoo.com>2020-02-04 08:06:28 +0000
committerThibault Delavallée <tde@odoo.com>2020-02-18 15:59:12 +0000
commit3721f49d4e64f29eb07686787bef77797fc69bc8 (patch)
treee71a471e49b9a8f7fb62006a84a133cf697e9754 /addons
parent9b55dfcc35f660fe94e376d14e63d30c33c068b1 (diff)
[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
Diffstat (limited to 'addons')
-rw-r--r--addons/website_event/controllers/main.py1
-rw-r--r--addons/website_event_questions/controllers/main.py20
-rw-r--r--addons/website_event_questions/tests/test_event_internals.py35
3 files changed, 49 insertions, 7 deletions
diff --git a/addons/website_event/controllers/main.py b/addons/website_event/controllers/main.py
index 5733639002f..84fa751112e 100644
--- a/addons/website_event/controllers/main.py
+++ b/addons/website_event/controllers/main.py
@@ -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():
diff --git a/addons/website_event_questions/controllers/main.py b/addons/website_event_questions/controllers/main.py
index bc8f98f1678..a24ccc941f9 100644
--- a/addons/website_event_questions/controllers/main.py
+++ b/addons/website_event_questions/controllers/main.py
@@ -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
diff --git a/addons/website_event_questions/tests/test_event_internals.py b/addons/website_event_questions/tests/test_event_internals.py
index dd13343b62c..aedaf148fc9 100644
--- a/addons/website_event_questions/tests/test_event_internals.py
+++ b/addons/website_event_questions/tests/test_event_internals.py
@@ -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]]}
+ ])