Odoo Help

Welcome!

This community 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.

0

How to pass data to a view using default_get function in odoo v9?

By
manuthalasseril
on 11/30/15, 7:39 AM 964 views

I rewrite a function called default_get

class open_questionnaire_line(osv.osv_memory):
_name = 'open.questionnaire.line'
_rec_name = 'question_id'
_columns = {
'question_id': fields.many2one('crm_profiling.question','Question', required=True),
'answer_id': fields.many2one('crm_profiling.answer', 'Answer'),
'wizard_id': fields.many2one('open.questionnaire', 'Questionnaire'),
}


class open_questionnaire(osv.osv_memory):
_name = 'open.questionnaire'
_columns = {
'questionnaire_id': fields.many2one('crm_profiling.questionnaire', 'Questionnaire name'),
'question_ans_ids': fields.one2many('open.questionnaire.line', 'wizard_id', 'Question / Answers'),
}

def default_get(self, cr, uid, fields, context=None):
if context is None: context = {}
res = super(open_questionnaire, self).default_get(cr, uid, fields, context=context)
questionnaire_id = context.get('questionnaire_id', False)
if questionnaire_id and 'question_ans_ids' in fields:
query = """
select question as question_id from profile_questionnaire_quest_rel where questionnaire = %s"""
cr.execute(query, (questionnaire_id,))
result = cr.dictfetchall()
res.update(question_ans_ids=result)
return res

and in my view

 <record id="open_questionnaire_form" model="ir.ui.view">
<field name="name">open.questionnaire.form</field>
<field name="model">open.questionnaire</field>
<field name="arch" type="xml">
<form string="Open Questionnaire">
<separator colspan="4" string="Questionnaire"/>
<field name="question_ans_ids" colspan="4" nolabel="1" mode="tree" width="550" height="200"/>
<footer>
<button name="questionnaire_compute" string="Save Data" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>

But it gives me an error

Error: send_commands to 'question_ans_ids' receive a non command value.

[{"question_id":4},{"question_id":3},{"question_id":2},{"question_id":1}]

How can I overcome this error.

Note : This module is the exact copy of crm_profiling (working in v8 and available only for v8). But now I trying it to rewrite in v9.

Please help

1

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/1/15, 3:42 PM

That's because you need to put the values in the write format expected for that kind of field. Change the method like this:

    def default_get(self, cr, uid, fields, context=None):
if context is None: context = {}
res = super(open_questionnaire, self).default_get(cr, uid, fields, context=context)
questionnaire_id = context.get('questionnaire_id', False)
if questionnaire_id and 'question_ans_ids' in fields:
query = """
select question as question_id from profile_questionnaire_quest_rel where questionnaire = %s"""
cr.execute(query, (questionnaire_id,))
result = cr.dictfetchall()
res.update(question_ans_ids=[(4,elem) for elem in result])
return res

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 11/30/15, 7:39 AM
Seen: 964 times
Last updated: 12/1/15, 3:42 PM