Skip to content

[17.0][ADD] survey_question_type_model_selection: new module - #209

Merged
OCA-git-bot merged 1 commit into
OCA:17.0from
Tecnativa:17.0-add-survey_question_type_model_selection
Jul 15, 2026
Merged

[17.0][ADD] survey_question_type_model_selection: new module#209
OCA-git-bot merged 1 commit into
OCA:17.0from
Tecnativa:17.0-add-survey_question_type_model_selection

Conversation

@eduezerouali-tecnativa

Copy link
Copy Markdown

This module extends the Survey question types by introducing a new question type that allows selecting records from any model, with configurable domain filters. This makes it possible to display dynamic, filtered model-based selections directly within surveys.

@Tecnativa TT59700

ping @pilarvargas-tecnativa @carlos-lopez-tecnativa @pedrobaeza

@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch from 6a9e1c1 to 433d4bc Compare December 16, 2025 12:24
@pedrobaeza pedrobaeza added this to the 17.0 milestone Dec 17, 2025
@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 2 times, most recently from a197d13 to 366a795 Compare December 18, 2025 14:32
@pilarvargas-tecnativa

Copy link
Copy Markdown

It's perfect, except that even though the answers are correctly stored in the participation section, when you go to the review in the survey itself, you can't see them, only the questions.

image

For this, I want to remind you that you must add them to the view that is printed because, if I'm not mistaken, it checks the types to style them.

@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 2 times, most recently from 5b5422e to 82e6168 Compare December 31, 2025 10:24
@eduezerouali-tecnativa

Copy link
Copy Markdown
Author

You are right. Now is displaying correctly. Thank you for your review.
Selección_046

@pedrobaeza

Copy link
Copy Markdown
Member

ping @pilarvargas-tecnativa

@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 2 times, most recently from 613de04 to a60e05b Compare March 6, 2026 15:18
"survey_id": cls.survey.id,
"title": "State",
"question_type": "model",
"question_model_id": 81,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does ID 81 correspond to? I think you should use the _get function instead of hardcoding the ID here,
like the default value self.env["ir.model"]._get_id("model.name").

<div
class="col-sm-12 o_survey_choice_btn py-1 px-3 w-100 h-100 rounded mb-3"
>
<span t-out="answer_lines[0].value_model.display_name or None" />

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this error when trying to print the survey.
Image

Image Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already fix, now it manages if it has no answer.

Comment on lines +17 to +19
setTimeout(() => this._initAllInputs(), 100);
setTimeout(() => this._initAllInputs(), 500);
setTimeout(() => this._initAllInputs(), 1000);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we do the same thing with different intervals. Could you add a better comment or docstring?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really need it, it is done in this._setupObserver(); ,we need init the selection. becuse when DOM is display first time it is not load. I don't know if there is a more practical way of implementing it.

errorMsg.style.fontSize = "0.875rem";
errorMsg.style.marginTop = "0.25rem";
errorMsg.style.display = "none";
errorMsg.textContent = "Please select a valid option from the list";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this text can be translated.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it can be translated

@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 3 times, most recently from bc6ae2e to 6b79df2 Compare March 20, 2026 16:58
@eduezerouali-tecnativa

Copy link
Copy Markdown
Author

@carlos-lopez-tecnativa thanks to take the time for review this PR. I did attend your comments. It is ready for review again. Thank you.

