From a5c0c9d45be64890d93b2599bfbee9afe9396b5d Mon Sep 17 00:00:00 2001 From: David Date: Mon, 26 Feb 2024 13:17:13 +0100 Subject: [PATCH] [ADD] survey_next_survey_update_partner: new module TT47575 --- .../addons/survey_next_survey_update_partner | 1 + .../setup.py | 6 + survey_next_survey_update_partner/README.rst | 101 ++++ survey_next_survey_update_partner/__init__.py | 1 + .../__manifest__.py | 19 + .../survey_update_generated_partner_demo.xml | 106 +++++ .../models/__init__.py | 1 + .../models/survey_user_input.py | 74 +++ .../readme/CONTEXT.md | 2 + .../readme/CONTRIBUTORS.md | 2 + .../readme/DESCRIPTION.md | 3 + .../readme/USAGE.md | 2 + .../static/description/index.html | 441 ++++++++++++++++++ .../tests/survey_contact_update_tour.esm.js | 83 ++++ .../tests/__init__.py | 1 + .../tests/test_next_survey_update_partner.py | 52 +++ 16 files changed, 895 insertions(+) create mode 120000 setup/survey_next_survey_update_partner/odoo/addons/survey_next_survey_update_partner create mode 100644 setup/survey_next_survey_update_partner/setup.py create mode 100644 survey_next_survey_update_partner/README.rst create mode 100644 survey_next_survey_update_partner/__init__.py create mode 100644 survey_next_survey_update_partner/__manifest__.py create mode 100644 survey_next_survey_update_partner/demo/survey_update_generated_partner_demo.xml create mode 100644 survey_next_survey_update_partner/models/__init__.py create mode 100644 survey_next_survey_update_partner/models/survey_user_input.py create mode 100644 survey_next_survey_update_partner/readme/CONTEXT.md create mode 100644 survey_next_survey_update_partner/readme/CONTRIBUTORS.md create mode 100644 survey_next_survey_update_partner/readme/DESCRIPTION.md create mode 100644 survey_next_survey_update_partner/readme/USAGE.md create mode 100644 survey_next_survey_update_partner/static/description/index.html create mode 100644 survey_next_survey_update_partner/static/tests/survey_contact_update_tour.esm.js create mode 100644 survey_next_survey_update_partner/tests/__init__.py create mode 100644 survey_next_survey_update_partner/tests/test_next_survey_update_partner.py diff --git a/setup/survey_next_survey_update_partner/odoo/addons/survey_next_survey_update_partner b/setup/survey_next_survey_update_partner/odoo/addons/survey_next_survey_update_partner new file mode 120000 index 00000000..bd15d4bc --- /dev/null +++ b/setup/survey_next_survey_update_partner/odoo/addons/survey_next_survey_update_partner @@ -0,0 +1 @@ +../../../../survey_next_survey_update_partner \ No newline at end of file diff --git a/setup/survey_next_survey_update_partner/setup.py b/setup/survey_next_survey_update_partner/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/survey_next_survey_update_partner/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/survey_next_survey_update_partner/README.rst b/survey_next_survey_update_partner/README.rst new file mode 100644 index 00000000..db7bd6e5 --- /dev/null +++ b/survey_next_survey_update_partner/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - 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 `__: + +|maintainer-chienandalu| + +This module is part of the `OCA/survey `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/survey_next_survey_update_partner/__init__.py b/survey_next_survey_update_partner/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/survey_next_survey_update_partner/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/survey_next_survey_update_partner/__manifest__.py b/survey_next_survey_update_partner/__manifest__.py new file mode 100644 index 00000000..f6df856c --- /dev/null +++ b/survey_next_survey_update_partner/__manifest__.py @@ -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"], + }, +} diff --git a/survey_next_survey_update_partner/demo/survey_update_generated_partner_demo.xml b/survey_next_survey_update_partner/demo/survey_update_generated_partner_demo.xml new file mode 100644 index 00000000..b2492c6c --- /dev/null +++ b/survey_next_survey_update_partner/demo/survey_update_generated_partner_demo.xml @@ -0,0 +1,106 @@ + + + + Next contact survey + nextcontact-survey-test-8e23-09e93f7fa2c5 + public + + + + + 0 + Company name + char_box + + + + + + 0 + Name + char_box + + + + + + 1 + Email + char_box + + + + + 2 + Notes + text_box + + + + + 3 + Color + numerical_box + + + + + 4 + Date + date + + + + + 4 + Country + simple_choice + + + + + 1 + Spain + + + + + 2 + Romania + + + + + 4 + Tags + multiple_choice + + + + + 1 + Vendor + + + + + 2 + Prospects + + + + + 3 + Employees + + + diff --git a/survey_next_survey_update_partner/models/__init__.py b/survey_next_survey_update_partner/models/__init__.py new file mode 100644 index 00000000..56623b54 --- /dev/null +++ b/survey_next_survey_update_partner/models/__init__.py @@ -0,0 +1 @@ +from . import survey_user_input diff --git a/survey_next_survey_update_partner/models/survey_user_input.py b/survey_next_survey_update_partner/models/survey_user_input.py new file mode 100644 index 00000000..e63597ca --- /dev/null +++ b/survey_next_survey_update_partner/models/survey_user_input.py @@ -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() diff --git a/survey_next_survey_update_partner/readme/CONTEXT.md b/survey_next_survey_update_partner/readme/CONTEXT.md new file mode 100644 index 00000000..8debb5c8 --- /dev/null +++ b/survey_next_survey_update_partner/readme/CONTEXT.md @@ -0,0 +1,2 @@ +When we have contact generation linked answers it's expected that we update the values +from the first survey. diff --git a/survey_next_survey_update_partner/readme/CONTRIBUTORS.md b/survey_next_survey_update_partner/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..320d387d --- /dev/null +++ b/survey_next_survey_update_partner/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Tecnativa](https://www.tecnativa.com) + - David Vidal diff --git a/survey_next_survey_update_partner/readme/DESCRIPTION.md b/survey_next_survey_update_partner/readme/DESCRIPTION.md new file mode 100644 index 00000000..8400006e --- /dev/null +++ b/survey_next_survey_update_partner/readme/DESCRIPTION.md @@ -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. diff --git a/survey_next_survey_update_partner/readme/USAGE.md b/survey_next_survey_update_partner/readme/USAGE.md new file mode 100644 index 00000000..6977a3d9 --- /dev/null +++ b/survey_next_survey_update_partner/readme/USAGE.md @@ -0,0 +1,2 @@ +Just configure the base modules. When the values in the second survey change, the generated +contact will be updated. diff --git a/survey_next_survey_update_partner/static/description/index.html b/survey_next_survey_update_partner/static/description/index.html new file mode 100644 index 00000000..dead2e5b --- /dev/null +++ b/survey_next_survey_update_partner/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Update generated partner on next survey + + + +
+

Update generated partner on next survey

+ + +

Beta License: AGPL-3 OCA/survey Translate me on Weblate Try me on Runboat

+

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

+ +
+

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

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

chienandalu

+

This module is part of the OCA/survey project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/survey_next_survey_update_partner/static/tests/survey_contact_update_tour.esm.js b/survey_next_survey_update_partner/static/tests/survey_contact_update_tour.esm.js new file mode 100644 index 00000000..9cd01d52 --- /dev/null +++ b/survey_next_survey_update_partner/static/tests/survey_contact_update_tour.esm.js @@ -0,0 +1,83 @@ +/** @odoo-module */ +import tour from "web_tour.tour"; + +tour.register( + "test_survey_contact_update", + { + test: true, + }, + [ + { + content: "Click on Start", + trigger: "button.btn:contains('Start Survey')", + }, + { + content: "Name", + trigger: "div.js_question-wrapper:contains('Name') input", + run: "text My Updated Name", + }, + { + content: "Company Name", + trigger: "div.js_question-wrapper:contains('Company name') input", + run: "text My Updated Company Name", + }, + { + content: "Email", + trigger: "div.js_question-wrapper:contains('Email') input", + run: "text survey_contact_generation@test.com", + }, + { + content: "Notes", + trigger: "div.js_question-wrapper:contains('Notes') textarea", + run: "text This is a test note", + }, + { + content: "Color", + trigger: "div.js_question-wrapper:contains('Color') input", + run: "text 1", + }, + { + content: "Date", + trigger: "div.js_question-wrapper:contains('Date') input", + run: "text 01/01/2023", + }, + { + content: "Country", + trigger: + "div.js_question-wrapper:contains('Country') label:contains('Romania') i", + run: function () { + $( + "div.js_question-wrapper:contains('Country') label:contains('Romania') i" + ).prop("checked", true); + }, + }, + { + content: "Tags", + trigger: + "div.js_question-wrapper:contains('Tags') label:contains('Prospects') i", + run: function () { + $( + "div.js_question-wrapper:contains('Tags') label:contains('Prospects') i" + ).prop("checked", true); + }, + }, + { + content: "Tags", + trigger: + "div.js_question-wrapper:contains('Tags') label:contains('Vendor') i", + run: function () { + $( + "div.js_question-wrapper:contains('Tags') label:contains('Vendor') i" + ).prop("checked", true); + }, + }, + { + content: "Click Submit", + trigger: "button[value='finish']", + }, + { + content: "Thank you", + trigger: "h1:contains('Thank you!')", + }, + ] +); diff --git a/survey_next_survey_update_partner/tests/__init__.py b/survey_next_survey_update_partner/tests/__init__.py new file mode 100644 index 00000000..eb9f72e6 --- /dev/null +++ b/survey_next_survey_update_partner/tests/__init__.py @@ -0,0 +1 @@ +from . import test_next_survey_update_partner diff --git a/survey_next_survey_update_partner/tests/test_next_survey_update_partner.py b/survey_next_survey_update_partner/tests/test_next_survey_update_partner.py new file mode 100644 index 00000000..27dfb7af --- /dev/null +++ b/survey_next_survey_update_partner/tests/test_next_survey_update_partner.py @@ -0,0 +1,52 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import HttpCase, tagged + +from odoo.addons.survey.tests.common import SurveyCase + + +@tagged("-at_install", "post_install") +class SurveyContactGenerationCase(SurveyCase, HttpCase): + def setUp(self): + """We run the tour in the setup so we can share the tests case with other + modules""" + super().setUp() + self.origin_survey = self.env.ref( + "survey_contact_generation.survey_contact_creation" + ) + self.next_survey = self.env.ref( + "survey_next_survey_update_partner.survey_next_contact" + ) + self.existing_inputs = self.origin_survey.user_input_ids + # Let's links several questions + self.origin_survey.next_survey_id = self.next_survey + self.env.ref( + "survey_contact_generation.survey_contact_q0" + ).next_survey_question_id = self.env.ref( + "survey_next_survey_update_partner.survey_next_contact_q0" + ) + self.env.ref( + "survey_contact_generation.survey_contact_q_company_name" + ).next_survey_question_id = self.env.ref( + "survey_next_survey_update_partner.survey_next_contact_q_company_name" + ) + + def test_contact_generation(self): + # Generate the contact first + self.start_tour( + f"/survey/start/{self.origin_survey.access_token}", + "test_survey_contact_generation", + ) + new_input = self.origin_survey.user_input_ids - self.existing_inputs + partner = self.env["res.partner"].search( + [("email", "=", "survey_contact_generation@test.com")] + ) + self.assertEqual(partner.name, "My Name") + self.assertEqual(partner.parent_id.name, "My Company Name") + next_answer = new_input.next_survey_input_id + self.start_tour( + f"/survey/{self.next_survey.access_token}/{next_answer.access_token}", + "test_survey_contact_update", + ) + self.assertEqual(partner.name, "My Updated Name") + self.assertEqual(partner.parent_id.name, "My Updated Company Name")