Adding default filter on tree view - OpenErp Custom module

一曲冷凌霜 提交于 2019-12-05 07:28:06

问题


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

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

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

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

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

And this filter must show all the records which aren't 'expired', or that hasn't passed the actual date when I'm browsing 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 I need to take as a filter for all the records in this module.

Right now, in the 'advanced search' I can put for example Fecha de Vencimiento not more than actual date, well, I need to have this as a 'default' filter.

Anyone could shed some light in how to get this by default in openerp's xml view?


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/18035007/adding-default-filter-on-tree-view-openerp-custom-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!