Comment on lines +20 to +31
if (!applySurveyPatch()) {
let attempts = 0;
const maxAttempts = 50;
const interval = setInterval(() => {
attempts++;
if (applySurveyPatch()) {
clearInterval(interval);
} else if (attempts >= maxAttempts) {
clearInterval(interval);
}
}, 100);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Could you add a docstring to explain the reason for this code? It is not clear to me.
I imagine the DOM is not ready yet, but what is the actual reason?

import publicWidget from "@web/legacy/js/public/public_widget";

publicWidget.registry.SurveyModelInput = publicWidget.Widget.extend({
selector: ".js_surveyform, .o_survey_form, body",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if this code is loaded correctly. I attached a video where, if I start the survey from the test (or more specifically, if it displays the main page before starting the survey), it works fine. However, when I start the survey from a link from the Share wizard, it does not display the main page. The first question is loaded, but the input does not display the options. I suspect it is not loading correctly. Please take a look.

survey_question_type_model_selection.mp4

@carlos-lopez-tecnativa

Copy link
Copy Markdown

I see the code adds a feature to allow the user to select options, similar to a many2one field, which is nice, but what is the reason for implementing this here? Could an external library be used instead, such as Choices.js or Tom Select, etc?

@pedrobaeza

Copy link
Copy Markdown
Member

For such simple feature, it's better to not add such maintenance burden.

@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch from 6b79df2 to 6f30609 Compare April 22, 2026 09:05
@OCA-git-bot OCA-git-bot added mod:survey_question_type_model_selection Module survey_question_type_model_selection series:17.0 labels Apr 22, 2026
@eduezerouali-tecnativa

Copy link
Copy Markdown
Author

Add choices to it. Main changes apply:

  • Add choices lib.
  • survey_form.esm.js add choices + remove unnecessary code.
  • Templates match new select.
  • Tours adapted to select.

Changes do not affect following PR #210 #211
Also add @carlos-lopez-tecnativa as contributor as main reviewer.

please @pilarvargas-tecnativa @carlos-lopez-tecnativa could you review.

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested functionally; it works. I left some technical comments to prevent mistakes.

Regarding the new library, it works fine, thanks. I didn’t request this as a change; it was just a question. If you decide to use an external library, that’s OK for me. Let’s see what @pedrobaeza thinks about this 😅

Comment on lines +12 to +17
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",
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a domain to prevent selecting models such as TransientModel and AbstractModel.

Because if a user selects a model like mail.thread, this causes an error in the frontend, and the domain is evaluated incorrectly.

Image Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_inherit = "survey.question"

question_type = fields.Selection(selection_add=[("model", "Model selection")])
question_model_id = fields.Many2one(

Copy link
Copy Markdown

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 is Administration / Access Rights), they will get an error when trying to add a new question.
Image

Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@pedrobaeza

Copy link
Copy Markdown
Member

Yes, adding a JS library if there are more reasonable options is not the first choice (wordplay with the library name, hehe), and more if there are license incompatibilities (don't know the library license). What is that library bringing?

@eduezerouali-tecnativa
eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch from 6f30609 to 473f349 Compare July 13, 2026 10:49
@eduezerouali-tecnativa

Copy link
Copy Markdown
Author

@carlos-lopez-tecnativa @pilarvargas-tecnativa could you review please?

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 17.0-ocabot-merge-pr-209-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

@pedrobaeza your merge command was aborted due to failed check(s), which you can inspect on this commit of 17.0-ocabot-merge-pr-209-by-pedrobaeza-bump-nobump.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 17.0-ocabot-merge-pr-209-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

@pedrobaeza The merge process could not be finalized, because command twine upload --disable-progress-bar --non-interactive --repository-url https://upload.pypi.org/legacy/ -u __token__ odoo_addon_survey_question_type_model_selection-17.0.1.0.0.2-py3-none-any.whl failed with output:

Uploading distributions to https://upload.pypi.org/legacy/
Uploading 
odoo_addon_survey_question_type_model_selection-17.0.1.0.0.2-py3-none-any.whl
�[33mWARNING �[0m Error during upload. Retry with the --verbose option for more details. 
�[31mERROR   �[0m HTTPError: 429 Too Many Requests from https://upload.pypi.org/legacy/  
         Too Many Requests                                                      

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 17.0-ocabot-merge-pr-209-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

@pedrobaeza The merge process could not be finalized, because command twine upload --disable-progress-bar --non-interactive --repository-url https://upload.pypi.org/legacy/ -u __token__ odoo_addon_survey_question_type_model_selection-17.0.1.0.0.2-py3-none-any.whl failed with output:

Uploading distributions to https://upload.pypi.org/legacy/
Uploading 
odoo_addon_survey_question_type_model_selection-17.0.1.0.0.2-py3-none-any.whl
�[33mWARNING �[0m Error during upload. Retry with the --verbose option for more details. 
�[31mERROR   �[0m HTTPError: 429 Too Many Requests from https://upload.pypi.org/legacy/  
         Too Many Requests                                                      

@pedrobaeza

Copy link
Copy Markdown
Member

@sbidoul there's no way to get this merged (among others). Please create manually the project.

@sbidoul

sbidoul commented Jul 15, 2026

Copy link
Copy Markdown
Member

Done. Please retry the merge.

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 17.0-ocabot-merge-pr-209-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 3e96d41 into OCA:17.0 Jul 15, 2026
5 of 7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 94676b9. Thanks a lot for contributing to OCA. ❤️

@pedrobaeza
pedrobaeza deleted the 17.0-add-survey_question_type_model_selection branch July 15, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants