跳至内容
菜单
此问题已终结
2 回复
1383 查看

i try to use xml rpc to read the calendar.event model :


 


model_name = 'calendar.event'
search_domain = []
search_result = models.execute_kw(db, uid, password, model_name, 'search_read', [search_domain]) 
print(search_result) 



but i get this error :

Traceback (most recent call last):
  File "c:\Users\PC\Desktop\New folder\models.py", line 5846, in ensure_one\n    raise ValueError("Expected singleton: %s" % self)\nValueError: Expected singleton: calendar.event(6, 3, 5, 4, 2, 1)\n'> 



can someone please explain for me what is the problem and how to use it correctely 

形象
丢弃
最佳答案

Hi,
At first look the code, seems to be fine, does it raise error if you remove the print(search_result) line ?

Also just change the model name to a different model like res.partner and see if that works and something wrong with this model only, so that it can be checked

Odoo XMLRPC: Search Read Method To Read From Database


Also specify the field names and see, it that brings any difference:

models.execute_kw(db, uid, password, model_name, 'search_read', [[]], {'fields': ['name']})


Thanks

形象
丢弃
最佳答案

Hi,

The error is arising due to there is more that one record contain in the search_result while you printing it. So to avoid singleton error provide a lupin in you function

Example:

search_result = models.execute_kw(db, uid, password, model_name, 'search_read', [search_domain])

for record in  search_result:  

    print(record)


Hope it helps

形象
丢弃
相关帖文 回复 查看 活动
5
2月 24
8483
0
11月 16
2893
1
6月 25
473
2
6月 25
2074
2
11月 24
8659