Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
1370 Widoki

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 

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
5
lut 24
8478
0
lis 16
2881
1
cze 25
470
2
cze 25
2071
2
lis 24
8651