Odoo Help

Welcome!

This community 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.

2

Replacing product_category with external data source

v8
By
Jacob Steringa
on 8/5/14, 12:10 PM 849 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?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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