Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
1385 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
5
Feb 24
8484
0
Nov 16
2896
1
Jun 25
475
2
Jun 25
2076
2
Nov 24
8660