Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to "postion=replace" a Form or Tree View, Menuitem ?

By
Ruban Kannan
on 10/6/14, 1:17 AM 1,988 views

Hello everyone, 

I want to list all the product template colums (39 columns I see in pgadmin) in the Product template Form view. Adding position="replace" for fields does not work for me since I want to see all the colums.

I want to know how I can replace the existing menuitem,action and views with the new items I created. Also, how can I inject new menuitem,action and views. Below is my XML content. 

<record id="product_vape_form_view" model="ir.ui.view">
            <field name="name">product.vape.form.view</field>
            <field name="model">product.template</field>
            <field name="arch" type="xml">
                <form>
                    <group>
                        <field name="warranty" />
                        <field name="uos_id" />
                        <field name="list_price" />
                        <field name="weight" />
                        <field name="color" />
                        <field name="image" />
                        <field name="write_uid" />
                        <field name="mes_type" />
                        <field name="uom_id" />
                        <field name="description_purchase" />
                        <field name="create_date" />
                        <field name="uos_coeff" />
                        <field name="create_uid" />
                        <field name="rental" />
                        <field name="product_manager" />
                        <field name="message_last_post" />
                        <field name="company_id" />
                        <field name="state" />
                        <field name="uom_po_id" />
                    </group>
                    <group>
                        <field name="type" />
                        <field name="description" />
                        <field name="weight_net" />
                        <field name="volume" />
                        <field name="write_date" />
                        <field name="active" />
                        <field name="categ_id" />
                        <field name="sale_ok" />
                        <field name="image_medium" />
                        <field name="name" />
                        <field name="description_sale" />
                        <field name="image_small" />
                        <field name="loc_rack" />
                        <field name="track_incoming" />
                        <field name="sale_delay" />
                        <field name="track_all" />
                        <field name="track_outgoing" />
                        <field name="loc_row" />
                        <field name="loc_case" />
                    </group>
                </form>
            </field>
        </record>
        <record id="product_vape_tree_view" model="ir.ui.view">
            <field name="name">product.vape.tree.view</field>
            <field name="model">product.template</field>
            <field name="arch" type="xml">
                <tree >
                    <field name="name" />
                    <field name="create_date"/>
                    <field name="create_uid"/>
                </tree>
            </field>
        </record>
        <record id="action_product_vape_tree_view" model="ir.actions.act_window">
            <field name="name">All Products</field>
            <field name="res_model">product.template</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="product_vape_tree_view"/>
        </record>
        <menuitem id="vape.product" action="action_product_vape_tree_view" name="All Vape Products" parent="base.menu_product" />

1

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 10/6/14, 2:25 AM

Ruben, aside from <record> tag, there is also <delete> tag.  Both works if you specify the XML ID (id) and model of the said attribute.  So, having said that:

  • You can delete a record by adding <delete id="the_xml_id_of_record_to_delete" model="the_model_to_delete/> somewhere in your XML
  • You can update a record by adding <record id = "the_xml_id_of_record_to_change" model="the_model_to_change"> ... </record>, where ... is the new content (list of fields and their values) of the record.  It will update the fields listed in the content.
  • If the record is created by other module you can specify the "full" XML ID: module_name.the_xml_id_of_record_to_change
  • Note that generally it is not advisible to change or delete a view as the view may be inherited by other modules. It is better to inherit a view instead.
  • To tie in a view to an action, you can specify it with the following XML snippet:
  • <record model="ir.actions.act_window.view" id="tie_in_view_to_action">
                <field name="sequence" eval="1"/>
                <field name="view_mode">form</field>
                <field name="view_id" ref="your_view_xml_id"/>
                <field name="act_window_id" ref="product_template_action_tree"/>
            </record>

Note that generally it is not advisible to change or delete a view as the view may be inherited by other modules. It is better to inherit a view instead. /// Thanks. I completely agree with the last point and I want to proceed this way. So, 1. How do I bulk replace fields in an inherited view? 2. How do I add a new menu item under an existing menu item and open the newly created View?

A or B or C Technologies Pvt LTD, Ruban Kannan
on 10/6/14, 5:06 AM

Menu will call an action (in this case, a window action). Window action will call a view. So, basically you need to do the following: - Inherit the view that you need to inherit. I am not aware of any way to bulk replace field. You can replace the form, I guess, but this will be quite similar as deleting the old view and creating a new one. - Create a new action window to using the new views that you have specified - Create a new menu whose parent is an old menu (specified by XML ID) and calling the new action that you have created. Check the account/account_view.xml for example. If you really need a different view from the original view, you can create (instead of inheriting or replacing) a new view and let the old view be.

Ivan
on 10/6/14, 6:17 AM

Thx John. I want to display my new action under Sales/Products underneath Sales/Products/Products by Category. I wrote my new action as . vape is my module name, base.menu_product seems to be the id of Sales/Products. It didn't work

A or B or C Technologies Pvt LTD, Ruban Kannan
on 10/6/14, 6:30 AM

See the last line of my XML for the action I wrote.

A or B or C Technologies Pvt LTD, Ruban Kannan
on 10/6/14, 6:31 AM

Sorry about the confusion. This works now. I didn't include the new XML file in my data of openerp.py.

A or B or C Technologies Pvt LTD, Ruban Kannan
on 10/6/14, 7:08 AM

Thx for this. So this works when I add a new line (field name="sequence" eval="1") or (field name="priority" eval="1") to the form view xml. But, since it changes the priority, it changes the default Form view. While this is okay for me, I just want to know how to associate the my custom form view only to the custom tree view I created. In other words, how to trigger the custom form view when a record in tree view is clicked.

A or B or C Technologies Pvt LTD, Ruban Kannan
on 10/6/14, 8:00 PM

Ruben, please refer to the last 2 points in this answer on how to tie in a view to an action.

Ivan
on 10/8/14, 12:59 AM
0
Ruban Kannan
On 10/6/14, 7:42 AM

I was able to inject a new Menuitem with the following line

<menuitem id="vape.product" action="action_product_vape_tree_view" name="All Vape Products" parent="base.menu_product" />

I'm still wondering how to use my custom defined Form View in place of the default product template form view "product.product_template_only_form_view"

 

Can't find product_template_only_form_view in my version of Odoo. Anyway, there are a couple of ways to achive that. First, the simplest one but no guarantee, is to set your custom view with a small priority. The view has a priority field in which a smaller priority (e.g. 1) will be picked first if there are more than one views defined for that model. Second, is to tie the action with the form view. In my version of Odoo, product.template is called by action with XML ID: product_template_action_tree. You can add the following record to tie in your view with this action: form

Ivan
on 10/6/14, 12:06 PM

Sorry the XML is not posted properly, I'll edit my previous answer.

Ivan
on 10/6/14, 12:07 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/6/14, 1:17 AM
Seen: 1988 times
Last updated: 3/16/15, 8:10 AM