Skip to content

Commit

Permalink
Merge PR #110 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 Feb 9, 2024
2 parents badbde0 + d1b4c8e commit 2c00f13
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 3 deletions.
5 changes: 4 additions & 1 deletion survey_contact_generation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Survey contacts generation
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0a298d1600a5f93ffe77357631c7e799e78b23b84c362b126720e36655dd5227
!! source digest: sha256:686194b29ccec62259bb1806203d6bd3366d3768a224120d92d09b53e9588562
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -44,6 +44,9 @@ To configure the contact generation:
#. In the *Contact* section of the *Options* tab, set
*Generate Contact* on, if you want contacts to be
generated from the answers to this survey.
#. If you want the generated to have a parent company, set the option
*Create Parent Contact* and link the `company_name` field to a question in the
survey.
#. In each question associated with a future new contact,
specify the corresponding contact field. To do this,
go to the 'Options' tab, then navigate to the 'Contact' group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<field name="access_mode">public</field>
<field name="users_can_go_back" eval="True" />
<field name="generate_contact" eval="True" />
<field name="create_parent_contact" eval="True" />
</record>
<record model="survey.question" id="survey_contact_q_company_name">
<field name="survey_id" ref="survey_contact_creation" />
<field name="sequence">0</field>
<field name="title">Company name</field>
<field name="question_type">char_box</field>
<field name="constr_mandatory" eval="True" />
<field name="res_partner_field" ref="base.field_res_partner__company_name" />
</record>
<record model="survey.question" id="survey_contact_q0">
<field name="survey_id" ref="survey_contact_creation" />
Expand Down
4 changes: 4 additions & 0 deletions survey_contact_generation/models/survey_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ class SurveySurvey(models.Model):
generate_contact = fields.Boolean(
help="Generate contacts for anonymous survey users",
)
create_parent_contact = fields.Boolean(
help="Set the company_name in a question and a parent contact will be "
"created to hold the generated one",
)
15 changes: 14 additions & 1 deletion survey_contact_generation/models/survey_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _prepare_partner(self):
)
basic_inputs = elegible_inputs.filtered(
lambda x: x.answer_type not in {"suggestion"}
and x.question_id.res_partner_field.name != "comment"
and x.question_id.res_partner_field.name not in {"comment", "company_name"}
)
vals = {
line.question_id.res_partner_field.name: line[f"value_{line.answer_type}"]
Expand All @@ -40,6 +40,19 @@ def _prepare_partner(self):
else line[f"value_{line.answer_type}"]
)
vals["comment"] += f"\n{line.question_id.title}: {value}"
# Create the parent company
elif field_name == "company_name" and self.survey_id.create_parent_contact:
if line[f"value_{line.answer_type}"]:
vals["parent_id"] = (
self.env["res.partner"]
.create(
{
"name": line[f"value_{line.answer_type}"],
"company_type": "company",
}
)
.id
)
else:
if line.question_id.question_type == "multiple_choice":
if not vals.get(field_name):
Expand Down
3 changes: 3 additions & 0 deletions survey_contact_generation/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ To configure the contact generation:
#. In the *Contact* section of the *Options* tab, set
*Generate Contact* on, if you want contacts to be
generated from the answers to this survey.
#. If you want the generated to have a parent company, set the option
*Create Parent Contact* and link the `company_name` field to a question in the
survey.
#. In each question associated with a future new contact,
specify the corresponding contact field. To do this,
go to the 'Options' tab, then navigate to the 'Contact' group,
Expand Down
5 changes: 4 additions & 1 deletion survey_contact_generation/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Survey contacts generation</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0a298d1600a5f93ffe77357631c7e799e78b23b84c362b126720e36655dd5227
!! source digest: sha256:686194b29ccec62259bb1806203d6bd3366d3768a224120d92d09b53e9588562
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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_contact_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_contact_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 new contacts from surveys answers.</p>
Expand All @@ -393,6 +393,9 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<li>In the <em>Contact</em> section of the <em>Options</em> tab, set
<em>Generate Contact</em> on, if you want contacts to be
generated from the answers to this survey.</li>
<li>If you want the generated to have a parent company, set the option
<em>Create Parent Contact</em> and link the <cite>company_name</cite> field to a question in the
survey.</li>
<li>In each question associated with a future new contact,
specify the corresponding contact field. To do this,
go to the ‘Options’ tab, then navigate to the ‘Contact’ group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ odoo.define("survey.tour_test_survey_contact_generation", function (require) {
trigger: "div.js_question-wrapper:contains('Name') input",
run: "text My Name",
},
{
content: "Company Name",
trigger: "div.js_question-wrapper:contains('Company name') input",
run: "text My Company Name",
},
{
content: "Email",
trigger: "div.js_question-wrapper:contains('Email') input",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ def test_contact_generation(self):
[("email", "=", "[email protected]")]
)
self.assertEqual(partner, self.user_input.partner_id)
self.assertEqual(partner.parent_id.name, "My Company Name")
4 changes: 4 additions & 0 deletions survey_contact_generation/views/survey_survey_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<group name="options" position="inside">
<group name="contact_options" string="Contact">
<field name="generate_contact" />
<field
name="create_parent_contact"
attrs="{'invisible': [('generate_contact', '=', False)]}"
/>
</group>
</group>
</field>
Expand Down

0 comments on commit 2c00f13

Please sign in to comment.