This question has been flagged
6 Replies
5586 Views

Dears,

During the survey, I need to add a "functionnal field", that computes a value based on other fields value.

For example, I have a question (Matrix type), and I want to perform such action during the survey (please copy/paste the link below):

http://prntscr.com/8yar4b

Is it possible to perform such developpement on a survey ?

Any hints, propositions will be welcome guys.

I have some ideas to share, your toughts interest me a lot.

Thanks.

Avatar
Discard
Author

Thanks Axel for your answer. It's very interesting. In my case, the survey module has no Qweb reports, it's based on generated Qweb templates. My goal is to compute the values and store them in the database, so as to use them on the survey dashboard. To be more precise, I'm developping a very specific human ressources appraisals, and the purpose is to compute values based on other fields value to give the hr manager, after the evaluation, an idea about the reaching goals percentage, defined last year. Therefore, once the evaluation is finished, the manager should be able to print these computed values, and also have them on his dashboard. Is it possible to do such developpement using javascript functions ? How could it be stored on the database then ? ( I would like to know more about what happens on server side when the evaluation form is sent). Thanks a lot for your answers.

Author Best Answer

Axel, The main problem for me, is that I'm obligated to print the computation, that's why I'm looking for a solution to compute and show results on the qweb template, if only there is a way to collect data, compute on the background via a functionnal field, and show computation results via a new qweb report (survey answers), it will be a great solution. What do you think of mi idea ? do you think is technically doable ? 

Avatar
Discard

There are 3 ways for using qweb templates,2 that matters for your situation, one for reports and the other for website pages, I'm doing deep stuffs inside qweb templates and their components these days, maybe if you show me some code of what you are doing or images of what you need, then I could figure out better your situation and could help you

If you will share some code, better upload to a github repo in the form of a module so I can install it and test it

Best Answer

From my point of view the best way to solve this is by doing the computation in a parser method that return the list of rows to display and iterate that list in the qweb report template. An example for your image

def crosstab(self, values):
    crosstab = []
headers = ('','Col 1', 'Col 2')
crosstab.append(headers)
    crosstab.append(('Line 1', 'Value (1,1)', 'Value (1,2)'))
crosstab.append(('Line 2', 'Value (2,1)', 'Value (2,2)'))
#calculate the rest of the lines or the previous to add the result to the list
crosstab.append(('Line 1', 'Value (1,1)', 'Value (1,2)'))

    return crosstab

Use like this in the qweb report template:

<table class="table table-bordered">
<t t-foreach="crosstab(value)" t-as="row">
    <tr>
<t t-foreach="row" t-as="measure">
        <td t-esc="measure"/>
      </t>
    </tr>
</t>
</table>

Change value to what you need to pass to the report function as an argument or pass more or less arguments depending of what you need to use to compute the crosstab table measures

Here is how to add functions in the parser, config the parser and use it on the qweb report template:

https://www.odoo.com/es_ES/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

Avatar
Discard

Do you means that your surveys are website templates? and you need the same as I described but for the website templates?

Author

Yes the surveys are website templates (Qweb), Yes I need some solution to compute the values entered by the user, and after the survey is sent, store it to the database, because I'll need it after for hr appraisals dashboards.

Author

Please take a look at : survey/views/survey_templates.xml there is all templates rendered during the survey user experience. I did some specific developpement on the matrix template, by extending its behavior ... I'm available if you want further explainations.