Odoo Help


Survey Module developpement : How to Prefill survey answers for a New Matrix type question ?

Yassine TEIMI
on 11/7/15, 8:59 AM 548 views

What I did is creating a new matrix type called 'tableau' (technical name : matrix_subtype), the idea behind is to give the matrix question the possibility to enter text, and combine text and radio button (or checkboxes). while it's only possible by default, to tick checkboxes, and radio buttons as answer.

So when choosing the matrix as a question type, I have three possibilities :

1. Once choice per row : And I create matrix columns (Row answers), so it creates radio buttons, and I can create text fields also for comment purpose, by ticking "comment tag" ( a new field I created ) :

Images intégrées 1

So In this case (Ticking comment tag) I've the follwing layout :

Images intégrées 2

2. Multiple choices per row : And it creates checkboxes, and If I tick comment tag, it creates the same layout, on the precedent image. (difference is checkboxes instead of radio buttons).

3. Board : and it gives me the following layout ( All text fields ) :

Images intégrées 3

The problem is when I send the survey, the prefill function (the one reponsible of filling the survey answers when trying to print, or visualize them) doesn't take into consideration, the text fields answers filled by the user, on matrix type question 'board' and 'comment columns'. I have to create this scenario, so as the function take it into consideration.

Here after the most interesting part on the prefill function :

for answer in previous_answers: 
if not answer.skipped:
answer_tag = '%s_%s_%s' % (answer.survey_id.id, answer.page_id.id, answer.question_id.id)
answer_value = None
if answer.answer_type == 'free_text':
answer_value = answer.value_free_text
elif answer.answer_type == 'text' and answer.question_id.type == 'textbox':
answer_value = answer.value_text
elif answer.answer_type == 'text' and answer.question_id.type != 'textbox':
# here come comment answers for matrices, simple choice and multiple choice
answer_tag = "%s_%s" % (answer_tag, 'comment')
answer_value = answer.value_text
elif answer.answer_type == 'number':
answer_value = answer.value_number.__str__()
elif answer.answer_type == 'date':
answer_value = answer.value_date
elif answer.answer_type == 'suggestion' and not answer.value_suggested_row:
answer_value = answer.value_suggested.id
elif answer.answer_type == 'suggestion' and answer.value_suggested_row:
answer_tag = "%s_%s" % (answer_tag, answer.value_suggested_row.id)
answer_value = answer.value_suggested.id

This is actually the second problem I'm facing with the creation of a new matrix type, the first one was that the user inputs weren't stored on database after form submit, but when extenhe datading the submit function behavior, it works fine, there is some littles fixes to do, but I'm on the right way.

Now all data coming from the matrix type 'tableau', or data coming from the 2 other scenarios I described at the first of my email, is not prefilled when I try to visualize data, or print the survey.

What I need to do is to find a way to collect answers data (the one stored on database).

Thanks a lot for your help.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/7/15, 8:59 AM
Seen: 548 times
Last updated: 11/7/15, 8:59 AM