admin管理员组

文章数量:1431935

In the form view in Odoo 16, I have 2 times the same field, one to display only the name of the partner, and in another, I have the name and address.

In both cases, it displays the name and address. It seems that I can't have 2 types of display for the same field?

xml

<group>
    <group>
        <field name="partner_shipping_id" />
    </group>
    <group>
        <field name="partner_shipping_id" context="{'show_address': 1}" options="{'always_reload': True, 'no_open':true}"  readonly="1"/>
    </group>
</group>

Any Idea ?

In the form view in Odoo 16, I have 2 times the same field, one to display only the name of the partner, and in another, I have the name and address.

In both cases, it displays the name and address. It seems that I can't have 2 types of display for the same field?

xml

<group>
    <group>
        <field name="partner_shipping_id" />
    </group>
    <group>
        <field name="partner_shipping_id" context="{'show_address': 1}" options="{'always_reload': True, 'no_open':true}"  readonly="1"/>
    </group>
</group>

Any Idea ?

Share Improve this question asked Nov 19, 2024 at 2:13 ConsepConsep 211 silver badge1 bronze badge 3
  • IIRC the fields will get the same "options" in the same view. You can call it Feature or Bug, but that's what i have experienced myself in some similar situations. – CZoellner Commented Nov 19, 2024 at 8:17
  • I'm afraid you're right CZoellner – Consep Commented Nov 27, 2024 at 15:57
  • @Consep I am facing the same issue. How did you solve? – Neural Commented Feb 28 at 9:28
Add a comment  | 

2 Answers 2

Reset to default 1

What you can try to do is to create the field twice, but without having it in database twice:


partner_shipping_id2 = fields.Many2one(
    related="partner_shipping_id",
    readonly=True,
)

Now, simply define the new field in the form to ensure that it appears as intended. For example like:

<group>
    <group>
        <field name="partner_shipping_id2" />
    </group>
    <group>
        <field name="partner_shipping_id" context="{'show_address': 1}" options="{'always_reload': True, 'no_open':true}"  readonly="1"/>
    </group>
</group>

just try to take the customer name (partner_id.name) from the model and put it in the xml.

<group>
    <group>
            <field name="partner_id.name" string="Delivery Address" />
    </group>
    <group>
        <field name="partner_shipping_id" context="{'show_address': 1}" options="{'always_reload': True, 'no_open':true}"  readonly="1"/>
    </group>
</group>

by default, a snippet handles the shipping fields so tricky to customize the field but this way should do for you.

本文标签: xmlHow to display 2 times an address field in form view Odoo 16Stack Overflow