Files
odoo_source/addons/website_event/models/event_registration_answer.py
T
Patrick Hoste cc60fcd45c [MOV] website_event(_crm)_questions: move event questions code
This commit moves the code from website_event_questions to
website_event and from website_event_crm_questions to
website_event_crm module.

Task-3056380

Part-of: odoo/odoo#112164
2023-05-12 21:50:44 +02:00

35 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
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
]