context default not working for one2many field

Mahmoud H

Hello everyone,

I created a simple project model, and linked it to res.partner model

I have added a page to res.partner, and listed the partner's projects there.

When the user click on add a new line in the tree, a new form will open, I want the partner_id field in the form to have by default the id of the partner the form opened from 

I inherited the partner view and added the following but partner_id field doesn't get a default value:

<page name="internal_notes" position="before">

    <page name="projects" string="Projects">

        <field name="customer_project_ids" context="{'default_partner_id' : active_id, 'default_name' : active_id}">


                <field name="name"/>

                <field name="subject"/>





This is the project form view




            <field name="name"/>

            <field name="subject"/>

            <field name="partner_id"/>




* setting a default value for others fields works fine, it doesn't work only for partner_id!!

* I even tried to give partner_id field a default value from py code, but it is also not working!

Thank you

1 Answer
Mahmoud H
Best Answer

For those who are facing similar issues, I find a workaround

I added the following in the respective model (CustomerProject)


    def default_get(self, fields):

        res = super(CustomerProject, self).default_get(fields)

        if 'default_partner_id' in self._context:

            res['partner_id'] = self._context.get('default_partner_id')

        return res

* 'fields' doesn't have partner_id, even though theoretically it should

I still have no idea why it is not working by default, maybe Odoo bug?