# Copyright 2022 Tecnativa - David Vidal # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import fields, models, _ class SurveyUserInput(models.Model): _inherit = "survey.user_input" opportunity_id = fields.Many2one(comodel_name="crm.lead") def _prepare_opportunity(self): return { "name": self.survey_id.title, "tag_ids": [(6, 0, self.survey_id.crm_tag_ids.ids)], "partner_id": self.partner_id.id, "user_id": self.survey_id.crm_team_id.user_id.id, "team_id": self.survey_id.crm_team_id.id, "company_id": self.create_uid.company_id.id, "survey_user_input_id": self.id, "description": self._prepare_lead_description(), } def _prepare_lead_description(self): """We can have surveys without partner. It's handy to have some relevant info in the description although the answers are linked themselves. :return str: description for the lead """ relevant_answers = self.user_input_line_ids.filtered( lambda x: not x.skipped and x.question_id.show_in_lead_description ) description = ''+_('Survey answers: ')+"