This question has been flagged

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}">

            <tree>

                <field name="name"/>

                <field name="subject"/>

            </tree>

        </field>

    </page>

</page>

This is the project form view

  <form>

    <sheet>

        <group>

            <field name="name"/>

            <field name="subject"/>

            <field name="partner_id"/>

        </group>

    </sheet>

</form>


* 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

Avatar
Discard
Author Best Answer

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

I added the following in the respective model (CustomerProject)

@api.model

    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?

Avatar
Discard
Best Answer

Hi, just found same problem, thanks to @mahmoud, here is my solution on Odoo 14:

@api.model
def default_get(self, fields):
""" BUG ODOO??? """
if 'default_service_id' in self._context:
    fields += ['service_id']
return super(YourClass, self).default_get(fields)
Avatar
Discard