This question has been flagged
4 Replies
3332 Views

i got this error

ValueError: Expected singleton: regular.data(1, 2, 3, 4, 5, 8)
can anybody tell me
py file:
@api.multi
@api.onchange('regulation')
def onchange_get_faileddata(self):

stud_list = []
stud_obj = self.env['regulardata.form']
for rec in self:
if rec.regulation:

stud_list =[{'subject_code': stu.regular.subject_code,'subject_name': stu.regular.subject_name,'subject_type':stu.regular.subject_type}
for stu in stud_obj.search([ ('course_id','=',rec.course_id),('year', '=',rec.year),('semester_id','=', rec.semester_id),

])]

rec.supply_data = stud_list
Avatar
Discard
Best Answer

Hope it works



@api.multi
@api.onchange('regulation')
def onchange_get_faileddata(self):
stud_list = []
stud_obj = self.env['regulardata.form']
for rec in self:
if rec.regulation:
stud_lines = stud_obj.search([ ('course_id','=',rec.course_id),('year', '=',rec.year),('semester_id','=', rec.semester_id)])
for stu in stud_lines:
stud_vals = {'subject_code': stu.regular.subject_code,'subject_name': stu.regular.subject_name,'subject_type':stu.regular.subject_type}
stud_list.append(stud_vals)

rec.supply_data = stud_list #note:supply_data = fields.One2many('your.model', 'inverse_fiels', string="your string")
else:
rec.supply_data = False #note:supply_data = fields.One2many('your.model', 'inverse_fiels', string="your string")


Avatar
Discard
Author

same error shown rakesh

raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: regular.data(6, 7)

Best Answer

I think   stu.regular   having  multiple records     stu.regular.subject_code and other fields from the stu.regular  getting error, if it is single object it will work 

in your case Expected singleton: regular.data(1, 2, 3, 4, 5, 8) because stu.regular=regular.data(1, 2, 3, 4, 5, 8)
you can't read data from multiple objects at a time

you have to loop it.

Avatar
Discard
Author

i tried like this subbarao

@api.multi

@api.onchange('regulation')

def onchange_get_passeddata(self):

stud_list = []

stud_obj = self.env['regulardata.form'].search([('course_id','=',self.course_id),('year', '=',self.year),('semester_id','=', self.semester_id)])

if self.regulation:

for stu in stud_obj:

for sub in stu.regular:

stud_list= [{'subject_code': sub.subject_code,'subject_name': sub.subject_name,'subject_type':sub.subject_type}]

self.regular_data = stud_list

error was cleared even though doesnot display values

if possible to give your full code related this question, fields declaration i have to check

finally what do you want (which output your expecting)

Author

regular_data.py:

class regulardataform(models.Model):

_name='regulardata.form'

_description='regular data'

name = fields.Char('Subject Name')

regulation = fields.Many2one('student.regulation','regulation')

course_id=fields.Selection([('mba','MBA'),('mca','MCA'),('btech','Btech')],'Course',required=True)

year=fields.Selection([('one','1'),('two','2')],'Year',required=True)

semester_id=fields.Selection([('one','1'),('two','2')],'Semester',required=True)

regular=fields.One2many('regular.data','regular_data')

class regulardata(models.Model):

_name='regular.data'

_description='Regular Data'

subject_code = fields.Char('Subject Code')

subject_name = fields.Char('Subject Name')

subject_type = fields.Char('Subject Type')

regular_data=fields.Many2one('regulardata.form','regulardata')

In this table have these data(subject code,subject name, subject typpe)

regular_single_entry.py:

class regularsingle(models.Model):

_name='regular.single'

_description='Student registration'

name=fields.Selection([('regular','Regular'),('supply','Supply')],'Exam Type',required=True)

course_id=fields.Selection([('mba','MBA'),('mca','MCA'),('btech','Btech')],'Course',required=True)

year=fields.Selection([('one','1'),('two','2')],'Year',required=True)

semester_id=fields.Selection([('one','1'),('two','2')],'Semester',required=True)

regulation=fields.Many2one('student.regulation','regulation',required=True)

hallticket_no = fields.Char('HallTicket Number')

regular_data=fields.One2many('page.regular','regular_data1')

@api.multi

@api.onchange('regulation')

def onchange_get_passeddata(self):

stud_list = []

stud_obj = self.env['regulardata.form'].search([('course_id','=',self.course_id),('year', '=',self.year),('semester_id','=', self.semester_id)])

if self.regulation:

for stu in stud_obj:

for sub in stu.regular:

stud_list= [{'subject_code': sub.subject_code,'subject_name': sub.subject_name,'subject_type':sub.subject_type}]

self.regular_data = stud_list

class regularregistration(models.Model):

_name='page.regular'

_description='Regular registration'

subject_code = fields.Char('Subject Code')

subject_name = fields.Char('Subject Name')

subject_type = fields.Char('Subject Type')

regular_data1=fields.Many2one('regular.single','regulardata')

when i select regulation froom dropdown get the data from regular.data