Yacino
Yacino

Reputation: 665

how to Filter date in odoo?

I'd like to filter some fields by date, This is the search view , it work good:

<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>

But i need to let the user select the date, without passing it in the code directly.

For example I want to let the user chose date with this calendar:

enter image description here

Upvotes: 1

Views: 5570

Answers (1)

For your reference Open

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

Here you can see the different option to filter data rather than directly pass it to code.

For that you need to create wizard in which you need to take fields for filtration and button to pass that filtration criteria to related models.

For 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>

Upvotes: 2

Related Questions