Files
odoo_source/addons/website_event_questions/models/event_registration.py
T
Aurélien Warnon a0e9e5670d [FIX] website_event_questions: support searching on attendees answers
Since: a0092d0011

Users can see attendees' selected answers in the registrations list view using
an optional field ("registration_answer_ids").

However, searching on this field is currently not correctly supported as the
"event.registration.answer" model does not implement it (no "_rec_name" and no
"_rec_names_search").

This commit adds a "_rec_names_search" attribute to allow users to search on
both "value_answer_id" and "value_text_box" fields.
This makes it easy to search for all attendees that have filled in a specific
answer, allowing a better organization of the event based on question results.

Task-2868203

closes odoo/odoo#92486

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-06-13 10:30:35 +02:00

41 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class EventRegistration(models.Model):
""" Store answers on attendees. """
_inherit = 'event.registration'
registration_answer_ids = fields.One2many('event.registration.answer', 'registration_id', string='Attendee Answers')
class EventRegistrationAnswer(models.Model):
""" Represents the user input answer for a single event.question """
_name = 'event.registration.answer'
_description = 'Event Registration Answer'
_rec_names_search = ['value_answer_id', 'value_text_box']
question_id = fields.Many2one(
'event.question', ondelete='restrict', required=True,
domain="[('event_id', '=', event_id)]")
registration_id = fields.Many2one('event.registration', required=True, ondelete='cascade')
partner_id = fields.Many2one('res.partner', related='registration_id.partner_id')
event_id = fields.Many2one('event.event', related='registration_id.event_id')
question_type = fields.Selection(related='question_id.question_type')
value_answer_id = fields.Many2one('event.question.answer', string="Suggested answer")
value_text_box = fields.Text('Text answer')
_sql_constraints = [
('value_check', "CHECK(value_answer_id IS NOT NULL OR COALESCE(value_text_box, '') <> '')", "There must be a suggested value or a text value.")
]
# for displaying selected answers by attendees in attendees list view
def name_get(self):
return [
(reg.id,
reg.value_answer_id.name if reg.question_type == "simple_choice" else reg.value_text_box
)
for reg in self
]