用 many2many 字段填充 many2one

Fill a many2one with a many2many field

我有一个 many2many 字段 employee_idv01,如何为每个员工创建 planning model 的记录。

例如,如果 record.employee_idv01 === hr.employee(6,3) 我需要为 hr.employee(6) 创建一个记录,为 hr.employee( 3)

    @api.model
    def create(self, vals):
        record = super(affectation3, self).create(vals)
        if record.employee_idv01:
            for i in self.employee_idv01??:


(how can I create records for planning with each employee???)

            self.env['planning'].create({
                                     'employee_id': record.????,
                                     'date_r01': record.date_r1,
                                     'date_r02': record.date_r2,
  

                             })           

你可以试试这个代码:

 for employee in self.employee_idv01:
      self.env['planning'].create({
                                'employee_id': employee.id,
                                'date_r01': record.date_r1,
                                'date_r02': record.date_r2,
                              })