I am trying to replace the product_category model with an external datasource by extending the product_category model and overwriting the read method.
I used this topic as an example: https://www.odoo.com/forum/help-1/question/how-does-the-orm-read-method-work-exactly-1040
I don't want to replace or modify some values, but I want to use an external api to fetch the categories. So what I tried was fetching a list of categories with the python requests library, transforming the items in the list to the key/value structure that Odoo uses and returning this list.
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
url = 'http://localhost/.....json'
params = {
'apikey': '....',
'limit': 20
}
r = requests.get(url, params=params)
res = []
for cat in r.json():
res.append({
'id': cat[u'id'],
'complete_name': cat[u'name'],
'parent_id': None
})
return res
I got it working without errors, except for the fact that the actual json-rpc call only returns 1 result while a print statement in the method shows 20 items.
I know that the one item that is returned by the json-rpc call has an identical id to one of the product categories in the odoo system and the other 19 not. What am I missing here?
Maybe there is a more official way to do this?