Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3181 Widoki

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. 

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

@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

Powiązane posty Odpowiedzi Widoki Czynność
2
lut 20
3570
3
lis 23
17185
3
lis 24
24656
1
kwi 23
5976
2
gru 22
6660