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

Hi everyone,

How can I create new form view for existing object model?

I'd like create a new menu for mail.message model. I created a new tree view, and action for tree view. For the form view (when edit message), I want to change some fields options (not allow create edit). But, this will affect to the existing menu "Message" (in Settings). And I want the new options only affect to my new form view.

My new view:

<record model="ir.ui.view" id="oit_view_message_form">

            <field name="name">oit_mail.message.form</field>

            <field name="model">mail.message</field>

            <field name="inherit_id" ref="mail.view_message_form"/>

            <field name="arch" type="xml">

                <field name="email_from" position="attributes">

                    <attribute name="options">{'no_create':true, 'no_create_edit':true, 'no_open':true}</attribute>

                </field>

            </field>

        </record>


So, how can I using my new view for my menu only, and keep the original view for original function?

Thank you

Avatar
Discard
Best Answer

Dear Vu Huynh,


you can copy the existing original form and then change the id, you must do this without inheritance. Then change and add the new features.

Then:

 

<record model="ir.actions.act_window.view" id="action_hr_voucher_confirmation1">
            <field name="sequence" eval="1"/>
            <field name="view_mode">tree</field>
            <field name="view_id" ref="view_hr_vouchers_confirmation_tree"/>
            <field name="act_window_id" ref="action_hr_voucher_confirmation_list"/>
        </record>
        <record model="ir.actions.act_window.view" id="action_hr_voucher_confirmation2">
            <field name="sequence" eval="2"/>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_hr_vouchers_confirmation_form"/>
            <field name="act_window_id" ref="action_hr_voucher_confirmation_list"/>
  </record>

you must link the new action with the new tree and new form as the above example.

action_hr_voucher_confirmation_list:  that refer to the new action id.

view_hr_vouchers_confirmation_tree: that refer to the new tree id.

view_hr_vouchers_confirmation_form: that refer to the new form id.

 I hope I helped you

Avatar
Discard
Author

Thank you, Ayman

This is very helpful

Best Answer

For this scenario you need to link your new view to the window action of your new menu.

To achieve this you need to simply create record of ir.actions.act_window.view.

Ex.

<record id="xml_id" model="ir.actions.act_window.view">

            <field eval="1" name="sequence"/>

            <field name="view_mode">form</field>

            <field name="view_id" ref="xml_id_of_form_view"/>

            <field name="act_window_id" ref="xml_id_of_menu_action"/>

</record>

By doing this this view will linked to the new menu action only.


Happy Coding!!!

Avatar
Discard