콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
835 화면

Hello,


I have created a custom date field "birthdate".


When I try to apply the “BETWEEN” operation to two dates by creating a custom filter, the system calls the search function twice, once with the >= operation and once with the <= operation.


In the results, Odoo shows me all the records responding to the first query AND all the records responding to the second. 


How can I get Odoo to display only the results that match both queries?


Thanks in advance



아바타
취소
작성자

Thank you for your reply.

Is it possible to allow the user to choose the date range?

베스트 답변

If you're building this filter in the XML of the search view or using the search domain directly in code (e.g., Python or JS), you must explicitly structure the domain with an AND condition like:
[('birthdate', '>=', start_date), ('birthdate', '<=', end_date)]


아바타
취소
작성자

Thanks for your reply,
That's what I'm thinking, but how can I allow the user to choose the start and end dates ?

베스트 답변

Hi Mr Tessa
check this 

<!-- Define a custom search view with proper date range filters -->
<record id="view_your_model_search" model="ir.ui.view">
    <field name="name">your.model.search</field>
    <field name="model">your.model</field>
    <field name="arch" type="xml">
        <search string="Search Records">
            <field name="name"/>
            <field name="birthdate"/>
            
            <!-- Custom date range filter -->
            <filter name="birthdate_range" string="Birth Date Range" 
                    domain="[]" 
                    context="{'search_default_birthdate_range': 1}"/>
            
            <!-- Predefined date ranges -->
            <separator/>
            <filter name="born_this_year" string="Born This Year"
                    domain="[('birthdate', '>=', context_today().strftime('%Y-01-01')),
                             ('birthdate', '<=', context_today().strftime('%Y-12-31'))]"/>
            
            <filter name="born_last_year" string="Born Last Year"
                    domain="[('birthdate', '>=', (context_today() - relativedelta(years=1)).strftime('%Y-01-01')),
                             ('birthdate', '<=', (context_today() - relativedelta(years=1)).strftime('%Y-12-31'))]"/>
            
            <group expand="0" string="Group By">
                <filter string="Birth Month" name="group_birth_month"
                        context="{'group_by': 'birthdate:month'}"/>
                <filter string="Birth Year" name="group_birth_year"
                        context="{'group_by': 'birthdate:year'}"/>
            </group>
        </search>
    </field>
</record>
아바타
취소
관련 게시물 답글 화면 활동
1
6월 21
5444
1
9월 16
56
0
3월 15
4832
3
7월 25
909
1
2월 23
6033