Odoo Help


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.


ODOO9: How to correct this condition?

Drees Far
on 4/25/16, 5:16 AM 261 views

Hi everybody!!!!

I have a function that read the records of the table hr_department.

And i have this condition:

 '('id', '=', (3, u'Administration / test'))'

I want to correct this to ('id', '=', 3).

Can anyone help me know how to get the 3 from  (3, u'Administration / test')  (this field is a many2one on hr.department)

Here is the code:

        res = {}

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

for emp in self.browse(cr, uid, ids, context=context):

contract_ids = obj_contract.search(cr, uid, [('employee_id', '=', emp.id)], order='date_start', context=context)

if contract_ids:

vals = obj_contract.read(cr,uid,contract_ids,['department_id'],context=context)

departments = vals[0]['department_id']

if departments:

if vals:

obj_department = self.pool.get('hr.department')

department_ids = obj_department.search(cr, uid, [('id', '=', departments[0])], order='id', context=context)

On 4/25/16, 6:15 AM

using (3, u'Administration / test')[0] will give you 3

but I think you used fieldname in condition. try using fieldname.id instead

I updated my question @fasluca

Drees Far
on 4/25/16, 6:37 AM

what you get when you print that 'departments' ? is it (3, u'Administration / test') ?

on 4/25/16, 7:02 AM


Drees Far
on 4/25/16, 7:13 AM

try department_ids = obj_department.search(cr, uid, [('id', '=', departments[0][0])], order='id', context=context)

on 4/25/16, 7:14 AM

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)


Asked: 4/25/16, 5:16 AM
Seen: 261 times
Last updated: 4/25/16, 6:36 AM