Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to fill a many2one field in openerp

By
Drees Far
on 11/4/15, 11:32 AM 807 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


0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 11/5/15, 4:30 AM

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.

2

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 11/4/15, 12:09 PM

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


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

Drees Far
on 11/5/15, 4:28 AM

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

Akhil P Sivan
on 11/5/15, 12:19 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/4/15, 11:32 AM
Seen: 807 times
Last updated: 11/21/15, 6:08 AM