I need to add a default filter, for the tree view of my module.
I saw some code example in openerp, like this one:
Ethan
This is how i solved it, without your advice it wouldn't be possible:
<record id="solvencia_search" model="ir.ui.view">
<field name="name">solvencia.solvencia.select</field>
<field name="model">solvencia.solvencia</field>
<field name="arch" type="xml">
<search string="Solvencias">
<field name="Fecha_de_Vence" string="Fecha de Vencimiento" filter_domain="[('Fecha_de_Vence','=',((context_today()-datetime.timedelta(days=10)).strftime('%%Y-%%m-%%d')))]"/>
<separator/>
<filter string="Fecha de Vencimiento" name="type_date" domain="[('Fecha_de_Vence','=',((context_today()-datetime.timedelta(days=10)).strftime('%%Y-%%m-%%d')))]" help="..."/>
<separator/>
<group expand="0" string="Group By...">
<filter string="Assigned to" domain="[]" context="{'group_by' : 'Fecha_de_Vence'}" />
<filter string="Status" domain="[]" context="{'group_by': 'Fecha_de_Emision'}"/>
<filter string="Priority" domain="[]" context="{'group_by': 'nsol'}"/>
</group>
</search>
</field>
And the context
in act_window
:
<record id="action_solvencia_solvencia" model="ir.actions.act_window">
<field name="name">Solvencias</field>
<field name="res_model">solvencia.solvencia</field>
<field name="view_type">form</field>
<field name="context">{"search_default_type_date":1}</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="solvencia_solvencia_tree"/>
<field name="nsol" />
<field name="Fecha_de_Emision" />
<field name="Fecha_de_Vence" />
<field name="ministerio" />
<field name="ins_em" />
<field name="cod_ver" />
<field name="cadidate" />
<field name="observa" />
</record>
Works perfectly, thank you very much!
You need a search view, and a context entry in act_window:
<record id="search_xxx_filter" model="ir.ui.view">
<field name="name">module.class.select</field>
<field name="model">module.class</field>
<field name="arch" type="xml">
<search string="Search xxx">
<field name="Fecha_de_Vence" string="Fecha de Vencimiento" filter_domain="[(1,'=',1)]"/>
<separator/>
<filter string="Fecha de Vencimiento" name="type_date" domain="[(1,'=',1)]" help="..."/>
<separator/>
<group expand="0" string="Group By...">
<filter string="Assigned to" domain="[]" context="{'group_by' : 'user_id'}" />
<filter string="Status" domain="[]" context="{'group_by': 'state'}"/>
<filter string="Priority" domain="[]" context="{'group_by': 'priority'}"/>
</group>
</search>
</field>
</record>
<record id="module_class_act" model="ir.actions.act_window">
<field name="name">xxx</field>
<field name="res_model">module.class</field>
<field name="view_type">form</field>
<field name="context">{"search_default_type_date":1}</field>
<field name="view_id" ref="module_class_tree-view"/>
</record>
I left the group entries in so you could see what they look like, but you'll need to either remove them or adjust them so they match your data. Also, the words module
and class
should be replaced with your data.