Skip to Content
Menu
This question has been flagged
1 Reply
842 Views

I want to add the filter in search view which will only display the records whose next_calibration_due_on value is in the current month.

I tried for the greater than today's date and I succeeded

<record id="view_calibration_test_search" model="ir.ui.view">
<field name="name">calibration.test.search</field>
<field name="model">calibration.test</field>
<field name="arch" type="xml">
<search string="Calibration">
<field name="company_name"/>
<field name="calibration_date" filter_domain="[('calibration_date', '>=', self)]" string="From Date"/>
<field name="calibration_date" filter_domain="[('calibration_date', '&lt;=', self)]" string="To Date"/>
<filter name="monthly_expiring" string="Expiring This Month"
domain="[('next_calibration_due_on', '>=', context_today())]"/>
</search>
</field>
</record>

But I want a filter for monthly range. How can I?

Avatar
Discard
Best Answer

Hi, 


Yes, you can add the filter in search view which will only display the records whose next_calibration_due_on value is in the current month, following below...

<filter name="monthly_expiring" string="Expiring This Month"

        domain="[

            ('next_calibration_due_on', '&gt;=', (context_today().strftime('%Y-%m-01'))),

            ('next_calibration_due_on', '&lt;', ((context_today() + relativedelta(months=1)).strftime('%Y-%m-01')))

        ]"/>

  • Setting the start date to the first day of the current month using context_today().strftime('%Y-%m-01')
  • Setting the end date to the first day of next month using context_today() + relativedelta(months=1)


Best Regards,

NIZAMUDHEEN MJ.

Accurates

Avatar
Discard
Related Posts Replies Views Activity
3
Jun 25
238
1
Jun 25
445
1
Jan 25
17323
0
Feb 24
28
1
Jan 20
3473