Paramita Paramita - 5 months ago 117
Python Question

Why my tree view is not loading in Odoo 9?

These following snippets are from my two XML files. I want to create a new tree view for the

res.partner
model.

<record id="distance_range_search_view_tree"model="ir.ui.view">
<field name="name">distance_range_search_view_tree</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<tree string="Contacts within Distance">
<field name="display_name"/>
<field name="country_id"/>
<field name="city"/>
<field name="state_id"/>
<field name="zip"/>
<field name="phone"/>
<field name="distance"/>
</tree>
</field>
</record>

<record id="distance_range_search_action" model="ir.actions.act_window">
<field name="name">Account Proximity Search</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name='view_mode'>tree</field>
<field name="view_id" ref="distance_range_search_view_tree"/>
<field name="help" type="html">
<p>
Here is the list of customers
</p>
</field>
</record>


And I use this method in my python file which returns the tree view:

@api.multi
def distance_to_search1(self):
#some other code
return {
'name': _('Contacts in this range'),
'type': 'ir.actions.act_window',
'res_model': 'res.partner',
'view_type': 'tree',
'view_mode': 'tree',
'view_id': self.env.ref('contact_geolocation.distance_range_search_view_tree').id,
'domain': [('id', 'in', filtered_partner_ids)],
}


Why is my tree view not loading?

Answer

Try this:

<record id="distance_range_search_action" model="ir.actions.act_window">
    <field name="name">Account Proximity Search</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">res.partner</field>
    <field name='view_type'>tree,form</field>
    <field name='view_mode'>tree</field>
    <field name="view_id" ref="distance_range_search_view_tree"/>
    <field name="target">current</field>
    <field name="help" type="html">
        <p>
           Here is the list of customers
        </p>
    </field>
</record>
@api.multi
def distance_to_search1(self):
    #some other code
    return {
        'name': _('Contacts in this range'),
        'type': 'ir.actions.act_window',
        'res_model': 'res.partner',
        'view_type': 'form',
        'view_mode': 'tree',
        'view_id': self.env.ref('contact_geolocation.distance_range_search_view_tree').id,
        'domain': [('id', 'in', filtered_partner_ids)],
    }  

Edit: I found this in the source code

For historical reasons, OpenERP has weird dealings in relation to view_mode and the view_type attribute (on window actions):

  • one of the view modes is tree, which stands for both list views and tree views
  • the choice is made by checking view_type, which is either form for a list view or tree for an actual tree view.

This methods simply folds the view_type into view_mode by adding a new view mode list which is the result of the tree view_mode in conjunction with the form view_type.

Comments