diff --git a/survey_contact_generation/README.rst b/survey_contact_generation/README.rst new file mode 100644 index 00000000..127381bf --- /dev/null +++ b/survey_contact_generation/README.rst @@ -0,0 +1,148 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================== +Survey contacts generation +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1cc82509977655cfc45ab7ead533ec21a2b39cc308129b35a4ad8b84cbd07891 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/survey_contact_generation + :alt: OCA/survey +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/survey-19-0/survey-19-0-survey_contact_generation + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to generate new contacts from surveys answers. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure the contact generation: + +1. Go to the configured survey. +2. 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. +3. 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. +4. 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, and select the 'Contact field' + field. + +To generate a hierarchy of contacts out of a single survey: + +1. A question mapped to the *Name* contact field opens a contact of its + own. Any other question fills in a field of the contact opened by its + *Node*. +2. In such a question, set *Node* to the question opening the contact it + hangs from. Leave it empty and its answers will belong to the main + generated contact. +3. Contacts typed as *Contact* share their address with their parent, so + set *Contact address type* to *Other address* in the questions + opening a contact that holds an address of its own. + +For instance, this survey generates a company, two of its workcenters +with their own address, and an employee hanging from each workcenter: + +===================== ============= ============ ============= +Question Contact field Node Address type +===================== ============= ============ ============= +Company name name +Workcenter 1 name Company name Other address +Workcenter 1 street street Workcenter 1 +Workcenter 1 employee name Workcenter 1 +Workcenter 2 name Company name Other address +Workcenter 2 street street Workcenter 2 +Workcenter 2 employee name Workcenter 2 +===================== ============= ============ ============= + +A node whose name goes unanswered generates no contact, and whatever +hangs from it hangs from its own node instead. + +Usage +===== + +if the survey is properly configured, once it is submited by an +anonomous user, a new contact is create or an existing one is linked. + +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 + - Ernesto Tejeda + - Stefan Ungureanu + - Pilar Vargas + - Eduardo Ezerouali + - Adasat Torres + +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-pilarvargas-tecnativa| image:: https://github.com/pilarvargas-tecnativa.png?size=40px + :target: https://github.com/pilarvargas-tecnativa + :alt: pilarvargas-tecnativa + +Current `maintainer `__: + +|maintainer-pilarvargas-tecnativa| + +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_contact_generation/__init__.py b/survey_contact_generation/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/survey_contact_generation/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/survey_contact_generation/__manifest__.py b/survey_contact_generation/__manifest__.py new file mode 100644 index 00000000..aee473cc --- /dev/null +++ b/survey_contact_generation/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2023 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Survey contacts generation", + "summary": "Generate new contacts from surveys", + "version": "19.0.1.0.0", + "development_status": "Beta", + "category": "Marketing/Survey", + "website": "https://github.com/OCA/survey", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["pilarvargas-tecnativa"], + "license": "AGPL-3", + "depends": ["survey"], + "data": [ + "views/survey_question_views.xml", + "views/survey_survey_views.xml", + ], + "demo": [ + "demo/survey_contact_generation_demo.xml", + "demo/survey_contact_nesting_demo.xml", + ], + "assets": { + "web.assets_tests": [ + "/survey_contact_generation/static/tests/survey_contact_generation_tour.esm.js", + ], + }, +} diff --git a/survey_contact_generation/demo/survey_contact_generation_demo.xml b/survey_contact_generation/demo/survey_contact_generation_demo.xml new file mode 100644 index 00000000..34c73394 --- /dev/null +++ b/survey_contact_generation/demo/survey_contact_generation_demo.xml @@ -0,0 +1,101 @@ + + + + + Contact Creation Survey + public + + + + + + + 0 + Company name + char_box + + + + + + 0 + Name + char_box + + + + + + 1 + Email + char_box + + + + + 2 + Notes + text_box + + + + + 3 + Color + numerical_box + + + + + 4 + Country + simple_choice + + + + + 1 + Spain + + + + + 2 + Romania + + + + + 4 + Tags + multiple_choice + + + + + 1 + Vendor + + + + + 2 + Prospects + + + + + 3 + Employees + + + diff --git a/survey_contact_generation/demo/survey_contact_nesting_demo.xml b/survey_contact_generation/demo/survey_contact_nesting_demo.xml new file mode 100644 index 00000000..e65a980b --- /dev/null +++ b/survey_contact_generation/demo/survey_contact_nesting_demo.xml @@ -0,0 +1,86 @@ + + + + + Nested Contact Creation Survey + 6c1b2f84-9a3d-4e77-b0c2-1d5e8a4f7c93 + public + + + + + + 0 + Company name + char_box + + + + + + + 1 + Workcenter 1 + char_box + + + other + + + + 2 + Workcenter 1 street + char_box + + + + + + 3 + Workcenter 1 employee + char_box + + + + + + 4 + Workcenter 1 employee email + char_box + + + + + + + 5 + Workcenter 2 + char_box + + + other + + + + 6 + Workcenter 2 street + char_box + + + + + + 7 + Workcenter 2 employee + char_box + + + + diff --git a/survey_contact_generation/i18n/es.po b/survey_contact_generation/i18n/es.po new file mode 100644 index 00000000..59a1ea29 --- /dev/null +++ b/survey_contact_generation/i18n/es.po @@ -0,0 +1,243 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_contact_generation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-06-14 11:55+0000\n" +"PO-Revision-Date: 2023-11-11 18:37+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_question__res_partner_type +msgid "" +"Address type of the contact this question opens. Contacts share their " +"address with their parent, so a node holding an address of its own needs a " +"different type." +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__allowed_partner_field_domain +msgid "Allowed Partner Field Domain" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q3 +msgid "Color" +msgstr "Color" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q_company_name +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_company +msgid "Company name" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_res_partner +#: model_terms:ir.ui.view,arch_db:survey_contact_generation.survey_form +#: model_terms:ir.ui.view,arch_db:survey_contact_generation.survey_question_form +msgid "Contact" +msgstr "Contacto" + +#. module: survey_contact_generation +#: model:survey.survey,title:survey_contact_generation.survey_contact_creation +msgid "Contact Creation Survey" +msgstr "Encuesta de creación de contactos" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_type +msgid "Contact address type" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_field +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question_answer__res_partner_field +msgid "Contact field" +msgstr "Campo de contacto" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question_answer__res_partner_field_resource_ref +msgid "Contact field value" +msgstr "Valor del campo Contacto" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q5 +msgid "Country" +msgstr "País" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_survey__create_parent_contact +msgid "Create Parent Contact" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q4 +msgid "Date" +msgstr "Fecha" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q1 +msgid "Email" +msgstr "Correo electrónico" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug3 +msgid "Employees" +msgstr "Empleados" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_field_name +msgid "Field Name" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_survey__generate_contact +msgid "Generate Contact" +msgstr "Generar contacto" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_survey__generate_contact +msgid "Generate contacts for anonymous survey users" +msgstr "Generar contacto para encuestas anónimas" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_res_partner__generating_survey_user_input_id +#: model:ir.model.fields,field_description:survey_contact_generation.field_res_users__generating_survey_user_input_id +msgid "Generating Survey User Input" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q0 +msgid "Name" +msgstr "Nombre" + +#. module: survey_contact_generation +#: model:survey.survey,title:survey_contact_generation.survey_contact_nesting +msgid "Nested Contact Creation Survey" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__survey_question_node_id +msgid "Node" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q2 +msgid "Notes" +msgstr "Notas" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug2 +msgid "Prospects" +msgstr "Perspectivas" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_question__survey_question_node_id +msgid "" +"Question opening the contact this one relates to. A question mapped to the " +"name opens a contact of its own, and hangs it from the contact of this node. " +"Any other question fills in a field of the contact this node opened." +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug2 +msgid "Romania" +msgstr "Rumanía" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_survey__create_parent_contact +msgid "" +"Set the company_name in a question and a parent contact will be created to " +"hold the generated one" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug1 +msgid "Spain" +msgstr "España" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_survey +msgid "Survey" +msgstr "Planificación" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_question_answer +msgid "Survey Label" +msgstr "Etiqueta de Encuesta" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_question +msgid "Survey Question" +msgstr "Pregunta de la encuesta" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_user_input +msgid "Survey User Input" +msgstr "Entrada de usuario de la encuesta" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q6 +msgid "Tags" +msgstr "Etiquetas" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug1 +msgid "Vendor" +msgstr "Vendedor" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_1 +msgid "Workcenter 1" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_1 +msgid "Workcenter 1 employee" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_1_email +msgid "Workcenter 1 employee email" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_1_street +msgid "Workcenter 1 street" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_2 +msgid "Workcenter 2" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_2 +msgid "Workcenter 2 employee" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_2_street +msgid "Workcenter 2 street" +msgstr "" + +#~ msgid "Allowed Field" +#~ msgstr "Campo permitido" + +#~ msgid "If other, please specify:" +#~ msgstr "Si es otro, especifíquelo:" + +#~ msgid "The answer you entered is not valid." +#~ msgstr "La respuesta que has introducido no es válida." + +#~ msgid "This question requires an answer." +#~ msgstr "Esta pregunta requiere una respuesta." diff --git a/survey_contact_generation/i18n/it.po b/survey_contact_generation/i18n/it.po new file mode 100644 index 00000000..fef1e1d2 --- /dev/null +++ b/survey_contact_generation/i18n/it.po @@ -0,0 +1,244 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_contact_generation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-11-11 12:42+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_question__res_partner_type +msgid "" +"Address type of the contact this question opens. Contacts share their " +"address with their parent, so a node holding an address of its own needs a " +"different type." +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__allowed_partner_field_domain +msgid "Allowed Partner Field Domain" +msgstr "Dominio campo partner consentito" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q3 +msgid "Color" +msgstr "Colore" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q_company_name +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_company +msgid "Company name" +msgstr "Nome azienda" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_res_partner +#: model_terms:ir.ui.view,arch_db:survey_contact_generation.survey_form +#: model_terms:ir.ui.view,arch_db:survey_contact_generation.survey_question_form +msgid "Contact" +msgstr "Contatto" + +#. module: survey_contact_generation +#: model:survey.survey,title:survey_contact_generation.survey_contact_creation +msgid "Contact Creation Survey" +msgstr "Sondaggio creazione contatto" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_type +msgid "Contact address type" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_field +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question_answer__res_partner_field +msgid "Contact field" +msgstr "Campo contatto" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question_answer__res_partner_field_resource_ref +msgid "Contact field value" +msgstr "Valore campo contatto" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q5 +msgid "Country" +msgstr "Nazione" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_survey__create_parent_contact +msgid "Create Parent Contact" +msgstr "Crea contatto partner" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q4 +msgid "Date" +msgstr "Data" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q1 +msgid "Email" +msgstr "E-mail" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug3 +msgid "Employees" +msgstr "Dipendenti" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_field_name +msgid "Field Name" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_survey__generate_contact +msgid "Generate Contact" +msgstr "Genera contatto" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_survey__generate_contact +msgid "Generate contacts for anonymous survey users" +msgstr "Genera contatti per utenti sondaggio anonimo" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_res_partner__generating_survey_user_input_id +#: model:ir.model.fields,field_description:survey_contact_generation.field_res_users__generating_survey_user_input_id +msgid "Generating Survey User Input" +msgstr "Generazione risposte utente sondaggio" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q0 +msgid "Name" +msgstr "Nome" + +#. module: survey_contact_generation +#: model:survey.survey,title:survey_contact_generation.survey_contact_nesting +msgid "Nested Contact Creation Survey" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__survey_question_node_id +msgid "Node" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q2 +msgid "Notes" +msgstr "Note" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug2 +msgid "Prospects" +msgstr "Prospettive" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_question__survey_question_node_id +msgid "" +"Question opening the contact this one relates to. A question mapped to the " +"name opens a contact of its own, and hangs it from the contact of this node. " +"Any other question fills in a field of the contact this node opened." +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug2 +msgid "Romania" +msgstr "Romania" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_survey__create_parent_contact +msgid "" +"Set the company_name in a question and a parent contact will be created to " +"hold the generated one" +msgstr "" +"Impostare il company_name in una richiesta e verrà creato il contatto " +"partner per gestirla" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug1 +msgid "Spain" +msgstr "Spagna" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_survey +msgid "Survey" +msgstr "Sondaggio" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_question_answer +msgid "Survey Label" +msgstr "Etichetta sondaggio" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_question +msgid "Survey Question" +msgstr "Domanda sondaggio" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_user_input +msgid "Survey User Input" +msgstr "Risposta utente al sondaggio" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q6 +msgid "Tags" +msgstr "Etichette" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug1 +msgid "Vendor" +msgstr "Fornitore" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_1 +msgid "Workcenter 1" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_1 +msgid "Workcenter 1 employee" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_1_email +msgid "Workcenter 1 employee email" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_1_street +msgid "Workcenter 1 street" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_2 +msgid "Workcenter 2" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_2 +msgid "Workcenter 2 employee" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_2_street +msgid "Workcenter 2 street" +msgstr "" + +#~ msgid "Allowed Field" +#~ msgstr "Campi permessi" + +#~ msgid "If other, please specify:" +#~ msgstr "Se altro, specificare:" + +#~ msgid "The answer you entered is not valid." +#~ msgstr "La risposta data non è valida." + +#~ msgid "This question requires an answer." +#~ msgstr "Questa domanda richiede una risposta." diff --git a/survey_contact_generation/i18n/survey_contact_generation.pot b/survey_contact_generation/i18n/survey_contact_generation.pot new file mode 100644 index 00000000..d664d5da --- /dev/null +++ b/survey_contact_generation/i18n/survey_contact_generation.pot @@ -0,0 +1,227 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_contact_generation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_question__res_partner_type +msgid "" +"Address type of the contact this question opens. Contacts share their " +"address with their parent, so a node holding an address of its own needs a " +"different type." +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__allowed_partner_field_domain +msgid "Allowed Partner Field Domain" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q3 +msgid "Color" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q_company_name +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_company +msgid "Company name" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_res_partner +#: model_terms:ir.ui.view,arch_db:survey_contact_generation.survey_form +#: model_terms:ir.ui.view,arch_db:survey_contact_generation.survey_question_form +msgid "Contact" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.survey,title:survey_contact_generation.survey_contact_creation +msgid "Contact Creation Survey" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_type +msgid "Contact address type" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_field +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question_answer__res_partner_field +msgid "Contact field" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question_answer__res_partner_field_resource_ref +msgid "Contact field value" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q5 +msgid "Country" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_survey__create_parent_contact +msgid "Create Parent Contact" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q4 +msgid "Date" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q1 +msgid "Email" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug3 +msgid "Employees" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__res_partner_field_name +msgid "Field Name" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_survey__generate_contact +msgid "Generate Contact" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_survey__generate_contact +msgid "Generate contacts for anonymous survey users" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_res_partner__generating_survey_user_input_id +#: model:ir.model.fields,field_description:survey_contact_generation.field_res_users__generating_survey_user_input_id +msgid "Generating Survey User Input" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q0 +msgid "Name" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.survey,title:survey_contact_generation.survey_contact_nesting +msgid "Nested Contact Creation Survey" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__survey_question_node_id +msgid "Node" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q2 +msgid "Notes" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug2 +msgid "Prospects" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_question__survey_question_node_id +msgid "" +"Question opening the contact this one relates to. A question mapped to the " +"name opens a contact of its own, and hangs it from the contact of this node." +" Any other question fills in a field of the contact this node opened." +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug2 +msgid "Romania" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model.fields,help:survey_contact_generation.field_survey_survey__create_parent_contact +msgid "" +"Set the company_name in a question and a parent contact will be created to " +"hold the generated one" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug1 +msgid "Spain" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_survey +msgid "Survey" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_question_answer +msgid "Survey Label" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_question +msgid "Survey Question" +msgstr "" + +#. module: survey_contact_generation +#: model:ir.model,name:survey_contact_generation.model_survey_user_input +msgid "Survey User Input" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q6 +msgid "Tags" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug1 +msgid "Vendor" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_1 +msgid "Workcenter 1" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_1 +msgid "Workcenter 1 employee" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_1_email +msgid "Workcenter 1 employee email" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_1_street +msgid "Workcenter 1 street" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_2 +msgid "Workcenter 2" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_employee_2 +msgid "Workcenter 2 employee" +msgstr "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_nesting_q_workcenter_2_street +msgid "Workcenter 2 street" +msgstr "" diff --git a/survey_contact_generation/models/__init__.py b/survey_contact_generation/models/__init__.py new file mode 100644 index 00000000..c9d60b7a --- /dev/null +++ b/survey_contact_generation/models/__init__.py @@ -0,0 +1,4 @@ +from . import res_partner +from . import survey_question +from . import survey_survey +from . import survey_user_input diff --git a/survey_contact_generation/models/res_partner.py b/survey_contact_generation/models/res_partner.py new file mode 100644 index 00000000..d6731a5a --- /dev/null +++ b/survey_contact_generation/models/res_partner.py @@ -0,0 +1,11 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + generating_survey_user_input_id = fields.Many2one( + comodel_name="survey.user_input", copy=False, readonly=True + ) diff --git a/survey_contact_generation/models/survey_question.py b/survey_contact_generation/models/survey_question.py new file mode 100644 index 00000000..9abcd638 --- /dev/null +++ b/survey_contact_generation/models/survey_question.py @@ -0,0 +1,95 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class SurveyQuestion(models.Model): + _inherit = "survey.question" + + allowed_partner_field_domain = fields.Binary( + compute="_compute_allowed_partner_field_domain", + ) + res_partner_field = fields.Many2one( + string="Contact field", + comodel_name="ir.model.fields", + ) + survey_question_node_id = fields.Many2one( + comodel_name="survey.question", + string="Node", + help="Question opening the contact this one relates to. A question " + "mapped to the name opens a contact of its own, and hangs it from the " + "contact of this node. Any other question fills in a field of the " + "contact this node opened.", + ) + # A many2one is just an id in the view, so we expose its name as a field + # to be able to use it in view modifiers + res_partner_field_name = fields.Char(related="res_partner_field.name") + res_partner_type = fields.Selection( + selection=lambda self: self.env["res.partner"] + ._fields["type"] + ._description_selection(self.env), + string="Contact address type", + help="Address type of the contact this question opens. Contacts share " + "their address with their parent, so a node holding an address of its " + "own needs a different type.", + ) + + @api.depends("question_type") + def _compute_allowed_partner_field_domain(self): + type_mapping = { + "char_box": ["char", "text"], + "text_box": ["html"], + "numerical_box": ["integer", "float", "html", "char"], + "date": ["date", "text", "char"], + "datetime": ["datetime", "html", "char"], + "simple_choice": ["many2one", "html", "char"], + "multiple_choice": ["many2many", "html", "char"], + } + for record in self: + allowed_types = type_mapping.get(record.question_type, []) + domain = [ + ("model", "=", "res.partner"), + ("ttype", "in", allowed_types), + ("store", "=", True), + ("readonly", "=", False), + ] + record.allowed_partner_field_domain = domain + + +class SurveyQuestionAnswer(models.Model): + _inherit = "survey.question.answer" + + @api.model + def default_get(self, fields): + result = super().default_get(fields) + if ( + not result.get("res_partner_field") + or "res_partner_field_resource_ref" not in fields + ): + return result + partner_field = self.env["ir.model.fields"].browse(result["res_partner_field"]) + # Otherwise we'll just use the value (char, text) + if partner_field.ttype not in {"many2one", "many2many"}: + return result + res = self.env[partner_field.relation].search([], limit=1) + if res: + result["res_partner_field_resource_ref"] = ( + f"{partner_field.relation},{res.id}" + ) + return result + + @api.model + def _selection_res_partner_field_resource_ref(self): + return [(model.model, model.name) for model in self.env["ir.model"].search([])] + + res_partner_field = fields.Many2one(related="question_id.res_partner_field") + res_partner_field_resource_ref = fields.Reference( + string="Contact field value", + selection="_selection_res_partner_field_resource_ref", + ) + + @api.onchange("res_partner_field_resource_ref") + def _onchange_res_partner_field_resource_ref(self): + """Set the default value as the product name, although we can change it""" + if self.res_partner_field_resource_ref: + self.value = self.res_partner_field_resource_ref.display_name or "" diff --git a/survey_contact_generation/models/survey_survey.py b/survey_contact_generation/models/survey_survey.py new file mode 100644 index 00000000..89a2800e --- /dev/null +++ b/survey_contact_generation/models/survey_survey.py @@ -0,0 +1,15 @@ +# Copyright 2023 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class SurveySurvey(models.Model): + _inherit = "survey.survey" + + 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", + ) diff --git a/survey_contact_generation/models/survey_user_input.py b/survey_contact_generation/models/survey_user_input.py new file mode 100644 index 00000000..5119d40e --- /dev/null +++ b/survey_contact_generation/models/survey_user_input.py @@ -0,0 +1,184 @@ +# Copyright 2022 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 _get_partner_nodes(self): + """The questions opening a contact of their own. + + Filling in the name opens a contact, and then `survey_question_node_id` + tells which contact it hangs from. Any other question fills in a field + of the contact its own `survey_question_node_id` opened. A name answered + outside any node belongs to the main generated contact instead. + """ + self.ensure_one() + questions = self.survey_id.question_ids + nodes = questions.survey_question_node_id + return questions.filtered( + lambda x: x.res_partner_field.name == "name" + and (x.survey_question_node_id or x in nodes) + ) + + def _get_partner_groups(self): + """The answers that fill in a contact, grouped by the contact they fill""" + self.ensure_one() + nodes = self._get_partner_nodes() + return self.user_input_line_ids.filtered( + lambda x: x.question_id.res_partner_field and not x.skipped + ).grouped( + lambda x: x.question_id + if x.question_id in nodes + else x.question_id.survey_question_node_id + ) + + def _get_partner_node_children(self, groups, node): + """The nodes whose contact hangs from the given node's one""" + return [ + child + for child in groups + # A node whose own node answered nothing hangs from the main contact + if child + and ( + child.survey_question_node_id == node + or (not node and child.survey_question_node_id not in groups) + ) + ] + + def _prepare_partner(self): + """Extract the values of the main contact from the answers""" + self.ensure_one() + groups = self._get_partner_groups() + vals = self._prepare_partner_vals( + groups.get(self.env["survey.question"], self.env["survey.user_input.line"]) + ) + vals["generating_survey_user_input_id"] = self.id + return vals + + def _create_partner_nodes(self, groups, node, parent): + """Generate the contact of every node hanging from the given one. + + `res.partner` sets `_allow_sudo_commands = False`, so the contacts can't + be nested in the `child_ids` of their parent: the commands would run + back as the survey taker, who isn't allowed to create contacts. Each + contact gets its own `create()` instead, linked through `parent_id`. + + Returns the contacts generated right below the given node. + """ + self.ensure_one() + partners = self.env["res.partner"] + for child in self._get_partner_node_children(groups, node): + vals = self._prepare_partner_vals(groups[child]) + if not vals.get("name"): + # A node whose name went unanswered opens no contact, so + # whatever hangs from it hangs from its own node instead. Its + # remaining answers are dropped: they have no contact to fill. + partners |= self._create_partner_nodes(groups, child, parent) + continue + if parent: + vals["parent_id"] = parent.id + # `contact` children share their address with their parent, so a + # node holding an address of its own needs a different type + if child.res_partner_type: + vals["type"] = child.res_partner_type + partner = self.env["res.partner"].sudo().create(vals) + self._create_contact_post_process(partner) + self._create_partner_nodes(groups, child, partner) + partners |= partner + return partners + + def _prepare_partner_vals(self, elegible_inputs): + """Extract the values of a single contact out of its group of answers""" + self.ensure_one() + basic_inputs = elegible_inputs.filtered( + lambda x: x.answer_type not in {"suggestion"} + 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}"] + for line in basic_inputs + } + for line in elegible_inputs - 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}" + # 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"] + .sudo() + .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): + 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 _create_contact_post_process(self, partner): + """After creating the lead send an internal message with the input link""" + partner.message_post_with_source( + "mail.message_origin_link", + render_values={"self": partner, "origin": self.survey_id}, + subtype_xmlid="mail.mt_note", + ) + + def _get_existing_partner(self, email, limit=1): + """Hook method that can be used to change the behavior of contact generation""" + return self.env["res.partner"].search([("email", "=ilike", email)], limit=limit) + + def _mark_done(self): + """Generate the contact when the survey is submitted""" + for user_input in self.filtered( + lambda r: r.survey_id.generate_contact and not r.partner_id + ): + vals = user_input._prepare_partner() + partner = self.env["res.partner"] + # Every answer may live inside a node, and then there's no main + # contact to generate: the root node contact takes its place + if set(vals) - {"generating_survey_user_input_id"}: + email = vals.get("email") + if email: + partner = user_input._get_existing_partner(email) + if not partner: + partner = self.env["res.partner"].sudo().create(vals) + user_input._create_contact_post_process(partner) + # The node contacts hang from the main one, when there's one + roots = user_input._create_partner_nodes( + user_input._get_partner_groups(), self.env["survey.question"], partner + ) + if not partner: + partner = next(iter(roots)) if len(roots) > 1 else roots + partner.sudo().generating_survey_user_input_id = user_input + if partner: + user_input.update({"partner_id": partner.id, "email": partner.email}) + return super()._mark_done() diff --git a/survey_contact_generation/pyproject.toml b/survey_contact_generation/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/survey_contact_generation/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/survey_contact_generation/readme/CONFIGURE.md b/survey_contact_generation/readme/CONFIGURE.md new file mode 100644 index 00000000..b3f74f7f --- /dev/null +++ b/survey_contact_generation/readme/CONFIGURE.md @@ -0,0 +1,41 @@ +To configure the contact generation: + +1. Go to the configured survey. +2. 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. +3. 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. +4. 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, and select the 'Contact field' + field. + +To generate a hierarchy of contacts out of a single survey: + +1. A question mapped to the *Name* contact field opens a contact of its + own. Any other question fills in a field of the contact opened by its + *Node*. +2. In such a question, set *Node* to the question opening the contact it + hangs from. Leave it empty and its answers will belong to the main + generated contact. +3. Contacts typed as *Contact* share their address with their parent, so + set *Contact address type* to *Other address* in the questions opening + a contact that holds an address of its own. + +For instance, this survey generates a company, two of its workcenters +with their own address, and an employee hanging from each workcenter: + +| Question | Contact field | Node | Address type | +|----------------------|---------------|----------------------|---------------| +| Company name | name | | | +| Workcenter 1 | name | Company name | Other address | +| Workcenter 1 street | street | Workcenter 1 | | +| Workcenter 1 employee| name | Workcenter 1 | | +| Workcenter 2 | name | Company name | Other address | +| Workcenter 2 street | street | Workcenter 2 | | +| Workcenter 2 employee| name | Workcenter 2 | | + +A node whose name goes unanswered generates no contact, and whatever hangs +from it hangs from its own node instead. diff --git a/survey_contact_generation/readme/CONTRIBUTORS.md b/survey_contact_generation/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..41e7f47b --- /dev/null +++ b/survey_contact_generation/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- [Tecnativa](https://www.tecnativa.com) + - David Vidal + - Ernesto Tejeda + - Stefan Ungureanu + - Pilar Vargas + - Eduardo Ezerouali + - Adasat Torres diff --git a/survey_contact_generation/readme/DESCRIPTION.md b/survey_contact_generation/readme/DESCRIPTION.md new file mode 100644 index 00000000..ac10b74a --- /dev/null +++ b/survey_contact_generation/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to generate new contacts from surveys answers. diff --git a/survey_contact_generation/readme/USAGE.md b/survey_contact_generation/readme/USAGE.md new file mode 100644 index 00000000..80fde260 --- /dev/null +++ b/survey_contact_generation/readme/USAGE.md @@ -0,0 +1,2 @@ +if the survey is properly configured, once it is submited by an +anonomous user, a new contact is create or an existing one is linked. diff --git a/survey_contact_generation/static/description/icon.png b/survey_contact_generation/static/description/icon.png new file mode 100644 index 00000000..ae0af814 Binary files /dev/null and b/survey_contact_generation/static/description/icon.png differ diff --git a/survey_contact_generation/static/description/index.html b/survey_contact_generation/static/description/index.html new file mode 100644 index 00000000..637befb9 --- /dev/null +++ b/survey_contact_generation/static/description/index.html @@ -0,0 +1,531 @@ + + + + + +Survey contacts generation + + + +
+ + + +Odoo Community Association + +
+

