Odoo Help

2

Replacing product_category with external data source

v8
By
Jacob Steringa
on 8/5/14, 12:10 PM 981 views

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?

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 8/5/14, 12:10 PM
Seen: 981 times
Last updated: 3/16/15, 8:10 AM