如何在odoo中过滤日期?

时间:2015-06-02 13:41:09

标签: view openerp odoo

我想按日期过滤一些字段,这是搜索视图,效果很好:

<record model="ir.ui.view" id="moulin_view_search">
            <field name="name">test.base.graph.view26</field>
            <field name="model">test.base</field>
            <field name="arch" type="xml">
                <search string="My Dashboard">
                    <field name="create_date" />
                    <filter name="filter_see_all" string="All" domain="['',('create_date','>','2015-05-29 12:12:12.120')]" context="{'group_by':'create_date:minute'}"/>    
                </search>
            </field>
        </record>

但是我需要让用户选择日期,而不是直接在代码中传递它。

例如,我想让用户选择此日历的日期:

enter image description here

1 个答案:

答案 0 :(得分:2)

供您参考打开

Accounting -> Reporting -> Legal Reports -> Accounting Reports -> General Ledger

在这里,您可以看到过滤数据的不同选项,而不是直接将其传递给代码。

为此您需要创建向导,在该向导中需要使用字段进行过滤,按钮将过滤条件传递给相关模型。

对于V.8

from openerp import models, fields, api
from datetime import datetime

class class_name(models.TransientModel):
    _name = 'model.name'

    date_from = Fields.Datetime('From')
    date_to = Fields.Datetime('To')

    @api.one
    def filter_data(self):
        ### you will get all the defined fields of wizard here.
        from_date = self.date_from
        to_date = self.date_to

        ### add your own logic to pass search criteria to the source model
    ## Define your fields here and add them in xml file and define menu with appropreate action to open that wizard. 

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

        <record model = "ir.ui.view" id = "view_id">
            <field name = "name">view.name</field>
            <field name = "model">model.name</field>
            <field name = "type">form</field>
            <field name = "arch" type = "xml">
                <form string = "String">
                    <sheet>
                        <group>
                            <field name="date_field_name" />
                        </group>
                        <footer>
                            <button name = "filter_data" string = "Search" type = "object" class = "oe_highlight"/>
                            <button string = "Cancel" class = "oe_link" special = "cancel"/>
                        </footer>
                    </sheet>
                </form>
            </field>
        </record>

        <act_window name = "Filter Data" 
                    res_model = "model.name"
                    src_model = "source.model.name"   ### specify source model in which you want to add this wizard 
                    view_mode = "form" 
                    view_type = "form"
                    multi="False"
                    target = "new" 
                    key2 = "client_action_multi"
                    id = "action_add_to_request2"
                    view_id = "view_id"/>
    </data>
</openerp>