如何在嵌套字典中调用值-Python / Openerp

时间:2017-08-10 11:49:37

标签: python python-2.7 openerp openerp-7

我正在尝试访问嵌套字典中的值并最终得到;

raise ValueError("Invalid field %r in leaf %r" % (left, str(leaf)))
ValueError: Invalid field 'att_date_date' in leaf "<osv.ExtendedLeaf: ('att_date_date', '<=', '2017-08-01') on on_call_days (ctx: )>"

请帮我解决这个问题。我的课程和其他必要的表达方式就像是吼叫;

on_call_days 字段;

'employee_id': fields.many2one('hr.employee', "Employee"),
'catagory_id':fields.related('employee_id', 'category', string='Emp Category', relation='hr.employee',store=True),
'oc_date':fields.date('From Date'),
'oc_amount':fields.float('Amount for the period'),
'processed_flag':fields.boolean("Entered flag"),

上课 allowance_attendances 字段;

'employee_id': fields.many2one('hr.employee', "Employee"),
'catagory_id':fields.related('employee_id', 'category', string='Emp Category', relation='hr.employee',store=True),        
'attendance_id':fields.integer("Attendance ID"),
'att_date':fields.char("Date"),
'att_date_date':fields.date("Date Date"),

class allowance_request 字段,这是我尝试使用这些表达式的类。

    'allowance_attendances_id':fields.one2many('allowance.attendances','allowance_request_id','Allowance Attendance'),
    'oc_days_id':fields.one2many('on.call.days','allowance_request_id','On Call Days'),

我试图做的是

   def onchange_employee(self, cr, uid, ids, employee_id,start_date,end_date,context=None):

        DATETIME_FORMAT2 = "%y/%m/%d"
        allo_att_obj=self.pool.get('allowance.attendances')
        on_call_obj=self.pool.get('on.call.days')
        val = {'value': {'allowance_attendances_id': [],'oc_days_id':[]}}
         if end_date:                

                filt +=[('att_date_date','<=', end_date)]            
            if start_date :              

                filt += [('att_date_date','>=', start_date)]

此功能还有其他功能,最后返回val

问题来自 filt + = [('att_date_date','&lt; =',end_date)] 我尝试从嵌套词典中检索值。请帮忙解决这个问题。

1 个答案:

答案 0 :(得分:1)

在这里你没有定义过滤器,所以你可能得到了回溯

Traceback (most recent call last):
File "<input>", line x, in <module>
NameError: name 'filt' is not defined

因此我将代码更改为:

def onchange_employee(self, cr, uid, ids, employee_id,start_date,end_date,context=None):

    DATETIME_FORMAT2 = "%y/%m/%d"
    allo_att_obj=self.pool.get('allowance.attendances')
    on_call_obj=self.pool.get('on.call.days')
    val = {'value': {'allowance_attendances_id': [],'oc_days_id':[]}}
    filt = []
    if end_date:                

            filt +=[('att_date_date','<=', end_date)]            
        if start_date :              

            filt += [('att_date_date','>=', start_date)]

如果它没有帮助,请告诉我日志。