diff --git a/survey_contact_generation/README.rst b/survey_contact_generation/README.rst new file mode 100644 index 0000000..f60b817 --- /dev/null +++ b/survey_contact_generation/README.rst @@ -0,0 +1,109 @@ +========================== +Survey contacts generation +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0a298d1600a5f93ffe77357631c7e799e78b23b84c362b126720e36655dd5227 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_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-15-0/survey-15-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=15.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: + +#. Go to the configured survey. +#. 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. +#. 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. + +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 + +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_contact_generation/__init__.py b/survey_contact_generation/__init__.py new file mode 100644 index 0000000..0650744 --- /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 0000000..8138023 --- /dev/null +++ b/survey_contact_generation/__manifest__.py @@ -0,0 +1,24 @@ +# 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": "16.0.1.0.0", + "development_status": "Beta", + "category": "Marketing/Survey", + "website": "https://github.com/OCA/survey", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["clement_thomas"], + "license": "AGPL-3", + "depends": ["survey"], + "data": [ + "views/survey_question_views.xml", + "views/survey_survey_views.xml", + ], + "demo": ["demo/survey_contact_generation_demo.xml"], + "assets": { + "web.assets_tests": [ + "/survey_contact_generation/static/tests/survey_contact_generation_tour.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 0000000..85fcc64 --- /dev/null +++ b/survey_contact_generation/demo/survey_contact_generation_demo.xml @@ -0,0 +1,100 @@ + + + + + Contact Creation Survey + 80e5f1e2-1a9d-4c51-8e23-09e93f7fa2c5 + public + + + + + + 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_contact_generation/i18n/es.po b/survey_contact_generation/i18n/es.po new file mode 100644 index 0000000..1a29c04 --- /dev/null +++ b/survey_contact_generation/i18n/es.po @@ -0,0 +1,168 @@ +# 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-06-14 13:58+0200\n" +"Last-Translator: \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: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: survey_contact_generation +#: model:ir.model.fields,field_description:survey_contact_generation.field_survey_question__allowed_field_ids +msgid "Allowed Field" +msgstr "Campo permitido" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q3 +msgid "Color" +msgstr "Color" + +#. module: survey_contact_generation +#: 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_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 "" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q5 +msgid "Country" +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 "" + +#. 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:survey.question,comments_message:survey_contact_generation.survey_contact_q0 +#: model:survey.question,comments_message:survey_contact_generation.survey_contact_q1 +#: model:survey.question,comments_message:survey_contact_generation.survey_contact_q2 +#: model:survey.question,comments_message:survey_contact_generation.survey_contact_q3 +#: model:survey.question,comments_message:survey_contact_generation.survey_contact_q4 +#: model:survey.question,comments_message:survey_contact_generation.survey_contact_q5 +#: model:survey.question,comments_message:survey_contact_generation.survey_contact_q6 +msgid "If other, please specify:" +msgstr "Si es otro, especifíquelo:" + +#. module: survey_contact_generation +#: model:survey.question,title:survey_contact_generation.survey_contact_q0 +msgid "Name" +msgstr "Nombre" + +#. 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 "" + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q5_sug2 +msgid "Romania" +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 "Planificación" + +#. 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 "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 "" + +#. module: survey_contact_generation +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q0 +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q1 +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q2 +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q3 +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q4 +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q5 +#: model:survey.question,validation_error_msg:survey_contact_generation.survey_contact_q6 +msgid "The answer you entered is not valid." +msgstr "La respuesta que has introducido no es válida." + +#. module: survey_contact_generation +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q0 +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q1 +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q2 +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q3 +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q4 +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q5 +#: model:survey.question,constr_error_msg:survey_contact_generation.survey_contact_q6 +msgid "This question requires an answer." +msgstr "Esta pregunta requiere una respuesta." + +#. module: survey_contact_generation +#: model:survey.question.answer,value:survey_contact_generation.survey_contact_q6_sug1 +msgid "Vendor" +msgstr "" diff --git a/survey_contact_generation/models/__init__.py b/survey_contact_generation/models/__init__.py new file mode 100644 index 0000000..93bb3b4 --- /dev/null +++ b/survey_contact_generation/models/__init__.py @@ -0,0 +1,3 @@ +from . import survey_question +from . import survey_survey +from . import survey_user_input diff --git a/survey_contact_generation/models/survey_question.py b/survey_contact_generation/models/survey_question.py new file mode 100644 index 0000000..e86d4a0 --- /dev/null +++ b/survey_contact_generation/models/survey_question.py @@ -0,0 +1,80 @@ +# 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_field_ids = fields.Many2many( + comodel_name="ir.model.fields", + compute="_compute_allowed_field_ids", + ) + res_partner_field = fields.Many2one( + string="Contact field", + comodel_name="ir.model.fields", + domain="[('id', 'in', allowed_field_ids)]", + ) + + @api.depends("question_type") + def _compute_allowed_field_ids(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: + record.allowed_field_ids = ( + self.env["ir.model.fields"] + .search( + [ + ("model", "=", "res.partner"), + ("ttype", "in", type_mapping.get(record.question_type, [])), + ] + ) + .ids + ) + + +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"] = "%s,%s" % ( + 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 0000000..9632102 --- /dev/null +++ b/survey_contact_generation/models/survey_survey.py @@ -0,0 +1,11 @@ +# 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", + ) 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 0000000..7f54edf --- /dev/null +++ b/survey_contact_generation/models/survey_user_input.py @@ -0,0 +1,77 @@ +# 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 _prepare_partner(self): + """Extract partner values from the answers""" + self.ensure_one() + elegible_inputs = self.user_input_line_ids.filtered( + lambda x: x.question_id.res_partner_field and not x.skipped + ) + basic_inputs = elegible_inputs.filtered( + lambda x: x.answer_type not in {"suggestion"} + and x.question_id.res_partner_field.name != "comment" + ) + 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}" + 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_view( + "mail.message_origin_link", + values={"self": partner, "origin": self.survey_id}, + subtype_id=self.env.ref("mail.mt_note").id, + ) + + 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 self.partner_id + ): + vals = user_input._prepare_partner() + partner = False + email = vals.get("email") + if email: + partner = self.env["res.partner"].search( + [("email", "=", email)], limit=1 + ) + if not partner: + partner = self.env["res.partner"].create(vals) + self._create_contact_post_process(partner) + self.update({"partner_id": partner.id, "email": partner.email}) + return super()._mark_done() diff --git a/survey_contact_generation/readme/CONFIGURE.rst b/survey_contact_generation/readme/CONFIGURE.rst new file mode 100644 index 0000000..18966aa --- /dev/null +++ b/survey_contact_generation/readme/CONFIGURE.rst @@ -0,0 +1,10 @@ +To configure the contact generation: + +#. Go to the configured survey. +#. 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. +#. 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. diff --git a/survey_contact_generation/readme/CONTRIBUTORS.rst b/survey_contact_generation/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..e3851e7 --- /dev/null +++ b/survey_contact_generation/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_ + + * David Vidal + * Ernesto Tejeda + * Stefan Ungureanu diff --git a/survey_contact_generation/readme/DESCRIPTION.rst b/survey_contact_generation/readme/DESCRIPTION.rst new file mode 100644 index 0000000..ac10b74 --- /dev/null +++ b/survey_contact_generation/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to generate new contacts from surveys answers. diff --git a/survey_contact_generation/readme/USAGE.rst b/survey_contact_generation/readme/USAGE.rst new file mode 100644 index 0000000..f7c7830 --- /dev/null +++ b/survey_contact_generation/readme/USAGE.rst @@ -0,0 +1,3 @@ +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 0000000..ae0af81 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 0000000..64dc95c --- /dev/null +++ b/survey_contact_generation/static/description/index.html @@ -0,0 +1,450 @@ + + + + + + +Survey contacts generation + + + +
+

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

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

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_contact_generation/static/tests/survey_contact_generation_tour.js b/survey_contact_generation/static/tests/survey_contact_generation_tour.js new file mode 100644 index 0000000..25e3d2b --- /dev/null +++ b/survey_contact_generation/static/tests/survey_contact_generation_tour.js @@ -0,0 +1,82 @@ +odoo.define("survey.tour_test_survey_contact_generation", function (require) { + "use strict"; + + const tour = require("web_tour.tour"); + + tour.register( + "test_survey_contact_generation", + { + test: true, + url: "/survey/start/80e5f1e2-1a9d-4c51-8e23-09e93f7fa2c5", + }, + [ + { + content: "Click on Start", + trigger: "button.btn:contains('Start Survey')", + }, + { + content: "Name", + trigger: "div.js_question-wrapper:contains('Name') input", + run: "text My 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_contact_generation/tests/__init__.py b/survey_contact_generation/tests/__init__.py new file mode 100644 index 0000000..d4c56fb --- /dev/null +++ b/survey_contact_generation/tests/__init__.py @@ -0,0 +1 @@ +from . import test_survey_contact_generation 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 0000000..ff24ca9 --- /dev/null +++ b/survey_contact_generation/tests/test_survey_contact_generation.py @@ -0,0 +1,31 @@ +# Copyright 2023 Tecnativa - David Vidal +# Copyright 2023 Tecnativa - Stefan Ungureanu +# 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.survey = self.env.ref("survey_contact_generation.survey_contact_creation") + 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) 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 0000000..e235807 --- /dev/null +++ b/survey_contact_generation/views/survey_question_views.xml @@ -0,0 +1,32 @@ + + + + survey.question + + + + + + + + + + {'default_question_id': active_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 0000000..c901a1b --- /dev/null +++ b/survey_contact_generation/views/survey_survey_views.xml @@ -0,0 +1,14 @@ + + + + survey.survey + + + + + + + + + + diff --git a/survey_event_registration_generation/__init__.py b/survey_event_registration_generation/__init__.py new file mode 100644 index 0000000..38718f0 --- /dev/null +++ b/survey_event_registration_generation/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import controllers \ No newline at end of file diff --git a/survey_event_registration_generation/__manifest__.py b/survey_event_registration_generation/__manifest__.py new file mode 100644 index 0000000..02890d9 --- /dev/null +++ b/survey_event_registration_generation/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2016-2020 Akretion France () +# @author: Alexis de Lattre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Survey event registration generation", + "version": "16.0.0.0.0", + "license": "AGPL-3", + "author": "Elabore", + "website": "https://www.elabore.coop", + "category": "", + "depends": ["survey"], + "data": [ + 'views/survey_question_views.xml', + 'views/survey_templates.xml' + ], + 'assets': { + 'survey.survey_assets': [ + '/survey_event_registration_generation/static/src/js/survey_form.js', + ], + }, + "installable": True, +} diff --git a/survey_event_registration_generation/controllers/__init__.py b/survey_event_registration_generation/controllers/__init__.py new file mode 100644 index 0000000..1aeae82 --- /dev/null +++ b/survey_event_registration_generation/controllers/__init__.py @@ -0,0 +1,4 @@ +# -*- encoding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import main \ No newline at end of file diff --git a/survey_event_registration_generation/controllers/main.py b/survey_event_registration_generation/controllers/main.py new file mode 100644 index 0000000..44e0aac --- /dev/null +++ b/survey_event_registration_generation/controllers/main.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.survey.controllers import main +from odoo.http import request + +class Survey(main.Survey): + def _prepare_survey_data(self, survey_sudo, answer_sudo, **post): + result = super(Survey, self)._prepare_survey_data(survey_sudo, answer_sudo, **post) + result['event_products'] = request.env['product.product'].search([('detailed_type','=','event')]) + + next_event_question = self._get_next_event_question(answer_sudo) + if next_event_question: + event_product = None + if next_event_question.event_product_question_id: + event_product = self._get_answer_event_product(next_event_question.event_product_question_id, answer_sudo) + if event_product: + event_tickets = request.env['event.event.ticket'].search([('product_id','=',event_product.id)]) + result['events'] = event_tickets.event_id + else: + result['events'] = request.env['event.event'].search([]) + + return result + + def _get_answer_event_product(self, question, answer_sudo): + for user_input_line in answer_sudo.user_input_line_ids: + if user_input_line.question_id == question: + return user_input_line.value_event_product + + + def _get_next_event_question(self, answer_sudo): + future_question = False + for question in answer_sudo.predefined_question_ids: + if question == answer_sudo.last_displayed_page_id: + future_question = True + continue + if not future_question: + continue + if question.question_type == 'event': + return question diff --git a/survey_event_registration_generation/models/__init__.py b/survey_event_registration_generation/models/__init__.py new file mode 100644 index 0000000..d6b6801 --- /dev/null +++ b/survey_event_registration_generation/models/__init__.py @@ -0,0 +1,3 @@ +from . import survey_question +from . import survey_user_input +from . import survey_user_input_line \ No newline at end of file diff --git a/survey_event_registration_generation/models/survey_question.py b/survey_event_registration_generation/models/survey_question.py new file mode 100644 index 0000000..94c1b05 --- /dev/null +++ b/survey_event_registration_generation/models/survey_question.py @@ -0,0 +1,28 @@ +from odoo import models, fields, api + + +class SurveyQuestion(models.Model): + _inherit = 'survey.question' + + question_type = fields.Selection( + selection_add=[('event_product', 'Event product'),('event', 'Event')]) + + + event_product_question_id = fields.Many2one( + 'survey.question', string="Event ticket question", copy=False, compute="_compute_event_product_question_id", + store=True, readonly=False, help="If you specify question of event product, only events of selected product will be proposed.", + domain="[('survey_id', '=', survey_id), \ + '&', ('question_type', '=', 'event_product'), \ + '|', \ + ('sequence', '<', sequence), \ + '&', ('sequence', '=', sequence), ('id', '<', id)]") + + + @api.depends('question_type') + def _compute_event_product_question_id(self): + """ Used as an 'onchange' : Reset the event ticket question if user change question type + Avoid CacheMiss : set the value to False if the value is not set yet.""" + for question in self: + if not question.question_type == 'event' or question.triggering_question_id is None: + question.triggering_question_id = False + \ No newline at end of file diff --git a/survey_event_registration_generation/models/survey_user_input.py b/survey_event_registration_generation/models/survey_user_input.py new file mode 100644 index 0000000..2b225bf --- /dev/null +++ b/survey_event_registration_generation/models/survey_user_input.py @@ -0,0 +1,47 @@ + +import logging +import textwrap +import uuid + +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError +from odoo.tools import float_is_zero + +_logger = logging.getLogger(__name__) + + +class SurveyUserInput(models.Model): + _inherit = 'survey.user_input' + + def save_lines(self, question, answer, comment=None): + old_answers = self.env['survey.user_input.line'].search([ + ('user_input_id', '=', self.id), + ('question_id', '=', question.id) + ]) + if question.question_type == 'event_product': + self._save_event_product(question, old_answers, answer) + elif question.question_type == 'event': + self._save_event(question, old_answers, answer) + else: + return super().save_lines(question, answer, comment) + + + def _save_event_product(self, question, old_answers, answer): + vals = self._get_line_answer_values(question, answer, question.question_type) + vals['value_event_product'] = int(vals['value_event_product']) + if old_answers: + old_answers.write(vals) + return old_answers + else: + return self.env['survey.user_input.line'].create(vals) + + def _save_event(self, question, old_answers, answer): + vals = self._get_line_answer_values(question, answer, question.question_type) + vals['value_event'] = int(vals['value_event']) + if old_answers: + old_answers.write(vals) + return old_answers + else: + return self.env['survey.user_input.line'].create(vals) \ No newline at end of file diff --git a/survey_event_registration_generation/models/survey_user_input_line.py b/survey_event_registration_generation/models/survey_user_input_line.py new file mode 100644 index 0000000..bd7db94 --- /dev/null +++ b/survey_event_registration_generation/models/survey_user_input_line.py @@ -0,0 +1,28 @@ +import logging +import textwrap +import uuid + +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError +from odoo.tools import float_is_zero + + +class SurveyUserInputLine(models.Model): + _inherit = 'survey.user_input.line' + + answer_type = fields.Selection( + selection_add=[('event_product', 'Event product'),('event', 'Event')]) + + value_event = fields.Many2one('event.event', string="Event") + value_event_product = fields.Many2one('product.product', string="Event product") + + def _compute_display_name(self): + super()._compute_display_name() + for line in self: + if line.answer_type == 'event_product': + line.display_name = line.value_event_product.name + elif line.answer_type == 'event': + line.display_name = line.value_event.name + \ No newline at end of file diff --git a/survey_event_registration_generation/static/src/js/survey_form.js b/survey_event_registration_generation/static/src/js/survey_form.js new file mode 100644 index 0000000..cc5d0a4 --- /dev/null +++ b/survey_event_registration_generation/static/src/js/survey_form.js @@ -0,0 +1,24 @@ +odoo.define('survey_event_registration_generation.survey.form', function (require) { +'use strict'; + +var SurveyFormWidget = require('survey.form'); + + +SurveyFormWidget.include({ + + _prepareSubmitValues: function (formData, params) { + var self = this; + + var result = this._super.apply(this, arguments); + this.$('[data-question-type]').each(function () { + if (['event','event_product'].includes($(this).data('questionType'))) { + params[this.name] = this.value; + } + }); + + return result; + }, + +}) + +}); diff --git a/survey_event_registration_generation/views/survey_question_views.xml b/survey_event_registration_generation/views/survey_question_views.xml new file mode 100644 index 0000000..0d25cf4 --- /dev/null +++ b/survey_event_registration_generation/views/survey_question_views.xml @@ -0,0 +1,16 @@ + + + + survey.question + + + + + + + + + + + diff --git a/survey_event_registration_generation/views/survey_templates.xml b/survey_event_registration_generation/views/survey_templates.xml new file mode 100644 index 0000000..6d05c19 --- /dev/null +++ b/survey_event_registration_generation/views/survey_templates.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + diff --git a/survey_event_registration_generation/views/survey_user_input_line_view.xml b/survey_event_registration_generation/views/survey_user_input_line_view.xml new file mode 100644 index 0000000..a2ffdb4 --- /dev/null +++ b/survey_event_registration_generation/views/survey_user_input_line_view.xml @@ -0,0 +1,17 @@ + + + + user.input.value.event.product + survey.user_input.line + + + + + + + + + + +