Skip to content
Snippets Groups Projects

Optional group by time intervals to use with _date_ and _datetime_ fields

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Gabriel Davini
    Edited
    date_search_group_by_example.xml 1.09 KiB
    <!--
    You can use a special interval on temporal -date and datetime- fields to alter 
    the default behaviour of a temporal field search grouping. 
    
    The ORM automatically groups the records by 'month', bu you have four other 
    options: 'day', 'week', 'quarter' and 'year'.
    
    I leave you an example on how to use these:
    -->
    
    <search string="Pickings">
        <group expand="0" string="Group By">
            <filter string="Dayly" domain="[]" context="{'group_by':'min_date:day'}"/>
            <filter string="Weekly" domain="[]" context="{'group_by':'min_date:week'}"/>
            <filter string="Monthly" domain="[]" context="{'group_by':'min_date'}"/>
            <filter string="Quarterly" domain="[]" context="{'group_by':'min_date:quarter'}"/>
            <filter string="Yearly" domain="[]" context="{'group_by':'min_date:year'}"/>
        </group>
    </search>
    
    <!-- 
    You can see a working example here: 
    
    https://gitlab.e-mips.com.ar/rafaela-alimentos/logistic_transport/blob/devel/views/delivery_view.xml#L69
    
    And you can read the ORM code that allows us to do this here:
    
    https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L1956
    -->
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment