Adding a default filter in a tree view - OpenErp custom module

I need to add a default filter for the tree view of my module.

I saw an example code in openerp, like this one:

<filter string="Partner" icon="terp-partner" domain="[]" context="{'group_by':'partner_id'}" /> 

This example in the purchase module, grouped by partner_id , as an example.

Now I have a custom module that I need to have a default filter when you click on its menu.

And this filter should show all records that have not β€œexpired”, or that have not transmitted the actual date when I look at the records in the module.

I have this field in my custom module:

 'Fecha_de_Vence': fields.date( 'Fecha de Vencimiento', required=True, select=True, ), 

This is the field that I need to take as a filter for all entries in this module.

Right now, in the "advanced search" I can set, for example, Fecha de Vencimiento no more than the actual date , well, I need this to be like the default filter.

Can anyone shed some light on how to get this by default in the openerp xml view?

+1
source share
2 answers

To view, you need to view and record the context 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 entries in the group so that you can see how they look, but you need to either delete them or adjust them to match your data. In addition, the words module and class should be replaced with your data.

+5
source

Ethan

Here is how I solved it, without your advice this would not have been 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 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 great, thank you very much!

+3
source

Source: https://habr.com/ru/post/1496574/


All Articles