Swan White Swan White - 1 year ago 48
Python Question

How to call values in nested dictionary-Python/Openerp

I am trying to access to a value which is in nested dictionary and getting end up with ;

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: )>"


Please help me to fix this. My classes and other necessary expressions are like bellow;

class on_call_days fields;

'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"),


class allowance_attendances fields;

'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 fields and this is the class which I tried to use those expressions.

'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'),


What I tried to do is

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)]


There are other stuff going on here for this function and it will return val at the end.

The issue is coming from filt +=[('att_date_date','<=', end_date)] where I tried to retrieve value from that nested dictionaries. Please help met to fix this.

Answer Source

Here you didn't defined the filt, so probably you get the traceback

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

so I changed code as:

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)]

If it doesnt helps please get me the log.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download