Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
8749 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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)
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 19
13656
1
thg 3 23
2338
0
thg 12 22
2983
0
thg 6 21
2909
0
thg 6 20
5419