简体   繁体   中英

how to use create() orm methode with loop ? odoo10

I want to create a year and subscribe a student in it by using the orm method create() . I tried this way, but I don't think this how to do it. I use Odoo 10(new API).

class InsYear(models.Model):
_name = 'core.student.ins_year'

 student_id = fields.Many2one('core.student',string='Student',required=True)

@api.depends('student_id')
def _year_creation_(self):


    for student in self.env['student_id'].browse():
        self.env['student_id'].create({
            'registration_number':'',
            'name_student':'',
            'surname_student':''})

and the student core is:

class Student(models.Model):
 _name = 'core.student'
 registration_number = fields.Char('Student registration number ',required=True)
 name_student =fields.Char('Student name ',required=True)
 surname_student = fields.Char('Student surname ',required=True)

Try like this,

@api.depends('student_id')
def _year_creation_(self):


for student in self:
    self.env['core.student'].create({
        'registration_number':'',
        'name_student':'',
        'surname_student':''})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM