Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD] survey_next_survey_update_partner: new module #115

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/survey_next_survey_update_partner/setup.py
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,
)
104 changes: 104 additions & 0 deletions survey_next_survey_update_partner/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
=======================================
Update generated partner on next survey
=======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c757503b3f3fa45d083a35116eb3c54212a1dd004e50408d5df6af3bcde76549
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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.

We can also add new info to the survey, so the partner gets updated with
it as well.

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.
1 change: 1 addition & 0 deletions survey_next_survey_update_partner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions survey_next_survey_update_partner/__manifest__.py
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"],
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?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>
<record model="survey.question" id="survey_next_contact_q7">
<field name="survey_id" ref="survey_next_contact" />
<field name="sequence">5</field>
<field name="title">Street</field>
<field name="question_type">char_box</field>
<field name="res_partner_field" ref="base.field_res_partner__street" />
</record>
</odoo>
1 change: 1 addition & 0 deletions survey_next_survey_update_partner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import survey_user_input
82 changes: 82 additions & 0 deletions survey_next_survey_update_partner/models/survey_user_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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 (
# Answered in the previous survey and with partner field
(
x.diff_with_origin
and x.origin_input_line.question_id.res_partner_field
and x.question_id.res_partner_field
)
# Not in previous but with partner field
or (not x.origin_input_line and x.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)s", 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()
2 changes: 2 additions & 0 deletions survey_next_survey_update_partner/readme/CONTEXT.md
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.
2 changes: 2 additions & 0 deletions survey_next_survey_update_partner/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Tecnativa](https://www.tecnativa.com)
- David Vidal
3 changes: 3 additions & 0 deletions survey_next_survey_update_partner/readme/DESCRIPTION.md
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.
4 changes: 4 additions & 0 deletions survey_next_survey_update_partner/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Just configure the base modules. When the values in the second survey change, the generated
contact will be updated.

We can also add new info to the survey, so the partner gets updated with it as well.
Loading
Loading