I got a model (Activity) with a Field Date ("date") on it. And I want to implement on my module a search view than finds the activities between 2 dates.
Anyone knows how? I made a search view by description but dont know how to implement this:
<record model="ir.ui.view" id="activity_search_view">
<field name="name">activity.search</field>
<field name="model">proyectosge.activity</field>
<field name="arch" type="xml">
<search>
<field name="description"/>
</search>
</field>
</record>
If the dates are always the same you can create a filter like this
<filter string="This Year"
name="thisyear"
domain="['|', ('date', '=', False), '&',('date','<=', time.strftime('%%Y-12-31')),('date','>=',time.strftime('%%Y-01-01'))]"
help="Journal invoices with period in current year" />
So, take a look at the domain, more examples (this year, this month, today, static dates):
domain="[('date','<=', time.strftime('%%Y-12-31')),('date','>=',time.strftime('%%Y-01-01'))]"
domain="[('date','<=', time.strftime('%Y-%m-%d')),('date','>=',time.strftime('%Y-%m-01'))]"
domain="[('date','<=', datetime.datetime.combine(context_today(), datetime.time(23,59,59))), ('date','>=', datetime.datetime.combine(context_today(), datetime.time(0,0,0)))]"
domain="[('date','<=', time.strftime('2020-12-31')),('date','>=',time.strftime('2000-01-01'))]"
If they are not static you must add both conditions with the advanced search. You can add the filter to favourites as well
Note: Keep in mind that you have to press the "Apply" to add each condition in the advanced search to use an "and" operator. Don´t press the button "Add a condition" because you are going to use an "or" operator