This question has been flagged
3 Replies
5830 Views

Hello everybody:

Please, i have an employee_id which is a many2one field.

And a function to fill in the any2one but my function allows me to get the employee_id in hr_contract model.

I got every thing but when i click i have got an error:

Python:

obj3 = self.pool.get('hr.contract')

obj_ids3 = obj3.search(cr, uid, [('employee_id','=',key)])

res3 = obj3.read(cr, uid, obj_ids3, ['id', 'date_start','trial_date_start','employee_id'], context) 

for s in res3:

print s['date_start']

if s['trial_date_start'] == False:

s['date_start'] = s['date_start']

else:

s['date_start'] = s['trial_date_start']

key = s['employee_id']

print key[1]

inputs = {

'date_contract' : s['date_start'],

'matricule' : key[0],

'employee_id' : s['employee_id'],

'initial_leaves' : 0.0,

}

ret += [inputs]

And the field is:

'employee_id' : fields.many2one('hr.employee', string="Employee"),

The error:

2015-11-04 16:13:31,073 14952 ERROR openerp openerp.sql_db: bad query: insert into "seetek_leaves_line" (id,"year_id","employee_id","date_contract","initial_leaves","matricule",create_uid,create_date,write_uid,write_date) values (129,25,ARRAY[2, 'ABDELWAHED RIHENE'],'2015-08-29',0.0,2,1,(now() at time zone 'UTC'),1,(now() at time zone 'UTC'))

Traceback (most recent call last):

File "/opt/openerp/v7/server/openerp/sql_db.py", line 226, in execute

res = self._obj.execute(query, params)

DataError: invalid input syntax for integer: "ABDELWAHED RIHENE"

LIGNE 1 : ...ate,write_uid,write_date) values (129,25,ARRAY[2, 'ABDELWAHE...

^

Can any one help me please


Avatar
Discard
Author Best Answer

Hi friends;

Here is the solution:

obj3 = self.pool.get('hr.contract')

obj_ids3 = obj3.search(cr, uid, [('employee_id','=',key)])

res3 = obj3.browse(cr, uid, obj_ids3, context=context)

for s in res3:

if s.trial_date_start == False:

date_start = s.date_start

else:

date_start = s.trial_date_start 

inputs = {

'date_contract' : date_start,

'matricule' : s.employee_id.matricule

'employee_id' : s.employee_id.id,

'initial_leaves' : 0.0,

}

ret.append(inputs)

return ret

Regards.

Avatar
Discard
Best Answer

You may try like this:


obj3 = self.pool.get('hr.contract')
obj_ids3 = obj3.search(cr, uid, [('employee_id','=',key)])
res3 = obj3.browse(cr, uid, obj_ids3, context=context)
for s in res3:
if s.trial_date_start == False:
date_start = s.date_start
else:
date_start = s.trial_date_start
key = s.employee_id
inputs = {

'date_contract' : date_start,

'matricule' : key[0],

'employee_id' : s.employee_id.id,

'initial_leaves' : 0.0,

}
ret.append(inputs)

return ret


Avatar
Discard
Author

Thanks a lot akhil for your help but there is a little mistake :/ i have corrected it below :)

That was not a mistake Drees, because I didn't what you meant by matricule. The problem in your question was instead of employee_id which is supposed to be an integer, you were passing an array. So dealing with a browse method is better than with read method to get it correctly. I just randomly put matricule, as you can give any value which you may need. But I forgot to mention it, that was my mistake, I agree :)