Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
domain openerp如何比较odoo中的2个日期字段_Openerp_Odoo_Openerp 7_Openerp 8_Odoo 8 - Fatal编程技术网

domain openerp如何比较odoo中的2个日期字段

domain openerp如何比较odoo中的2个日期字段,openerp,odoo,openerp-7,openerp-8,odoo-8,Openerp,Odoo,Openerp 7,Openerp 8,Odoo 8,我创建了一个方法,当我将收到产品和数量的日期更改为stock.move的日期时,我在类中声明start\u date=fields.Datetime() def onchange_project(self, cr, uid,start_date): """ onchange handler of start date. """ pool_stockmove =self.pool.get('stock.move') domain =[('date','&

我创建了一个方法,当我将收到产品和数量的日期更改为stock.move的日期时,我在类中声明
start\u date=fields.Datetime()

def onchange_project(self, cr, uid,start_date):
    """
    onchange handler of start date.
    """  
    pool_stockmove =self.pool.get('stock.move')
    domain =[('date','>=',start_date)]  
    ids = pool_stockmove.search(cr, uid, domain)

这个方法很好用,但我想比较一下开始日期>=开始日期和日期之间的“库存日期”,你可以试试这样的方法

 cr.execute("SELECT id FROM hr_timesheet_sheet_sheet WHERE (date_from >= %s AND date_to <= %s) AND (user_id=%s) AND (id <> %s)",(sheet.date_from,sheet.date_to, new_user_id, sheet.id))                 
 if cr.fetchall():
     return False

cr.execute(“从hr\u时间表\u工作表中选择id,其中(date_from>=%s和date_to日期以字符串格式存储。您可以像hr示例中那样使用sql进行比较,但我建议使用ORM而不是原始sql进行比较。这更方便,建议始终使用它,因为
sql
可以逃避用代码编写的安全性和其他检查(但在您的代码中可能不是这样)

很难理解你想和哪个日期比较,为什么你不能这样做

我猜你想做这样的事情:

[('date', '>=', 'start_date'), ('date', '<=', 'start_date')]
它的意思与上面一行相同(如果使用
“|”
,则表示

Odoo damains使用波兰符号:

对于日期格式,如果需要,可以使用python模块
datetime
更改日期格式。

这是一个简单的示例: employees=self.env['hr.employee'].search([],order='name asc')

对于员工中的员工:
出席人数=self.env['hr.attention'].搜索人数([
('employee_id','=',employee.id),
('check_in','>=',date_start_obj.strftime(DATETIME格式)),

(‘check_out’,‘谢谢你的回复。我不知道如何用方法格式化日期,以及如何调用它来使用要格式化的开始日期。这是我非常需要的。
[('date', '>=', 'start_date'), ('date', '<=', 'start_date')]
['&', ('date', '>=', 'start_date'), ('date', '<=', 'start_date')]
    for employee in employees:
        presence_count = self.env['hr.attendance'].search_count([
            ('employee_id', '=', employee.id),
            ('check_in', '>=', date_start_obj.strftime(DATETIME_FORMAT)),
            ('check_out', '<=', date_end_obj.strftime(DATETIME_FORMAT)),
        ])

        absence_count = date_diff - presence_count

        docs.append({
            'employee': employee.name,
            'presence': presence_count,
            'absence': absence_count,
        })