I can update my One2many field with the following function called from a button:
@api.multi
def getlinks(self):
self.salary.unlink()
staffs = self.env['sankeremployee.monthly'].search([('employee', '=', self.employee.id)])
data = []
for staff in staffs:
data.append((0, 0, {'employee': staff.employee.id, 'basic': staff.basic}))
self.salary = data
However, I would like to do this using an onchange function. When I tried this with the following code, the record is created but the field values are not passed on. Is there some way of correcting this? I am using version 12.
@api.onchange('employee')
def getlinks(self):
self.salary.unlink()
staffs = self.env['sankeremployee.monthly'].search([('employee', '=', self.employee.id)])
data = []
for staff in staffs:
data.append((0, 0, {'employee': staff.employee.id, 'basic': staff.basic}))
self.salary = data
would you try to call your function in onchange methode
like :
@api.onchange('employee')
def onchange_employe(self):
self.getlinks()