Survey contacts generation

+ +

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

+

This module allows to generate new contacts from surveys answers.

+

Table of contents

+ +
+

Configuration

+

To configure the contact generation:

+
    +
  1. Go to the configured survey.
  2. +
  3. 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.
  4. +
  5. 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.
  6. +
  7. 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, and select the ‘Contact field’ +field.
  8. +
+

To generate a hierarchy of contacts out of a single survey:

+
    +
  1. A question mapped to the Name contact field opens a contact of its +own. Any other question fills in a field of the contact opened by its +Node.
  2. +
  3. In such a question, set Node to the question opening the contact it +hangs from. Leave it empty and its answers will belong to the main +generated contact.
  4. +
  5. Contacts typed as Contact share their address with their parent, so +set Contact address type to Other address in the questions +opening a contact that holds an address of its own.
  6. +
+

For instance, this survey generates a company, two of its workcenters +with their own address, and an employee hanging from each workcenter:

+ ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
QuestionContact fieldNodeAddress type
Company namename  
Workcenter 1nameCompany nameOther address
Workcenter 1 streetstreetWorkcenter 1 
Workcenter 1 employeenameWorkcenter 1 
Workcenter 2nameCompany nameOther address
Workcenter 2 streetstreetWorkcenter 2 
Workcenter 2 employeenameWorkcenter 2 
+

