تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2813 أدوات العرض

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)

الصورة الرمزية
إهمال
أفضل إجابة

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

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

الكاتب

yes

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 24
984
3
أكتوبر 15
11284
2
فبراير 25
7915
1
أبريل 24
1070
1
أكتوبر 23
8227