Skip to content

Commit

Permalink
Merge PR #112 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Oct 11, 2024
2 parents 6298cb3 + b99c5fc commit 345d2c8
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 3 deletions.
5 changes: 4 additions & 1 deletion survey_crm_generation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Survey leads generation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d79e7bbad72ba02077da9a051eb24fff17d230a080af344ca6067f5492e3a544
!! source digest: sha256:289aff9f8141bd13d33db390ba910026796e8a0f3cce337d3776c85eb08f44c4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -47,6 +47,9 @@ To configure the leads/opportunities generation:

The questions marked to be shown in the lead description will be shown there.

If you want to fill crm.lead fields from the answers set the *CRM Lead field* you want
to fill with the given answer.

Usage
=====

Expand Down
21 changes: 21 additions & 0 deletions survey_crm_generation/demo/survey_crm_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,25 @@
<field name="show_in_lead_description" eval="True" />
<field name="constr_mandatory" eval="True" />
</record>
<record model="survey.question" id="survey_oca_q4">
<field name="survey_id" ref="become_partner" />
<field name="sequence">6</field>
<field name="title">Referenced by</field>
<field name="question_type">simple_choice</field>
<field name="comments_allowed" eval="True" />
<field name="comment_count_as_answer" eval="True" />
<field name="comments_message">Other:</field>
<field name="crm_lead_field" ref="crm.field_crm_lead__referred" />
<field name="constr_mandatory" eval="True" />
</record>
<record model="survey.question.answer" id="survey_oca_q4_sug1">
<field name="question_id" ref="survey_oca_q4" />
<field name="sequence">1</field>
<field name="value">TV</field>
</record>
<record model="survey.question.answer" id="survey_oca_q4_sug2">
<field name="question_id" ref="survey_oca_q4" />
<field name="sequence">2</field>
<field name="value">Internet</field>
</record>
</odoo>
34 changes: 33 additions & 1 deletion survey_crm_generation/models/survey_question.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import api, fields, models


class SurveyQuestion(models.Model):
_inherit = "survey.question"

show_in_lead_description = fields.Boolean()
# Save into model fields
allowed_crm_lead_field_ids = fields.Many2many(
comodel_name="ir.model.fields",
compute="_compute_allowed_crm_lead_field_ids",
)
crm_lead_field = fields.Many2one(
comodel_name="ir.model.fields",
domain="[('id', 'in', allowed_crm_lead_field_ids)]",
)

@api.depends("question_type")
def _compute_allowed_crm_lead_field_ids(self):
type_mapping = {
"char_box": ["char", "text"],
"text_box": ["html", "text"],
"numerical_box": ["integer", "float", "html", "char"],
"date": ["date", "text", "char"],
"datetime": ["datetime", "html", "char"],
"simple_choice": ["html", "char"],
"multiple_choice": ["html", "char"],
}
for record in self:
record.allowed_crm_lead_field_ids = (
self.env["ir.model.fields"]
.search(
[
("model", "=", "crm.lead"),
("ttype", "in", type_mapping.get(record.question_type, [])),
]
)
.ids
)
21 changes: 21 additions & 0 deletions survey_crm_generation/models/survey_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ def _prepare_opportunity(self):
"contact_name": self.nickname,
}
)
# Fill sale.order fields from answers
elegible_inputs = self.user_input_line_ids.filtered(
lambda x: x.question_id.crm_lead_field and not x.skipped
)
basic_inputs = elegible_inputs.filtered(
lambda x: x.answer_type not in {"suggestion"}
)
vals.update(
{
line.question_id.crm_lead_field.name: line[f"value_{line.answer_type}"]
for line in basic_inputs
}
)
for line in elegible_inputs - basic_inputs:
field_name = line.question_id.crm_lead_field.name
value = (
line.suggested_answer_id.value
if line.answer_type == "suggestion"
else line[f"value_{line.answer_type}"]
)
vals[field_name] = value
return vals

def _prepare_lead_description(self):
Expand Down
3 changes: 3 additions & 0 deletions survey_crm_generation/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ To configure the leads/opportunities generation:
#. You can set the crm team to assign the leads to.

The questions marked to be shown in the lead description will be shown there.

If you want to fill crm.lead fields from the answers set the *CRM Lead field* you want
to fill with the given answer.
5 changes: 4 additions & 1 deletion survey_crm_generation/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Survey leads generation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d79e7bbad72ba02077da9a051eb24fff17d230a080af344ca6067f5492e3a544
!! source digest: sha256:289aff9f8141bd13d33db390ba910026796e8a0f3cce337d3776c85eb08f44c4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/survey/tree/15.0/survey_crm_generation"><img alt="OCA/survey" src="https://img.shields.io/badge/github-OCA%2Fsurvey-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/survey-15-0/survey-15-0-survey_crm_generation"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/survey&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to generate leads/opportunities from surveys.</p>
Expand Down Expand Up @@ -394,6 +395,8 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<li>You can set the crm team to assign the leads to.</li>
</ol>
<p>The questions marked to be shown in the lead description will be shown there.</p>
<p>If you want to fill crm.lead fields from the answers set the <em>CRM Lead field</em> you want
to fill with the given answer.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
Expand Down
11 changes: 11 additions & 0 deletions survey_crm_generation/static/tests/survey_crm_generation_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ odoo.define(
"div.js_question-wrapper:contains('And your name?') textarea",
run: "text Tecnativa",
},
{
content: "Referenced by",
trigger:
"div.js_question-wrapper:contains('Referenced by') span:contains('Other:')",
},
{
content: "Referenced by: other",
trigger:
"div.js_question-wrapper:contains('Referenced by') textarea",
run: "text Mr. Odoo",
},
{
content: "Click Submit",
trigger: "button[value='finish']",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ def test_lead_generation(self):
self.generated_lead.description,
expected_lead_description,
)
self.assertEqual("Mr. Odoo", self.generated_lead.referred)
2 changes: 2 additions & 0 deletions survey_crm_generation/views/survey_question_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
name="show_in_lead_description"
attrs="{'invisible': [('question_type', 'in', ['matrix', 'simple_choice', 'multiple_choice'])]}"
/>
<field name="allowed_crm_lead_field_ids" invisible="1" />
<field name="crm_lead_field" widget="selection" />
</group>
</xpath>
</field>
Expand Down

0 comments on commit 345d2c8

Please sign in to comment.