A node whose name goes unanswered generates no contact, and whatever +hangs from it hangs from its own node instead.

+
+
+

Usage

+

if the survey is properly configured, once it is submited by an +anonomous user, a new contact is create or an existing one is linked.

+
+
+

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
    • +
    • Ernesto Tejeda
    • +
    • Stefan Ungureanu
    • +
    • Pilar Vargas
    • +
    • Eduardo Ezerouali
    • +
    • Adasat Torres
    • +
    +
  • +
+
+
+

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:

+

pilarvargas-tecnativa

+

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_contact_generation/static/tests/survey_contact_generation_tour.esm.js b/survey_contact_generation/static/tests/survey_contact_generation_tour.esm.js new file mode 100644 index 00000000..1c24a85c --- /dev/null +++ b/survey_contact_generation/static/tests/survey_contact_generation_tour.esm.js @@ -0,0 +1,93 @@ +import {registry} from "@web/core/registry"; + +registry.category("web_tour.tours").add("test_survey_contact_generation", { + steps: () => [ + { + content: "Click on Start", + trigger: "button.btn:contains('Start Survey')", + run: "click", + }, + { + content: "Company Name", + trigger: "div.js_question-wrapper:contains('Company') input", + run: "edit My Company Name", + }, + { + content: "Submit and go to Next Page", + trigger: 'button[value="next"]', + run: "click", + }, + { + content: "Name", + trigger: "div.js_question-wrapper:contains('Name') input", + run: "edit My Name", + }, + { + content: "Submit and go to Next Page", + trigger: 'button[value="next"]', + run: "click", + }, + { + content: "Email", + trigger: "div.js_question-wrapper:contains('Email') input", + run: "edit survey_contact_generation@test.com", + }, + { + content: "Submit and go to Next Page", + trigger: 'button[value="next"]', + run: "click", + }, + { + content: "Notes", + trigger: "div.js_question-wrapper:contains('Notes') textarea", + run: "edit This is a test note", + }, + { + content: "Submit and go to Next Page", + trigger: 'button[value="next"]', + run: "click", + }, + { + content: "Color", + trigger: "div.js_question-wrapper:contains('Color') input", + run: "edit 1", + }, + { + content: "Submit and go to Next Page", + trigger: 'button[value="next"]', + run: "click", + }, + { + content: "Country", + trigger: + "div.js_question-wrapper:contains('Country') label:contains('Romania') i.fa-circle-thin", + run: "click", + }, + { + content: "Tags", + trigger: + "div.js_question-wrapper:contains('Tags') label:contains('Prospects') i", + run: "click", + }, + { + content: "Tags", + trigger: + "div.js_question-wrapper:contains('Tags') label:contains('Vendor') i", + run: "click", + }, + { + content: "Click Submit", + trigger: "button.btn:contains('Submit')", + run: "click", + }, + { + content: "Modal", + trigger: "footer:contains('Submit') button.btn-primary", + run: "click", + }, + { + content: "Thank you", + trigger: "h1:contains('Thank you!')", + }, + ], +}); diff --git a/survey_contact_generation/tests/__init__.py b/survey_contact_generation/tests/__init__.py new file mode 100644 index 00000000..a8a77a9f --- /dev/null +++ b/survey_contact_generation/tests/__init__.py @@ -0,0 +1,2 @@ +from . import test_survey_contact_generation +from . import test_survey_contact_nesting diff --git a/survey_contact_generation/tests/test_survey_contact_generation.py b/survey_contact_generation/tests/test_survey_contact_generation.py new file mode 100644 index 00000000..3b7ad5f8 --- /dev/null +++ b/survey_contact_generation/tests/test_survey_contact_generation.py @@ -0,0 +1,186 @@ +# Copyright 2023 Tecnativa - David Vidal +# Copyright 2023 Tecnativa - Stefan Ungureanu +# Copyright 2026 Tecnativa - Adasat Torres +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import Command +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() + + def _create_reference(obj): + return f"{obj._name},{obj.id}" + + self.vendor_category = self.env["res.partner.category"].create( + { + "name": "Vendor", + } + ) + self.prospect_category = self.env["res.partner.category"].create( + { + "name": "Prospects", + } + ) + self.employee_category = self.env["res.partner.category"].create( + { + "name": "Employees", + } + ) + + self.survey = self.env["survey.survey"].create( + { + "title": "Contact Creation Survey", + "access_mode": "public", + "users_can_go_back": True, + "generate_contact": True, + "create_parent_contact": True, + "question_and_page_ids": [ + Command.create( + { + "sequence": 0, + "title": "Company", + "question_type": "char_box", + "constr_mandatory": True, + "res_partner_field": self.env.ref( + "base.field_res_partner__company_name" + ).id, + } + ), + Command.create( + { + "sequence": 1, + "title": "Name", + "question_type": "char_box", + "constr_mandatory": True, + "res_partner_field": self.env.ref( + "base.field_res_partner__name" + ).id, + } + ), + Command.create( + { + "sequence": 2, + "title": "Email", + "question_type": "char_box", + "res_partner_field": self.env.ref( + "base.field_res_partner__email" + ).id, + } + ), + Command.create( + { + "sequence": 3, + "title": "Notes", + "question_type": "text_box", + "res_partner_field": self.env.ref( + "base.field_res_partner__comment" + ).id, + } + ), + Command.create( + { + "sequence": 4, + "title": "Color", + "question_type": "numerical_box", + "res_partner_field": self.env.ref( + "base.field_res_partner__color" + ).id, + } + ), + Command.create( + { + "sequence": 6, + "title": "Country", + "question_type": "simple_choice", + "res_partner_field": self.env.ref( + "base.field_res_partner__country_id" + ).id, + "suggested_answer_ids": [ + Command.create( + { + "sequence": 1, + "value": "Spain", + "res_partner_field_resource_ref": ( + _create_reference(self.env.ref("base.es")) + ), + } + ), + Command.create( + { + "sequence": 2, + "value": "Romania", + "res_partner_field_resource_ref": ( + _create_reference(self.env.ref("base.ro")) + ), + } + ), + ], + } + ), + Command.create( + { + "sequence": 7, + "title": "Tags", + "question_type": "multiple_choice", + "res_partner_field": self.env.ref( + "base.field_res_partner__category_id" + ).id, + "suggested_answer_ids": [ + Command.create( + { + "sequence": 1, + "value": "Vendor", + "res_partner_field_resource_ref": ( + _create_reference(self.vendor_category) + ), + } + ), + Command.create( + { + "sequence": 2, + "value": "Prospects", + "res_partner_field_resource_ref": ( + _create_reference(self.prospect_category) + ), + } + ), + Command.create( + { + "sequence": 3, + "value": "Employees", + "res_partner_field_resource_ref": ( + _create_reference(self.vendor_category) + ), + } + ), + ], + } + ), + ], + } + ) + initial_user_inputs = self.survey.user_input_ids + # Run the survey as a portal user and get the generated quotation + self.start_tour( + f"/survey/start/{self.survey.access_token}", + "test_survey_contact_generation", + ) + self.user_input = self.survey.user_input_ids - initial_user_inputs + + +@tagged("-at_install", "post_install") +class SurveyContactGenerationTests(SurveyContactGenerationCase): + def test_contact_generation(self): + partner = self.env["res.partner"].search( + [("email", "=", "survey_contact_generation@test.com")] + ) + self.assertEqual(partner, self.user_input.partner_id) + self.assertEqual(partner.parent_id.name, "My Company Name") + self.assertEqual(partner.generating_survey_user_input_id, self.user_input) diff --git a/survey_contact_generation/tests/test_survey_contact_nesting.py b/survey_contact_generation/tests/test_survey_contact_nesting.py new file mode 100644 index 00000000..81c35d59 --- /dev/null +++ b/survey_contact_generation/tests/test_survey_contact_nesting.py @@ -0,0 +1,225 @@ +# Copyright 2026 Tecnativa - Eduardo Ezerouali +# Copyright 2026 Tecnativa - Adasat Torres +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestSurveyContactNesting(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.survey = cls.env["survey.survey"].create( + { + "title": "Nested Contact Creation Survey", + "access_mode": "public", + "users_can_go_back": True, + "generate_contact": True, + } + ) + cls.questions = cls.env["survey.question"] + cls.q_company = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 0, + "title": "Company name", + "question_type": "char_box", + "constr_mandatory": True, + "res_partner_field": cls.env.ref("base.field_res_partner__name").id, + } + ) + cls.q_workcenter_1 = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 1, + "title": "Workcenter 1", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__name").id, + "res_partner_type": "other", + } + ) + cls.q_workcenter_1_street = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 2, + "title": "Workcenter 1 street", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__street").id, + } + ) + cls.q_employee_1 = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 3, + "title": "Workcenter 1 employee", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__name").id, + } + ) + cls.q_employee_1_email = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 4, + "title": "Workcenter 1 employee email", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__email").id, + } + ) + cls.q_workcenter_2 = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 5, + "title": "Workcenter 2", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__name").id, + "res_partner_type": "other", + } + ) + cls.q_workcenter_2_street = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 6, + "title": "Workcenter 2 street", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__street").id, + } + ) + cls.q_employee_2 = cls.questions.create( + { + "survey_id": cls.survey.id, + "sequence": 7, + "title": "Workcenter 2 employee", + "question_type": "char_box", + "res_partner_field": cls.env.ref("base.field_res_partner__name").id, + } + ) + questions = { + question.sequence: question for question in cls.survey.question_ids + } + questions[1].survey_question_node_id = questions[0] + questions[2].survey_question_node_id = questions[1] + questions[3].survey_question_node_id = questions[1] + questions[4].survey_question_node_id = questions[3] + questions[5].survey_question_node_id = questions[0] + questions[6].survey_question_node_id = questions[5] + questions[7].survey_question_node_id = questions[5] + + def _answer(self, user_input, answers): + """Answer the given `{question: value}` map with char box lines""" + for question, value in answers.items(): + self.env["survey.user_input.line"].create( + { + "user_input_id": user_input.id, + "question_id": question.id, + "skipped": not value, + "answer_type": "char_box" if value else False, + "value_char_box": value, + } + ) + + def _submit(self, answers=None): + """Answer the whole survey, overriding the given answers, and submit it""" + user_input = self.env["survey.user_input"].create({"survey_id": self.survey.id}) + default_answers = { + self.q_company: "ACME", + self.q_workcenter_1: "Workcenter North", + self.q_workcenter_1_street: "1 North Street", + self.q_employee_1: "Alice", + self.q_employee_1_email: "alice@example.com", + self.q_workcenter_2: "Workcenter South", + self.q_workcenter_2_street: "2 South Street", + self.q_employee_2: "Bob", + } + default_answers.update(answers or {}) + self._answer(user_input, default_answers) + user_input._mark_done() + return user_input + + def _get_contact(self, user_input, name): + return self.env["res.partner"].search( + [("id", "child_of", user_input.partner_id.id), ("name", "=", name)] + ) + + def test_groups_open_one_contact_per_name_question(self): + """A name question opens a contact, any other one fills the node's contact""" + user_input = self.env["survey.user_input"].create({"survey_id": self.survey.id}) + self._answer( + user_input, + { + self.q_company: "ACME", + self.q_workcenter_1: "Workcenter North", + self.q_workcenter_1_street: "1 North Street", + self.q_employee_1: "Alice", + }, + ) + groups = user_input._get_partner_groups() + self.assertEqual( + {key.title for key in groups}, + {"Company name", "Workcenter 1", "Workcenter 1 employee"}, + ) + # The street doesn't open a contact: it fills in the workcenter's one + self.assertEqual( + groups[self.q_workcenter_1].question_id, + self.q_workcenter_1 + self.q_workcenter_1_street, + ) + + def test_contact_hierarchy(self): + """Every node generates a contact hanging from the contact of its node""" + user_input = self._submit() + company = user_input.partner_id + self.assertEqual(company.name, "ACME") + self.assertFalse(company.parent_id) + self.assertEqual(company.generating_survey_user_input_id, user_input) + north = self._get_contact(user_input, "Workcenter North") + south = self._get_contact(user_input, "Workcenter South") + self.assertEqual(north.parent_id, company) + self.assertEqual(south.parent_id, company) + self.assertEqual(self._get_contact(user_input, "Alice").parent_id, north) + self.assertEqual(self._get_contact(user_input, "Bob").parent_id, south) + + def test_sibling_nodes_do_not_share_their_answers(self): + """Contacts hanging from the same node don't overwrite each other""" + user_input = self._submit() + self.assertEqual( + self._get_contact(user_input, "Workcenter North").street, "1 North Street" + ) + self.assertEqual( + self._get_contact(user_input, "Workcenter South").street, "2 South Street" + ) + self.assertEqual( + self._get_contact(user_input, "Alice").email, "alice@example.com" + ) + self.assertFalse(self._get_contact(user_input, "Bob").email) + + def test_address_type_isolates_the_address(self): + """A node typed as an address doesn't share it with its parent's family""" + user_input = self._submit() + north = self._get_contact(user_input, "Workcenter North") + self.assertEqual(north.type, "other") + # A `contact` child still shares the address of its own node + self.assertEqual(self._get_contact(user_input, "Alice").type, "contact") + self.assertEqual(self._get_contact(user_input, "Alice").street, north.street) + + def test_skipped_node_hands_its_children_over(self): + """A node whose name went unanswered generates no contact""" + user_input = self._submit({self.q_workcenter_1: False}) + company = user_input.partner_id + self.assertFalse(self._get_contact(user_input, "Workcenter North")) + # Alice hangs from the company now, as her own node generated nothing + self.assertEqual(self._get_contact(user_input, "Alice").parent_id, company) + # A nameless contact holding the orphan street is not generated either + contacts = self.env["res.partner"].search([("id", "child_of", company.id)]) + self.assertFalse(contacts.filtered(lambda x: not x.name)) + self.assertFalse(contacts.filtered(lambda x: x.street == "1 North Street")) + + def test_root_node_contact_is_the_generated_one(self): + """With every answer inside a node there's no main contact to generate""" + user_input = self._submit() + # The root node contact takes the place of the main one + self.assertEqual(user_input.partner_id.name, "ACME") + self.assertEqual( + self.env["res.partner"].search_count( + [("generating_survey_user_input_id", "=", user_input.id)] + ), + 1, + ) diff --git a/survey_contact_generation/views/survey_question_views.xml b/survey_contact_generation/views/survey_question_views.xml new file mode 100644 index 00000000..e85c0c32 --- /dev/null +++ b/survey_contact_generation/views/survey_question_views.xml @@ -0,0 +1,47 @@ + + + + survey.question + + + + + + + + + + + + + {'default_question_id': id, 'default_res_partner_field': res_partner_field} + + + + + + + + diff --git a/survey_contact_generation/views/survey_survey_views.xml b/survey_contact_generation/views/survey_survey_views.xml new file mode 100644 index 00000000..865911d8 --- /dev/null +++ b/survey_contact_generation/views/survey_survey_views.xml @@ -0,0 +1,18 @@ + + + + survey.survey + + + + + + + + + + +