Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1378 Visualizzazioni

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 

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona
Risposta migliore

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

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
5
feb 24
8481
0
nov 16
2887
1
giu 25
471
2
giu 25
2074
2
nov 24
8658