-
-
Notifications
You must be signed in to change notification settings - Fork 135
[17.0][ADD] survey_question_type_model_selection: new module #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eduezerouali-tecnativa
wants to merge
1
commit into
OCA:17.0
Choose a base branch
from
Tecnativa:17.0-add-survey_question_type_model_selection
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| ==================================== | ||
| Survey model selection question type | ||
| ==================================== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:fe3c2db9a4d30bf585e09ebda06f06903385422b6582e9cd6eec923ed3a86f06 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |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_question_type_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_question_type_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 add Model selection field question type for attach on survey | ||
| page. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Configuration | ||
| ============= | ||
|
|
||
| Once installed from the configuration of the questions, in the options, | ||
| you can select the model to apply and also you can add filters. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/survey/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/survey/issues/new?body=module:%20survey_question_type_model_selection%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * Tecnativa | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - `Tecnativa <https://www.tecnativa.com>`__ | ||
|
|
||
| - 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 <https://odoo-community.org/page/maintainer-role>`__: | ||
|
|
||
| |maintainer-eduezerouali-tecnativa| | ||
|
|
||
| This module is part of the `OCA/survey <https://github.com/OCA/survey/tree/17.0/survey_question_type_model_selection>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import models |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Copyright 2025 Tecnativa - Eduardo Ezerouali | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| { | ||
| "name": "Survey model selection question type", | ||
| "version": "17.0.1.0.0", | ||
| "summary": "This module add model selection field as question type for survey page", | ||
| "author": "Tecnativa, Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/survey", | ||
| "license": "AGPL-3", | ||
| "maintainers": ["eduezerouali-tecnativa"], | ||
| "category": "Marketing/Survey", | ||
| "depends": ["survey"], | ||
| "data": [ | ||
| "views/survey_question_views.xml", | ||
| "views/survey_user_input_line_views.xml", | ||
| "views/survey_template.xml", | ||
| ], | ||
| "assets": { | ||
| "survey.survey_assets": [ | ||
| "survey_question_type_model_selection/static/src/js/survey_form.esm.js", | ||
| "survey_question_type_model_selection/static/src/lib/choices/choices.js", | ||
| "survey_question_type_model_selection/static/src/lib/choices/choices.css", | ||
| ], | ||
| "web.assets_tests": [ | ||
| "survey_question_type_model_selection/static/tests/test_tour_survey_question_model.esm.js", | ||
| ], | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from . import survey_question | ||
| from . import survey_user_input | ||
| from . import survey_user_input_line |
36 changes: 36 additions & 0 deletions
36
survey_question_type_model_selection/models/survey_question.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Copyright 2025 Tecnativa - Eduardo Ezerouali | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| import ast | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class SurveyQuestion(models.Model): | ||
| _inherit = "survey.question" | ||
|
|
||
| question_type = fields.Selection(selection_add=[("model", "Model selection")]) | ||
| question_model_id = fields.Many2one( | ||
| string="Applies to", | ||
| comodel_name="ir.model", | ||
| default=lambda self: self.env["ir.model"]._get_id("res.partner"), | ||
| ondelete="cascade", | ||
| ) | ||
|
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| question_model_name = fields.Char(related="question_model_id.model") | ||
| question_domain = fields.Char(string="Filter Domain") | ||
|
|
||
| def _get_parsed_domain(self): | ||
| """Parse domain string safely into a Python list.""" | ||
| if not self.question_domain: | ||
| return [] | ||
| try: | ||
| domain = ast.literal_eval(self.question_domain) | ||
| return domain if isinstance(domain, list) else [] | ||
| except Exception: | ||
| return [] | ||
|
|
||
| def get_model_options(self): | ||
| """Return Model options filtered by the domain.""" | ||
| self.ensure_one() | ||
| domain = self._get_parsed_domain() | ||
| records = self.env[self.question_model_name].sudo().search(domain) | ||
| return [(rec.id, rec.display_name, rec._name) for rec in records] | ||
32 changes: 32 additions & 0 deletions
32
survey_question_type_model_selection/models/survey_user_input.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # 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 _save_lines(self, question, answer, comment=None, overwrite_existing=True): | ||
| old_answers = self.env["survey.user_input.line"].search( | ||
| [ | ||
| ("user_input_id", "=", self.id), | ||
| ("question_id", "=", question.id), | ||
| ] | ||
| ) | ||
| if question.question_type == "model": | ||
| if not answer: | ||
| answer = False | ||
| else: | ||
| answer = f"{question.question_model_id.model},{answer}" | ||
| self._save_line_simple_answer(question, old_answers, answer) | ||
| else: | ||
| super()._save_lines( | ||
| question, answer, comment=comment, overwrite_existing=overwrite_existing | ||
| ) | ||
| return True | ||
|
|
||
| def _get_line_answer_values(self, question, answer, answer_type): | ||
| res = super()._get_line_answer_values(question, answer, answer_type) | ||
| if answer_type == "model": | ||
| res["value_model"] = answer | ||
| return res |
29 changes: 29 additions & 0 deletions
29
survey_question_type_model_selection/models/survey_user_input_line.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright 2025 Tecnativa - Eduardo Ezerouali | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class SurveyUserInputLine(models.Model): | ||
| _inherit = "survey.user_input.line" | ||
|
|
||
| answer_type = fields.Selection( | ||
| selection_add=[ | ||
| ("model", "Model selection"), | ||
| ] | ||
| ) | ||
| value_model = fields.Reference( | ||
| string="Selection answer", selection="_selection_target_model" | ||
| ) | ||
|
|
||
| def _compute_display_name(self): | ||
| for line in self: | ||
| if line.answer_type == "model": | ||
| line.display_name = line.value_model.display_name | ||
| return super()._compute_display_name() | ||
|
|
||
| @api.model | ||
| def _selection_target_model(self): | ||
| return [ | ||
| (model.model, model.name) | ||
| for model in self.env["ir.model"].sudo().search([]) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Once installed from the configuration of the questions, in the options, | ||
| you can select the model to apply and also you can add filters. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - [Tecnativa](https://www.tecnativa.com) | ||
| - Eduardo Ezerouali | ||
| - Carlos López |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| This module add Model selection field question type for attach on survey page. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take into account that if a user does not have permission to read

ir.model(the group required to grant this access isAdministration / Access Rights), they will get an error when trying to add a new question.