Skip to Content
Menu
This question has been flagged
2 Replies
2324 Views

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. 

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

@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 Replies Views Activity
2
Feb 20
2750
3
Nov 23
15312
3
Nov 24
21082
1
Apr 23
4573
2
Dec 22
5499