Skip to Content
Menu
This question has been flagged
3 Replies
1671 Views

The following code fails when exceuting the read method.  More specifically the fault is: HrEmployeePrivate.read() missing 1 required positional argument: \'fields\'\n'>

... so the the two questions obviously are: (1) What this field & (2) how to adjust the code that the read works.... 

======== Python / Odoo 16 ================

model = "hr.employee"

search = [('work_email','=', 'Donald.Duck@somecompany.com')]

method = "search"


operation = xmlrpc.client.ServerProxy(url+"/xmlrpc/object")

list_of_employee_ids = operation.execute(db, internalID, password, model, method, search)


print(list_of_employee_ids)


method = "read"


list_of_employee_detail = operation.execute(db, internalID, password, model, method, list_of_employee_ids)


Avatar
Discard
Best Answer

Hi Markus Schmid,

in above error shows that missing fields which you need to read,

try this then check,

fields_to_read = ['name', 'work_email', 'other_field_name']

method = "read"

# Perform read operation with specified fieldslist_of_employee_detail = operation.execute(db, internalID, password, model, method, list_of_employee_ids, fields_to_read)

Thanks

Avatar
Discard
Best Answer

Is the list_of_employee_ids​ a valid list? What does the print statement output? See, e.g., the example in the official documentation (https://www.odoo.com/documentation/16.0/developer/reference/external_api.html#read-records):

ids = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'limit': 1})
[record] = models.execute_kw(db, uid, password, 'res.partner', 'read', [ids])

The list of fields to fetch is optional for a read request, so you don't have to use that. Why don't you use the search_read​ method instead? Odoo provides a search_read() shortcut which is equivalent to a search() followed by a read(), but avoids having to perform two requests and keep ids around (see documentation link above). E.g.,

models.execute_kw(db, uid, password, 'res.partner', 'search_read', [[['is_company', '=', True]]], {'fields': ['name', 'country_id', 'comment'], 'limit': 5})

I hope this helps!

Avatar
Discard
Author

Thank you for pointing that out!

The updated python code (combining what Nikhil & Jort point out) looks as follows:

import xmlrpc.client

url = 'https://AAAAAAAAA.odoo.com/'
db = 'AAAAAAAAA'
username = 'XXXXX@zzzz.com'
password = 'correctpassword for username'

common = xmlrpc.client.ServerProxy(url+"/xmlrpc/common")
internalID = common.login(db, username,password)

model = "hr.employee"
method = 'search_read'
search = [[['work_email','=', eMail]]]
fields_to_read = {'fields': ['name', 'job_id', 'parent_id', 'hourly_cost']}

operation = xmlrpc.client.ServerProxy(url+"/xmlrpc/object")

list_of_employee_detail = operation.execute_kw(db, internalID, password, model, method, search, fields_to_read )

print(list_of_employee_detail)

Author Best Answer

Thank you!

One question: In some cases it works without the "fields_to_read"..... 

To be consistent on my side.... Can I add the "fields_to_read" to all my xml/rpc reads?

Regardless:  You have been a great help for me!  

Thanks again!

Avatar
Discard
Related Posts Replies Views Activity
0
Mar 25
327
4
Apr 24
172488
0
Dec 23
1332
5
Feb 25
223307
1
Dec 22
2299