Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3261 มุมมอง

Hello,

I am creating custom model that inherit other two models. In that I have created onchange method for page_ids.page_ids is one2many field in survey.survey But after trying to create page from one2many field it gives me following error:


  File "/usr/local/sampada/survey-workspace/spn/custom/survey_inherit/model/survey_create.py", line 22, in onchange_question
    for i in self.page_ids.questions_id:
  File "/usr/local/sampada/survey-workspace/spn/odoo/fields.py", line 987, in __get__
    record.ensure_one()
  File "/usr/local/sampada/survey-workspace/spn/odoo/models.py", line 4724, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: survey.page(<odoo.models.NewId object at 0x7f177adb31f8>, <odoo.models.NewId object at 0x7f177adb3678>)


  py file:

from odoo import models,fields, api


class SurveyCreate(models.Model):

_name = 'survey.survey'

_inherit = ['survey.survey','survey.question']

@api.multi

@api.onchange('page_ids')

def onchange_question(self):

for i in self.page_ids.questions_id:

self.question = i.question

self.type = i.type

print('question:',self.question)

print('type:',self.type)


can any one please help me. 

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Try this,

def onchange_question(self):
for i in self.page_ids.mapped('questions_id'):
self.question = i.question
self.type = i.type

Thanks

อวตาร
ละทิ้ง
ผู้เขียน

@Niyas Thanks for answer , The solution provide by you not work. As mapped return list of quetions_id still not working.

are you sure from the field name is questions_id or question_ids

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.พ. 20
3641
How to track One2many field in Odoo12? แก้ไขแล้ว
3
พ.ย. 23
17276
Error: Couldn't load module web แก้ไขแล้ว
3
พ.ย. 24
24861
How I get the current ID of a record ? แก้ไขแล้ว
1
เม.ย. 23
6050
2
ธ.ค. 22
6757