-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] survey_next_survey_update_partner: new module
TT47575
- Loading branch information
1 parent
af94ce2
commit a5c0c9d
Showing
16 changed files
with
895 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/survey_next_survey_update_partner/odoo/addons/survey_next_survey_update_partner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../survey_next_survey_update_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
======================================= | ||
Update generated partner on next survey | ||
======================================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:dd735ba1b6b61947d30528044352b5df2553ca77a21cdf4c7c16a880b8b66f4e | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsurvey-lightgray.png?logo=github | ||
:target: https://github.com/OCA/survey/tree/15.0/survey_next_survey_update_partner | ||
:alt: OCA/survey | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/survey-15-0/survey-15-0-survey_next_survey_update_partner | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/survey&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module acts as a bridge of ``survey_contact_generation`` and | ||
``survey_answer_generation`` so when we link contact generation | ||
questions, the values that change in the next survey update those of the | ||
created partner. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Use Cases / Context | ||
=================== | ||
|
||
When we have contact generation linked answers it's expected that we | ||
update the values from the first survey. | ||
|
||
Usage | ||
===== | ||
|
||
Just configure the base modules. When the values in the second survey | ||
change, the generated contact will be updated. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/survey/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/survey/issues/new?body=module:%20survey_next_survey_update_partner%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
------------ | ||
|
||
- `Tecnativa <https://www.tecnativa.com>`__ | ||
|
||
- David Vidal | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-chienandalu| image:: https://github.com/chienandalu.png?size=40px | ||
:target: https://github.com/chienandalu | ||
:alt: chienandalu | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-chienandalu| | ||
|
||
This module is part of the `OCA/survey <https://github.com/OCA/survey/tree/15.0/survey_next_survey_update_partner>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Update generated partner on next survey", | ||
"summary": "Update the partner values when it's generated from the previous survey", | ||
"version": "15.0.1.0.0", | ||
"development_status": "Beta", | ||
"category": "Marketing/Survey", | ||
"website": "https://github.com/OCA/survey", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"maintainers": ["chienandalu"], | ||
"license": "AGPL-3", | ||
"depends": ["survey_contact_generation", "survey_answer_generation"], | ||
"data": [], | ||
"demo": ["demo/survey_update_generated_partner_demo.xml"], | ||
"assets": { | ||
"web.assets_tests": ["survey_next_survey_update_partner/static/tests/*.js"], | ||
}, | ||
} |
106 changes: 106 additions & 0 deletions
106
survey_next_survey_update_partner/demo/survey_update_generated_partner_demo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record model="survey.survey" id="survey_next_contact"> | ||
<field name="title">Next contact survey</field> | ||
<field name="access_token">nextcontact-survey-test-8e23-09e93f7fa2c5</field> | ||
<field name="access_mode">public</field> | ||
<field name="users_can_go_back" eval="True" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q_company_name"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<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_next_contact_q0"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">0</field> | ||
<field name="title">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__name" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q1"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">1</field> | ||
<field name="title">Email</field> | ||
<field name="question_type">char_box</field> | ||
<field name="res_partner_field" ref="base.field_res_partner__email" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q2"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">2</field> | ||
<field name="title">Notes</field> | ||
<field name="question_type">text_box</field> | ||
<field name="res_partner_field" ref="base.field_res_partner__comment" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q3"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">3</field> | ||
<field name="title">Color</field> | ||
<field name="question_type">numerical_box</field> | ||
<field name="res_partner_field" ref="base.field_res_partner__color" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q4"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">4</field> | ||
<field name="title">Date</field> | ||
<field name="question_type">date</field> | ||
<field name="res_partner_field" ref="base.field_res_partner__date" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q5"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">4</field> | ||
<field name="title">Country</field> | ||
<field name="question_type">simple_choice</field> | ||
<field name="res_partner_field" ref="base.field_res_partner__country_id" /> | ||
</record> | ||
<record model="survey.question.answer" id="survey_next_contact_q5_sug1"> | ||
<field name="question_id" ref="survey_next_contact_q5" /> | ||
<field name="sequence">1</field> | ||
<field name="value">Spain</field> | ||
<field name="res_partner_field_resource_ref" ref="base.es" /> | ||
</record> | ||
<record model="survey.question.answer" id="survey_next_contact_q5_sug2"> | ||
<field name="question_id" ref="survey_next_contact_q5" /> | ||
<field name="sequence">2</field> | ||
<field name="value">Romania</field> | ||
<field name="res_partner_field_resource_ref" ref="base.ro" /> | ||
</record> | ||
<record model="survey.question" id="survey_next_contact_q6"> | ||
<field name="survey_id" ref="survey_next_contact" /> | ||
<field name="sequence">4</field> | ||
<field name="title">Tags</field> | ||
<field name="question_type">multiple_choice</field> | ||
<field name="res_partner_field" ref="base.field_res_partner__category_id" /> | ||
</record> | ||
<record model="survey.question.answer" id="survey_next_contact_q6_sug1"> | ||
<field name="question_id" ref="survey_next_contact_q6" /> | ||
<field name="sequence">1</field> | ||
<field name="value">Vendor</field> | ||
<field | ||
name="res_partner_field_resource_ref" | ||
ref="base.res_partner_category_0" | ||
/> | ||
</record> | ||
<record model="survey.question.answer" id="survey_next_contact_q6_sug2"> | ||
<field name="question_id" ref="survey_next_contact_q6" /> | ||
<field name="sequence">2</field> | ||
<field name="value">Prospects</field> | ||
<field | ||
name="res_partner_field_resource_ref" | ||
ref="base.res_partner_category_2" | ||
/> | ||
</record> | ||
<record model="survey.question.answer" id="survey_next_contact_q6_sug3"> | ||
<field name="question_id" ref="survey_next_contact_q6" /> | ||
<field name="sequence">3</field> | ||
<field name="value">Employees</field> | ||
<field | ||
name="res_partner_field_resource_ref" | ||
ref="base.res_partner_category_3" | ||
/> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import survey_user_input |
74 changes: 74 additions & 0 deletions
74
survey_next_survey_update_partner/models/survey_user_input.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2024 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import _, models | ||
|
||
|
||
class SurveyUserInput(models.Model): | ||
_inherit = "survey.user_input" | ||
|
||
def _prepare_generated_partner_update(self, lines): | ||
basic_inputs = lines.filtered( | ||
lambda x: x.answer_type not in {"suggestion"} | ||
and x.question_id.res_partner_field.name not in {"comment"} | ||
) | ||
vals = { | ||
line.question_id.res_partner_field.name: line[f"value_{line.answer_type}"] | ||
for line in basic_inputs | ||
} | ||
for line in lines - basic_inputs: | ||
field_name = line.question_id.res_partner_field.name | ||
if line.question_id.res_partner_field.ttype == "many2one": | ||
vals[ | ||
field_name | ||
] = line.suggested_answer_id.res_partner_field_resource_ref.id | ||
elif line.question_id.res_partner_field.ttype == "many2many": | ||
vals.setdefault(field_name, []) | ||
vals[field_name] += [ | ||
(4, line.suggested_answer_id.res_partner_field_resource_ref.id) | ||
] | ||
# We'll use the comment field to add any other infos | ||
elif field_name == "comment": | ||
vals.setdefault("comment", "") | ||
value = ( | ||
line.suggested_answer_id.value | ||
if line.answer_type == "suggestion" | ||
else line[f"value_{line.answer_type}"] | ||
) | ||
vals["comment"] += f"\n{line.question_id.title}: {value}" | ||
else: | ||
if line.question_id.question_type == "multiple_choice": | ||
if not vals.get(field_name): | ||
vals[field_name] = line.suggested_answer_id.value | ||
else: | ||
vals[field_name] += line.suggested_answer_id.value | ||
else: | ||
vals[field_name] = line.suggested_answer_id.value | ||
return vals | ||
|
||
def _mark_done(self): | ||
"""Update the contact in the previous survey if any""" | ||
for user_input in self.filtered( | ||
lambda x: x.origin_input_id | ||
and x.partner_id.generating_survey_user_input_id == x.origin_input_id | ||
): | ||
lines = user_input.user_input_line_ids.filtered( | ||
lambda x: not x.skipped | ||
and x.diff_with_origin | ||
and x.origin_input_line.question_id.res_partner_field | ||
) | ||
vals = self._prepare_generated_partner_update(lines) | ||
comment = vals.pop("comment", None) | ||
company_name = vals.pop("company_name", None) | ||
user_input.partner_id.update(self._prepare_generated_partner_update(lines)) | ||
if comment: | ||
user_input.partner_id.comment += _( | ||
"\nUpdated comment\n %(comment)", comment=comment | ||
) | ||
if ( | ||
company_name | ||
and user_input.origin_input_id.survey_id.create_parent_contact | ||
): | ||
user_input.partner_id.parent_id.name = company_name | ||
elif company_name: | ||
user_input.partner_id.company_name = company_name | ||
return super()._mark_done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
When we have contact generation linked answers it's expected that we update the values | ||
from the first survey. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- [Tecnativa](https://www.tecnativa.com) | ||
- David Vidal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module acts as a bridge of `survey_contact_generation` and `survey_answer_generation` so | ||
when we link contact generation questions, the values that change in the next survey update | ||
those of the created partner. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Just configure the base modules. When the values in the second survey change, the generated | ||
contact will be updated. |
Oops, something went wrong.