コンテンツへスキップ
メニュー
この質問にフラグが付けられました
4 返信
291 ビュー

Please here is my function:


def _get_project_id_by_name (self, cr, uid, project_name, context=None):

obj = self.pool.get('callim_project')

obj_ids = obj.search(cr, uid, [('project', '=', project_name)])

res = obj.read(cr, uid, obj_ids, ['id'], context)

print("--------------------get_project_id_by_name-------------------------")

print (res[0]['id'])

return res[0]['id']

I got this error: List of index out of range i didnt understand its source. Please help

アバター
破棄

Thanks a lot for the answer. I have corrected it but it doesnt work: def _get_project_id_by_name (self, cr, uid, project_name, context=None): obj = self.pool.get('callim_project') obj_ids = obj.search(cr, uid, [('project', '=', project_name)]) res = obj.read(cr, uid, obj_ids, ['id'], context) print("--------------------get_project_id_by_name-------------------------") if res == {}: return True else: return res[0]['id']

could you please print res and post what you get,...

最善の回答

Hi,

Index out of range error occurs when you are providing an index for which a list element does not exist.

Here you have to check whether res is empty or not before printing it.(You can use if statement for this)


Hope this helps.....


アバター
破棄
著作者 最善の回答

I tried to do this:


def _get_project_id_by_name (self, cr, uid, project_name, context=None):

obj = self.pool.get('callim_project')

obj_ids = obj.search(cr, uid, [('project', '=', project_name)])

res = obj.read(cr, uid, obj_ids, ['id'], context)

print("--------------------get_project_id_by_name-------------------------")

print res

if res == []:

return False

else:

return res[0]['id']


And it works now, i do not have any problem.

But when sir please i need extremely to know how to do this in odoo: 

services.create(cr,uid,value,context)??

Please help

アバター
破棄