summaryrefslogtreecommitdiff
path: root/addons/website_event_crm_questions/models/event_registration.py
blob: 724ced14a31f4af35f21f6f9d072334197aefed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models, _


class EventRegistration(models.Model):
    _inherit = 'event.registration'

    def _get_lead_description_registration(self, prefix='', line_suffix=''):
        """Add the questions and answers linked to the registrations into the description of the lead."""
        reg_description = super(EventRegistration, self)._get_lead_description_registration(prefix=prefix, line_suffix=line_suffix)
        if not self.registration_answer_ids:
            return reg_description

        answer_descriptions = []
        for answer in self.registration_answer_ids:
            answer_value = answer.value_answer_id.name if answer.question_type == "simple_choice" else answer.value_text_box
            answer_value = "\n".join(["    %s" % line for line in answer_value.split('\n')])
            answer_descriptions.append("  - %s\n%s" % (answer.question_id.title, answer_value))
        return "%s\n%s\n%s" % (reg_description, _("Questions"), '\n'.join(answer_descriptions))

    def _get_lead_description_fields(self):
        res = super(EventRegistration, self)._get_lead_description_fields()
        res.append('registration_answer_ids')
        return res