Skip to content

Commit

Permalink
[FIX] survey_crm_generation: support all answers for lead description
Browse files Browse the repository at this point in the history
TT40979
  • Loading branch information
chienandalu committed Nov 16, 2023
1 parent 28039be commit a37c27b
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions survey_crm_generation/models/survey_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@ def _prepare_opportunity(self):
"description": self._prepare_lead_description(),
}

def _build_answers_description(self, answers):
"""TODO: Maybe this should go into a common module like survey_mail_result"""
description = ""
for answer in answers:
if answer.answer_type != "suggestion":
description += f"{answer.question_id.title}: "
description += f"{answer[f'value_{answer.answer_type}']}\n"
continue
elif answer.question_id.question_type == "simple_choice":
description += f"{answer.question_id.title}: "
description += f"{answer.suggested_answer_id.value}\n"
elif answer.question_id.question_type == "multiple_choice":
multiple_choice_dict = {}
multiple_choice_dict.setdefault(answer.question_id, [])
multiple_choice_dict[answer.question_id].append(
answer.suggested_answer_id.value
)
for question, answers in multiple_choice_dict.items():
description += (
f"{question.title or ''}: "
f"{' / '.join([x for x in answers if x])}\n"
)
elif answer.question_id.question_type == "matrix":
matrix_dict = {}
for answer in self.user_input_line_ids.filtered(
lambda x: x.question_id.question_type == "matrix" and not x.skipped
):
matrix_dict.setdefault(answer.question_id, {})
matrix_dict[answer.question_id].setdefault(answer.matrix_row_id, [])
matrix_dict[answer.question_id][answer.matrix_row_id].append(
answer.suggested_answer_id.value
)
for question, rows in matrix_dict.items():
description += f"{question.title}: \n"
for row, answers in rows.items():
description += (
f" {row.value}: "
f"{' / '.join([x for x in answers if x])}\n"
)
return 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.
Expand All @@ -29,11 +70,7 @@ def _prepare_lead_description(self):
relevant_answers = self.user_input_line_ids.filtered(
lambda x: not x.skipped and x.question_id.show_in_lead_description
)
description = "\n".join(
f"{answer.question_id.title}: {answer[f'value_{answer.answer_type}']}"
for answer in relevant_answers
)
return description
return self._build_answers_description(relevant_answers)

def _create_opportunity_post_process(self):
"""After creating the lead send an internal message with the input link"""
Expand Down

0 comments on commit a37c27b

Please sign in to comment.