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.

1

How can I use a search view into a view displayed by a button ?

By
PJ Soule
on 9/19/13, 1:09 PM 3,176 views

Hi everyone.

I'm new to OpenERP, and I experience some issue to display a view by clicking on a button from another view (creating an ir.action.act_window object). I can display the view that I want to, but the search view isn't available.

When I display the view from a menu link, no problem, my search view appears and is functional.

Here the XML for the tree I want to display and my search view :

<!-- Search view -->
     <record id="view_search_result_filter" model="ir.ui.view">
        <field name="name">Filtres des résultats</field>
        <field name="model">flights.result</field>
        <field name="arch" type="xml">
            <search string="Résultats">
                <group expand="1" string="Group By...">
                    <filter name="solu" string="Solution" domain="[]" context="{'group_by':'solution_name'}"/>
                    <filter name="traj" string="Trajet" domain="[]" context="{'group_by':'journey_name'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Tree view -->
    <record id="flights_result_tree" model="ir.ui.view">
        <field name="name">flights.result.tree</field>
        <field name="model">flights.result</field>
        <field name="arch" type="xml">
            <tree string="Résultats">
                <field name="solution_name" invisible="1" />
                <field name="solution_number" invisible="1" />
                <field name="source" />
                <field name="airline" />
                <field name="fare" />
                <field name="fare_type" />
                <field name="private_fare" />
                <field name="journey_number" invisible="1"  />
                <field name="journey_name"  invisible="1" />
                <field name="alternative_number"  invisible="1" />
                <field name="alternative_name"  invisible="1" />
                <field name="alternative_departure_datetime" />
                <field name="alternative_arrival_datetime" />
                <field name="alternative_stops" />
                <field name="alternative_technical_stops" />
                <field name="alternative_departure_airport" />
                <field name="alternative_arrival_airport" />
          </tree>
        </field>
    </record>

And here is the code of the button which display my view :

def flight_open_results(self, cr, uid, ids, context=None):
    this = self.browse(cr, uid, ids, context=context)[0]
    tree_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'app_flights', 'flights_result_tree')[1]
    search_view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'app_flights', 'view_search_result_filter')[1]
    form_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'app_flights', 'flights_result_form')[1]

    res = {
        'type': 'ir.actions.act_window',
        'name': 'Résultats',
        'view_type': 'tree',
        'view_mode': 'tree,form',
        'res_model': 'flights.result',
        'domain':[('search_id','=',this.id)],
        'context':{'search_default_Current': 1, 'search_default_solu': 1, 'search_default_traj':1},
        'views': [(tree_id,'tree'),(form_id,'form')],
        'search_view_id': search_view_id
    }

    return res

And to finish, my menu link, which works well :

    <record model="ir.actions.act_window" id="action_flights_results">
        <field name="name">Résultats</field>
        <field name="res_model">flights.result</field>
        <field name="view_type">form</field>
        <field name="domain">[]</field>
        <field name="view_mode">form,tree</field>
        <field name="view_id" ref="flights_result_tree" />  
        <field name="context">{'search_default_Current': 1, 'search_default_solu': 1, 'search_default_traj':1}</field>
    </record>

    <menuitem name="Résultats"
        parent="menu_engine_flights"
        id="menu_engine_flights_results"
        action="action_flights_results"/>

As you see, I added a form view to make some tests, and :

  • From the "normal" view, opened with a menu link, everything works fine : I can click on a line, my form view shows, with controls to navigate between elements on the top of the page.

  • From the view opened from the button, when I click on a line of my tree, nothing happens. And when I switch to the form view, there is no record loaded and I don't have any navigation control, only the possibility to create a new record.

I think this is a lead to the answer, but I don't know OpenERP weel enough to find the solution. Could you help me with this please ?

Thank you.

2

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 9/25/13, 9:01 AM

In the return value of flight_open_results you should change the view_type from tree to form.

Also the view_mode ('tree,form') is different to that defined in action_flights_results ('form, tree').

It works, thanks ! I'm really a newbie into the openERP world, and I dn't really understand why I have to call the form view to show the tree view, but though, it works, and that's all I needed. Thank you again !

PJ Soule
on 9/27/13, 10:47 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: 9/19/13, 1:09 PM
Seen: 3176 times
Last updated: 3/10/16, 11:00 AM