On_change on a selection field inside a one2many field

I am trying to use a on_change method. The field that I am trying to use it on is a selection field. The selection field is on a one2many field that tries to use the value from the parent view. Example -

@fields.depends('patient', 'attendants_relation')
    def on_change_attendants_relation(self):
        if self.attendants_relation == 'Self':
            self.attendant_name = self.patient.patient_name 

here the ‘patient’ is the many2one field that is created to create a one2many field.

On changing the attendants_relation here, self.patient comes as None (until the record in one2many is not saved). Is there any way to access the data from the parent view ?

I’m not sure if there is a way to fill the selection field doing it this way, so maybe I’m wrong, but I would set the on_change on the one2many field, and iterate all the rows, setting the value for the attendants_relation field when it is needed.

Yes but you must tell the client to do so by filling depends like this:

@fields.depends('patient', '_parent_patient.patient_name', 'attendants_relation')

It is always better to keep the ‘patient’ field like that it will still work if the record is edited outside the One2Many.

2 Likes

Thank you for helping!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.