odoo xml 时间搜索条件

Posted PYTHON & ODOO

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了odoo xml 时间搜索条件相关的知识,希望对你有一定的参考价值。


 今年

<filter string="This Year" name="year" domain="[(‘date‘,‘&lt;=‘, time.strftime(‘%%Y-12-31‘)),(‘date‘,‘&gt;=‘,time.strftime(‘%%Y-01-01‘))]"/>

今天

<filter icon="terp-go-today" string="Today" domain="[(‘date‘,‘&lt;=‘, datetime.datetime.combine(context_today(), datetime.time(23,59,59))), (‘date‘,‘&gt;=‘, datetime.datetime.combine(context_today(), datetime.time(0,0,0)))]"/> 

上月
(‘date‘, ‘like‘, (context_today() - datetime.timedelta(month=1)).strftime(‘%%Y-%%m‘))  
(‘date‘, ‘like‘, (context_today() - relativedelta(month=1)).strftime(‘%%Y-%%m‘)) 

(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production)d ),(‘date‘,‘&lt;‘, time.strftime(‘%%Y-%%m-01‘)),(‘date‘,‘&gt;=‘,  (context_today() - relativedelta(months=1)).strftime(‘%%Y-%%m-01‘) ) 

(‘date‘, ‘&gt;=‘, ((context_today()+relativedelta(weeks=-2, days=1, weekday=0)).strftime(‘%%Y-%%m-%%d‘))),(‘date‘, ‘&lt;=‘, ((context_today()+relativedelta(weeks=-1, weekday=6)).strftime(‘%%Y-%%m-%%d‘)))

上周日
(‘date‘, ‘&lt;=‘, ((context_today()+relativedelta(weeks=-1, weekday=6)).strftime(‘%%Y-%%m-%%d‘))) 

 

上周一
(‘date‘, ‘&gt;=‘, ((context_today()+relativedelta(weeks=-2, days=1, weekday=0)).strftime(‘%%Y-%%m-%%d‘))) 

 

本周一
(‘date‘, ‘&gt;=‘, ((context_today()+relativedelta(weeks=-1, weekday=0)).strftime(‘%%Y-%%m-%%d‘))) 

 

实例:

<record id="inherit_iew_move_search" model="ir.ui.view">
            <field name="name">inherit.stock.move.search</field>
            <field name="model">stock.move</field>
            <field name=‘inherit_id‘ ref=‘stock.view_move_search‘/>
            <field name="arch" type="xml">
                <field name="name" position="after">
                    <field name="date" string="开始时间" filter_domain="[(‘date‘,‘>‘,self)]"/>
                    <field name="date" string="结束时间" filter_domain="[(‘date‘,‘<‘,self)]"/>
                </field>

                <filter name="ready" position="after">
                    <filter string="领料" name="slip"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production)d )]"/>
                    
                    <filter string="今日领料" name="slip1"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production)d ),(‘date‘, ‘<=‘, datetime.datetime.combine(context_today(), datetime.time(23,59,59))),(‘date‘,‘>=‘, datetime.datetime.combine(context_today(), datetime.time(0,0,0)))]"/>
                    <filter string="本周领料" name="slip2"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production)d ),(‘date‘, ‘>=‘, ((context_today()+relativedelta(weeks=-1, weekday=0)).strftime(‘%%Y-%%m-%%d‘))), ]"/>
                    <filter string="本月领料" name="slip3"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production)d ),(‘date‘, ‘like‘, time.strftime(‘%%Y-%%m‘))]"/>
                    <filter string="上月领料" name="slip4"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production)d ),(‘date‘, ‘<‘, time.strftime(‘%%Y-%%m-01‘)),(‘date‘,‘>=‘, (context_today() - relativedelta(months=1)).strftime(‘%%Y-%%m-01‘))]"/>
                    <separator/>

                    <filter string="退料" name="slip_return"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_material_production_return)d )]"/>
                    <filter string="收货" name="purchase"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(stock.picking_type_in)d )]"/>
                    <filter string="退货" name="purchase_return"
                            domain="[(‘state‘,‘=‘,‘done‘),(‘picking_type_id‘,‘=‘,%(mtlcs_stock.picking_type_purchase_input_return)d )]"/>
                </filter>
                <group string="Group By" position="inside">
                    <filter string="部门" name="groupby_department" icon="terp-gtk-jump-to-rtl" domain="[]"
                            context="{‘group_by‘:‘department_id‘}"/>
                </group>
            </field>
        </record>

以上是关于odoo xml 时间搜索条件的主要内容,如果未能解决你的问题,请参考以下文章

odoo14-实际使用

Odoo - 如何按日期搜索

odoo 中 ORM操作

Odoo 13 Enterprise SaaS,我可以编辑产品搜索模块以仅使用 JavaScript 搜索产品描述吗?

Odoo 10:更改树视图中的默认搜索

Odoo 13 - 搜索方法 - 使用模型相关字段的“订单”属性