diff --git a/survey_crm_generation_model_selection/README.rst b/survey_crm_generation_model_selection/README.rst new file mode 100644 index 00000000..58af8412 --- /dev/null +++ b/survey_crm_generation_model_selection/README.rst @@ -0,0 +1,87 @@ +========================================= +Survey CRM generation for model selection +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1ed70ed2baad9fdb72626d6449dca767166a726a4ab008b85ce8c5959be52662 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/17.0/survey_crm_generation_model_selection + :alt: OCA/survey +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/survey-17-0/survey-17-0-survey_crm_generation_model_selection + :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=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to generate new lead from surveys answers from +question type model selection. + +**Table of contents** + +.. contents:: + :local: + +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 `__ + + - Eduardo Ezerouali + +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-eduezerouali-tecnativa| image:: https://github.com/eduezerouali-tecnativa.png?size=40px + :target: https://github.com/eduezerouali-tecnativa + :alt: eduezerouali-tecnativa + +Current `maintainer `__: + +|maintainer-eduezerouali-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_crm_generation_model_selection/__init__.py b/survey_crm_generation_model_selection/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/survey_crm_generation_model_selection/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/survey_crm_generation_model_selection/__manifest__.py b/survey_crm_generation_model_selection/__manifest__.py new file mode 100644 index 00000000..f09cc0f4 --- /dev/null +++ b/survey_crm_generation_model_selection/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Tecnativa - Eduardo Ezerouali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Survey CRM generation for model selection", + "summary": "Generate new leads from surveys using model selection", + "version": "17.0.1.0.0", + "category": "Marketing/Survey", + "website": "https://github.com/OCA/survey", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["eduezerouali-tecnativa"], + "license": "AGPL-3", + "depends": ["survey_crm_generation", "survey_question_type_model_selection"], + "assets": { + "web.assets_tests": [ + "survey_crm_generation_model_selection/static/tests/tour_crm_generation_model.esm.js" + ], + }, + "auto_install": True, +} diff --git a/survey_crm_generation_model_selection/models/__init__.py b/survey_crm_generation_model_selection/models/__init__.py new file mode 100644 index 00000000..b5635ae6 --- /dev/null +++ b/survey_crm_generation_model_selection/models/__init__.py @@ -0,0 +1,2 @@ +from . import survey_question +from . import survey_user_input diff --git a/survey_crm_generation_model_selection/models/survey_question.py b/survey_crm_generation_model_selection/models/survey_question.py new file mode 100644 index 00000000..a17327e4 --- /dev/null +++ b/survey_crm_generation_model_selection/models/survey_question.py @@ -0,0 +1,20 @@ +# Copyright 2025 Tecnativa - Eduardo Ezerouali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class SurveyQuestion(models.Model): + _inherit = "survey.question" + + @api.depends("question_type") + def _compute_allowed_crm_lead_field_domain(self): + res = super()._compute_allowed_crm_lead_field_domain() + for record in self: + if record.question_type == "model": + record.allowed_partner_field_domain = [ + ("model", "=", "crm.lead"), + ("ttype", "in", ["many2one", "many2many"]), + ("store", "=", True), + ("readonly", "=", False), + ] + return res diff --git a/survey_crm_generation_model_selection/models/survey_user_input.py b/survey_crm_generation_model_selection/models/survey_user_input.py new file mode 100644 index 00000000..5482b2f8 --- /dev/null +++ b/survey_crm_generation_model_selection/models/survey_user_input.py @@ -0,0 +1,17 @@ +# Copyright 2025 Tecnativa - Eduardo Ezerouali +# 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_opportunity(self): + res = super()._prepare_opportunity() + for key, value in res.items(): + if isinstance(value, models.BaseModel): + if len(value) == 1: + res[key] = value.id + else: + res[key] = [(6, 0, value.ids)] + return res diff --git a/survey_crm_generation_model_selection/pyproject.toml b/survey_crm_generation_model_selection/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/survey_crm_generation_model_selection/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/survey_crm_generation_model_selection/readme/CONTRIBUTORS.md b/survey_crm_generation_model_selection/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..4462ed21 --- /dev/null +++ b/survey_crm_generation_model_selection/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Tecnativa](https://www.tecnativa.com) + - Eduardo Ezerouali diff --git a/survey_crm_generation_model_selection/readme/DESCRIPTION.md b/survey_crm_generation_model_selection/readme/DESCRIPTION.md new file mode 100644 index 00000000..351e3f15 --- /dev/null +++ b/survey_crm_generation_model_selection/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to generate new lead from surveys answers from question type model selection. diff --git a/survey_crm_generation_model_selection/static/description/index.html b/survey_crm_generation_model_selection/static/description/index.html new file mode 100644 index 00000000..274f7b37 --- /dev/null +++ b/survey_crm_generation_model_selection/static/description/index.html @@ -0,0 +1,429 @@ + + + + + +Survey CRM generation for model selection + + + +
+

Survey CRM generation for model selection

+ + +

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

+

This module allows to generate new lead from surveys answers from +question type model selection.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

eduezerouali-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_crm_generation_model_selection/static/tests/tour_crm_generation_model.esm.js b/survey_crm_generation_model_selection/static/tests/tour_crm_generation_model.esm.js new file mode 100644 index 00000000..0ebf01ab --- /dev/null +++ b/survey_crm_generation_model_selection/static/tests/tour_crm_generation_model.esm.js @@ -0,0 +1,50 @@ +/** @odoo-module */ + +import {registry} from "@web/core/registry"; + +registry.category("web_tour.tours").add("test_survey_crm_question_model", { + test: true, + url: "/survey/start/b137640d-14d4-4748-9ef6-344caaaaaafff", + steps: () => [ + { + content: "Start Survey", + trigger: "button.btn:contains('Start Survey')", + run: "click", + }, + { + content: "Name", + trigger: + "div.js_question-wrapper:contains('Name') input, div.js_question-wrapper:contains('Name') textarea", + run: "text Tecnativa", + }, + { + content: "Email", + trigger: + "div.js_question-wrapper:contains('Email') input, div.js_question-wrapper:contains('Email') textarea", + run: "text test@test.com", + }, + { + content: "Open dropdown", + trigger: ".choices, .choices__inner", + run: "click", + }, + + // WAIT OPTION LIST (no separate waiting-only step) + { + content: "Select option 62", + trigger: ".choices__list--dropdown .choices__item--choice[data-value='62']", + run: "click", + extra_trigger: + ".choices__list--dropdown.is-active, .choices__list--dropdown", + }, + { + content: "Click Submit", + trigger: "button[value='finish']", + run: "click", + }, + { + content: "Thank you", + trigger: "div.o_survey_finished", + }, + ], +}); diff --git a/survey_crm_generation_model_selection/tests/__init__.py b/survey_crm_generation_model_selection/tests/__init__.py new file mode 100644 index 00000000..50b3d17d --- /dev/null +++ b/survey_crm_generation_model_selection/tests/__init__.py @@ -0,0 +1 @@ +from . import test_crm_generation_model diff --git a/survey_crm_generation_model_selection/tests/test_crm_generation_model.py b/survey_crm_generation_model_selection/tests/test_crm_generation_model.py new file mode 100644 index 00000000..82fefe4b --- /dev/null +++ b/survey_crm_generation_model_selection/tests/test_crm_generation_model.py @@ -0,0 +1,83 @@ +# Copyright 2026 Tecnativa - Eduardo Ezerouali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from markupsafe import Markup + +from odoo import Command +from odoo.tests import HttpCase, tagged + +from odoo.addons.base.tests.common import BaseCommon + + +@tagged("-at_install", "post_install") +class SurveyCrmGenerationCase(BaseCommon, HttpCase): + @classmethod + def setUpClass(cls): + """We run the tour in the setup so we can share the tests case with other + modules""" + super().setUpClass() + cls.reference = cls.env["res.partner"].create({"name": "Reference Partner"}) + cls.tag_lead = cls.env["crm.tag"].create({"name": "Survey"}) + cls.tag_lead_partnership = cls.env["crm.tag"].create({"name": "Partnership"}) + cls.team_partnership = cls.env["crm.team"].create({"name": "Partnership"}) + cls.survey = cls.env["survey.survey"].create( + { + "title": "Become Partner", + "survey_type": "custom", + "questions_layout": "one_page", + "access_mode": "public", + "access_token": "b137640d-14d4-4748-9ef6-344caaaaaafff", + "crm_team_id": cls.team_partnership.id, + "crm_tag_ids": [ + Command.set([cls.tag_lead.id, cls.tag_lead_partnership.id]) + ], + "generate_leads": True, + } + ) + cls.question = cls.env["survey.question"].create( + { + "survey_id": cls.survey.id, + "title": "Name", + "question_type": "char_box", + "show_in_lead_description": True, + } + ) + cls.question = cls.env["survey.question"].create( + { + "survey_id": cls.survey.id, + "title": "Email", + "question_type": "char_box", + "show_in_lead_description": True, + } + ) + cls.question = cls.env["survey.question"].create( + { + "survey_id": cls.survey.id, + "title": "Country", + "question_type": "model", + "question_model_id": cls.env["ir.model"]._get_id("res.country"), + "crm_lead_field": cls.env.ref("crm.field_crm_lead__country_id").id, + } + ) + + def test_lead_generation(self): + self.start_tour( + f"/survey/start/{self.survey.access_token}", + "test_survey_crm_question_model", + login="portal", + ) + self.generated_lead = self.survey.user_input_ids.opportunity_id + self.assertFalse(self.generated_lead.stage_id.is_won) + self.assertEqual(self.generated_lead.team_id, self.team_partnership) + self.assertEqual( + self.generated_lead.tag_ids, + (self.tag_lead + self.tag_lead_partnership), + ) + expected_lead_description = Markup( + "
  • Name: Tecnativa
  • " + "
  • Email: test@test.com
  • " + ) + self.assertEqual( + self.generated_lead.description, + expected_lead_description, + ) + self.assertEqual(self.generated_lead.country_id.name, "Algeria") diff --git a/test-requirements.txt b/test-requirements.txt index 66bc2cba..e515c6a6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ odoo_test_helper +odoo-addon-survey_question_type_model_selection @ git+https://github.com/OCA/survey.git@refs/pull/209/head#subdirectory=survey_question_type_model_selection