Accessing parent fields / Passing field to child relation

Hi, I’m trying to obtain fields of the parent in on_change_with however I keep getting None. I’ve tried the answer from On_change on a selection field inside a one2many field but I still can’t seem to obtain the value of the parent field.

In my, I have the following fields

    pharmacy = fields.Many2One(
        '', 'Pharmacy')

    child= fields.One2Many(
        'prescriptions.child', 'name', 'Prescriptions')

In my

    pharmacy_location = fields.Integer("Pharmacy Location")

def on_change_with_pharmacy_location(self):

When I create a new child and modify DependingOnChangeField, this results in an exception as _parent_pharmacy does not exist in the model, and I checked pharmacy and pharmacy_location in self and they are both None as well

Am I missing something here or is there any other ways to obtain parent field values? It doesn’t necessarily have to be in on_change_with, as my main purpose is to obtain the parent field values when I create a new child or edit existing child, not to update the value of pharmacy_location.


After ‘_parent’, you have to specify the many2one field of the child class which is linking it with the parent, so you have to put something like ('name', '') assuming that name is the field that points to the parent class.

The return should be just:

Thanks for the answer. Now I’m able to obtain the id of the pharmacy.

On top of that, just checking if is it possible for me to get the fields of pharmacy other than id? Currently I’m only able to get the id of the pharmacy

For example can I directly get

With the I would be able to search for the in DB, but I wonder if I can reduce this redundancy by directly obtaining the in just one step.

Maybe I’m wrong but I would say yes, can you check if the pharmacy you are using to test it have a location?

I tried but other than, I can’t get any of the other fields of :frowning:

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