[IMP] survey_crm_generation:

Manage lead description of survey answer with multiple objects
This commit is contained in:
clementthomas
2023-10-24 10:57:13 +02:00
parent dcd8dbb968
commit d5a834f3c9
2 changed files with 24 additions and 6 deletions

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-19 14:35+0000\n"
"PO-Revision-Date: 2023-09-19 14:35+0000\n"
"POT-Creation-Date: 2023-10-24 08:50+0000\n"
"PO-Revision-Date: 2023-10-24 08:50+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"

View File

@@ -30,10 +30,28 @@ class SurveyUserInput(models.Model):
lambda x: not x.skipped and x.question_id.show_in_lead_description
)
description = '<u>'+_('Survey answers: ')+"</u><ul><li>"+"</li><li>".join(
f"{answer.question_id.title}: {answer[f'value_{answer.answer_type}'].display_name}" if isinstance(answer[f'value_{answer.answer_type}'],models.Model) else f"{answer.question_id.title}: {answer[f'value_{answer.answer_type}']}"
for answer in relevant_answers
)+"</li></ul>"
li = ''
for answer in relevant_answers:
li += '<li>'
answer_value = answer[f'value_{answer.answer_type}']
#case of value Models
if isinstance(answer_value,models.Model):
# case of Multi Models
if len(answer_value._ids) > 1:
ul2 = f'{answer.question_id.title}: <ul>'
for answer_value_object in answer_value:
ul2 += '<li>'+f"{answer_value_object.display_name}"+'</li>'
ul2 += '</ul>'
li += ul2
# case of One Models
else:
li += f"{answer.question_id.title}: {answer_value.display_name}"
else:
# case of string value
li += f"{answer.question_id.title}: {answer_value}"
li += '</li>'
description = '<u>'+_('Survey answers: ')+"</u><ul>"+li+"</ul>"
return description
def _create_opportunity_post_process(self):