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.

0

How to use the osv ORM to fetch all products in Python? (Or all customers, or any other type)

By
Kasper Souren
on 7/14/14, 2:42 PM 1,118 views

How to use the osv ORM to fetch all products in Python? (Or all customers, or any other type)

Got as far as

python

>>> import openerp

>>> tools.config.parse_config(['--addons-path=addons'])

>>> import openerp.addons.product

>>> openerp.addons.product.product_product.search?

Ok, so I need to pass cr, uid and args. What are these?

0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 7/15/14, 2:38 AM

If you are trying to fetch data from odoo db from outside of odoo (ie. some external aplication or script) you should use xmlrpc protocol.

here is an example of xmlrpc usage: https://www.odoo.com/forum/Help-1/question/Can-someone-tell-me-how-to-create-and-write-objects-using-JSON-RPC-calls-52660#answer-53218

If you are doing it from some custom module for odoo, then you use odoo orm to fetch like:

The folowing line fill fetch all ids of records in 'some.model'.. once you have ids, fetch the records...

data_ids = self.pool.get('some.model').search(cr, uid, [])

explained:
- some.model iz actual database model (res.partner, product.product...) 
- cr = database cursor
- uid = current user id
- [] - is search parameter, in this case simply take all record from 'some.model'
----> example of using simple criteria : [('name','=', something)]  will search for all records that match ctireria name = something.. 

note: this is sytax for v7, in v8 this will work, but you can also use new syntax ( cr and uid is not needed anymore, it is already in self..)

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: 7/14/14, 2:42 PM
Seen: 1118 times
Last updated: 3/16/15, 8:10 AM