Skip to Content
Menu
This question has been flagged
2 Replies
5166 Views

I have created a model and a view that inherits the sale.order view and adds som custom field to it. I do not want to modify the original sale order view.

This code will (almost) do what I need:

    <record id="work_order_form" model="ir.ui.view">
        <field name="name">Workorder Form View</field>
        <field name="model">sale.order</field>
        <field name="priority" eval="10"/>
        <field name="inherit_id" ref="sale.view_order_form"/>
        <!--<field name="mode">primary</field> -->
        <field name="arch" type="xml">
            <xpath expr="//field[@name='partner_id']" position="after">
                <field name="custom_field_1"/>
                <field name="custom_field_2"/>
            </xpath>
        </field>
    </record>


Now within my model it will open the work order view and display my custom fields.Good!

Going back to the sales model you have two options 1. Quotation and  2. Order.

When I open a Sales order it has not changed the original sale.order.form view. Good!

But, still within the sale model if you open or create a new quotation though, it will also add my custom fields.

Within developer mode I can see that somehow my model has chaged the original quotation view (sale.view_order_form) into my view (work_order_form).

Somehow the quotation view (usually the same view as sale.order) has changed to the workorder view

A Sale Order (choose Order from Menu) is not affected.

I played around with the priority (changed it to higher or lower priorities) but that didn't really get a better result.

Can someone help and explain this strange behavior? Thanks


Avatar
Discard
Best Answer

If you inherit any view, basically the original view will have your changes as well and that is the use of inheritance.

In your case, you just don't want to show your custom fields to SO/Quotation menu and you can do it by hiding those custom fields from the original view/menu and just show them in your menu.

First, you should create a new action, add it in your menu and add something in the context of the action to show/hide the custom fields.

<record id="my_custom_action_orders" model="ir.actions.act_window">
<field name="name">Sales Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'show_custom': True}</field>
</record>

Now, use the context value to show/hide the custom fields in your view as follow:

<xpath expr="//field[@name='partner_id']" position="after">
<field name="custom_field_1" invisible="not context.get('show_custom', False)"/>
<field name="custom_field_2" invisible="not context.get('show_custom', False)"/>
</xpath>

This way, your custom fields will be visible in your new menu (because the action context has "show_custom": True) and will be hidden in original views/menus.

I hope this will solve your problem.

Avatar
Discard
Author

Works perfect, thanks a lot.

One last question: Do I have to do this for each custom field or is there a way to apply ('show_custom' , False) to all my custom fields (I have quite a few) within that view.

Anyhow, I am very happy!

Happy to know this worked.

Yes, use the context to hide all your fields from other menus/views.

Best Answer

Hi.

Either you can set the mode as primary and see, also give priority value greater than 16. See the below sample:

<record id="sale_onboarding_quotation_layout_form" model="ir.ui.view">
<field name="name">sale.onboarding.quotation.layout.form</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_document_template_form" />
<field name="mode">primary</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<xpath expr="//button[@special='save']" position="replace">
<button string="Apply" class="btn btn-primary" type="object" name="action_save_onboarding_quotation_layout" />
</xpath>
</field>
</record>

Thanks

Avatar
Discard
Author

Dear Niyas thank you for your answer. When I implement your solution I have two results. If I use eval="1000" non of the views (including my own) will display my custom fields. So I tried different priorities and found out that everything >20 will give me the same result. Only when I use eval="20" or smaller my custom fields will reappear. But, in this case, also in the Quotation view from the sale model. I also tend to think that the problem is somehow linked the action calling the wrong view. Why only the quotation action (and not also the Orders action) behaves like this?

you can specify the views in corresponding menus, did you tried using mode primary ?

see this: https://www.youtube.com/watch?v=-2EAt9nN4o0

Related Posts Replies Views Activity
1
Nov 24
1403
5
Jul 24
92472
1
Dec 23
2860
1
May 22
3432
0
Jan 20
2797