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

PJ Soule

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'}"/>
    <!-- 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" />

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('').get_object_reference(cr, uid, 'app_flights', 'flights_result_tree')[1]
    search_view_id = self.pool.get('').get_object_reference(cr, uid, 'app_flights', 'view_search_result_filter')[1]
    form_id = self.pool.get('').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',
        '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>
    <menuitem name="Résultats"

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.

1 Answer
Andreas Brueckl
Best Answer

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').

1 Comment
PJ Soule

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 !