这是我的函数create():
api.model
def set_student_level(self):
for record in self:
if record.student_ids:
for student in record.student_ids:
update_student_ids = self.env['ecole.partner.school'].browse(self.env.context.get('active_ids'))
if update_student_ids:
for rec in update_student_ids:
partner = update_student_ids.partner_id.id
school_year = update_student_ids.school_year.id
school_name = update_student_ids.school_name.id
school_level = update_student_ids.school_level.id
half_pension = update_student_ids.half_pension
half_pension_name = update_student_ids.half_pension_name.id
half_pension_begin_date = update_student_ids.half_pension_begin_date
half_pension_end_date = update_student_ids.half_pension_end_date
nursery = update_student_ids.nursery
nursery_name = update_student_ids.nursery_name.id
nursery_begin_date = update_student_ids.nursery_begin_date
nursery_end_date = update_student_ids.nursery_end_date
#Ecriture en dur dans la BDD
vals = {'partner_id': partner,
'school_year': school_year,
'school_name': school_name,
'school_level': school_level,
'half_pension': half_pension,
'half_pension_name': half_pension_name,
'half_pension_begin_date': half_pension_begin_date,
'half_pension_end_date': half_pension_end_date,
'nursery': nursery,
'nursery_name': nursery_name,
'nursery_begin_date': nursery_begin_date,
'nursery_end_date': nursery_end_date}
res = update_student_ids.create(vals)
return res
我的问题是,当我选择一条记录并单击按钮set_student_level
时,插入将在数据库中起作用。但是,当我选择多个记录时,出现错误(ValueError: Expected singleton: school.partner.school (15, 68))
。
答案 0 :(得分:0)
这里update_student_ids
将是一组记录。因此您应在for循环中将update_student_ids
替换为rec
。
例如:
for rec in update_student_ids:
partner = rec.partner_id.id
...