콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
11219 화면

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

아바타
취소
베스트 답변

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
아바타
취소

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.

관련 게시물 답글 화면 활동
3
7월 25
22096
0
9월 23
144
1
5월 20
3243
2
1월 24
16206
1
8월 17
3732