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 make two different listviews from the same model in a module?

By
Yenthe
on 11/27/14, 9:14 AM 975 views

Hi everybody

I want to extend the project module and make a new menu item that shows the project.project data in a listview but with other fields.
The default project listview looks like this:
http://i.imgur.com/II0O8PW.png

I now want to create a second menu item that also shows a listview but with other field names. It should show me the name and some of my custom fields (such as x_internal_ip and x_external_ip).
How exactly should I do this? I've coded the second menu-item and the view but if I change the fields in the arch of project.project it reflects on both the project.project views that I now have.

My custom code:

<!--CUSTOM-->
    <record id="project_detail_tree" model="ir.ui.view">
            <field name="name">Details</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <tree string="Details">
                    <field name="x_name"/>
            <field name="x_number"/>
            <field name="x_vm_name"/>
            <field name="x_internal_ip"/>
            <field name="x_external_ip"/>
            <field name="x_port"/>
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="course_search_view">
            <field name="name">project.project.search</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <search>
                    <field name="name"/>
                </search>
            </field>
        </record>

        <record model="ir.actions.act_window" id="project_course_action">
            <field name="name">Details overview</field>
            <field name="res_model">project.project</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        <field name="arch" type="xml">
                <search>
                    <field name="name"/>
                </search>
                </field>
        </record>

        <menuitem id="detail_menu" name="Details specifications" parent="base.menu_main_pm" />
        <menuitem id="project_details_menu" name="Details configuration" parent="detail_menu" action="project_course_action" />

The thing is that my code from project.project.tree is combined with the code of the default project.project tree code there is, which looks like this:

<record id="view_project" model="ir.ui.view">
            <field name="name">project.project.tree</field>
            <field name="model">project.project</field>
            <field name="field_parent">child_ids</field>
            <field name="arch" type="xml">
                <tree fonts="bold:message_unread==True" colors="red:date and (date&lt;current_date) and (state == 'open');blue:state in ('draft','pending');grey: state in ('close','cancelled')" string="Projects">
                    <field name="sequence" widget="handle"/>
                    <field name="message_unread" invisible="1"/>
                    <field name="date" invisible="1"/>
                    <field name="name" string="Project Name"/>
                    <field name="user_id" string="Project Manager"/>
                    <field name="partner_id" string="Contact"/>
                    <field name="parent_id" string="Parent" invisible="1"/>
                    <field name="planned_hours" widget="float_time"/>
                    <field name="total_hours" widget="float_time"/>
                    <field name="effective_hours" widget="float_time"/>
                    <field name="progress_rate" widget="progressbar"/>
                    <field name="state"/>
                </tree>
            </field>
        </record>

What is the solution to make a second view with data from project.project in a second tree view?

Thanks
Yenthe

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 11/28/14, 4:25 AM

Yenthe, you need 2 actions in this case.  Within each action you can specify which views to use.  Bole has pointed out a good example file in ir.actions.act_window.view.  Search for "ir.actions.act_window.view" in that file for samples.

@John, thanks for the reply and some extra guidance! What I don't understand is why these two views interfere with eachother? I'm really missing the logic of this. Could you help me any further and give me a little sample or something? I'm really not sure about what to do. There are like three tree views in the sample too. :/

Yenthe
on 11/28/14, 4:35 AM

Yenthe, when Odoo executes a window action that does not specify any specify view, it will search for a view of that model and the requested type (tree, form, etc.) based on the order of priority and name. So, the higher the priority (the smaller the number), the more chance it will be picked up if a view is requested without specifying which specific one. The same goes for the name order if you have multiple views with the same priority. I'm not too sure what is the behaviour if you have multiple valid views with the same priority and name.

Ivan
on 11/28/14, 5:14 AM

One more thing that you might have known before: trace the XML ids to see which view is used by which action.

Ivan
on 11/28/14, 5:16 AM
0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 11/27/14, 11:45 AM

You can find good example for similar thing in account module.. 
Check account_invoice_view.xml.... 
there is invoice_form and invoice_supplier_form views both "sitting" on same model.. 
Trick is to define separate actions , and in them define wich view should they call.. 

Take a closer look and apply to your models :) 
I see you are quite experienced, so no need for noob-like step-by-step expanation.. 

also.. hope this will help you a bit : )

 

@Bole, thanks for the reply! Sadly I can't seem to find my error. I know it has to do with the view it should call and the correction references but I just can't find what I'm doing wrong! Care to take a look at it and give me a bit more guidance? Looks like I'm missing something vital here.

Yenthe
on 11/28/14, 3:10 AM

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: 11/27/14, 9:14 AM
Seen: 975 times
Last updated: 3/16/15, 8:10 AM