İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
11279 Görünümler

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

Avatar
Vazgeç
En İyi Yanıt

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
Avatar
Vazgeç

Thanks-a-million, Axel. This helped me today!

Hello Dave,

It will work, the mistake you did is you are passing wrong values to one2many field.

I hope you understood what's the mistake you did.

İlgili Gönderiler Cevaplar Görünümler Aktivite
3
Tem 25
22235
0
Eyl 23
144
1
May 20
3336
2
Oca 24
16383
1
Ağu 17
3802