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

XMLRPC: How to fetch a list of all ids that belongs to a given model?

By
Francisco Luz
on 4/15/14, 4:43 AM 3,157 views

I am aware that I have to structure my xmlrpc query like this:

ids = execute(dbname, uid, pwd, model, 'search', args)
fields = ['field_a', 'field_b', 'field_c']
elements = execute(dbname, uid, pwd, model, 'read', ids, fields)

I need help on structuring the args parameter in order to fetch a list of available elements from these models:

  • res.users as in Settings->Users
  • res.company as in Settings->Companies
  • res.partners as in Sales->Customers and Purchases->Suppliers
  • sale.order as in Sales->Sales Orders
  • account.invoice as in Accounting->Customer Invoices
  • purchase.order as in Purchases->Quotations and Purchases->Purchase Orders

UPDATE 1

Each model fetch request should return all the ids that belong to a given company id.

1
Francisco Luz
On 5/3/14, 5:13 PM

I see a lot of articles all over the internet talking about how to use xmlrpc on OpenERP 7 and all of them seem to be based on the xmlrpc documentation from the OpenERP 6.

Although not too sure, I think the xmlrpc docs from v6 is mostly outdated for v7.

For starters, there are new methods and endpoints on v7. They are:

  • Method read | /web/dataset/search_read
  • Method authenticate | /web/session/authenticate
  • Method get_session_info | /web/session/get_session_info
  • Method destroy | /web/session/destroy

For those like me interested in implementing a php app, I found this very handy library called php-oe-json hosted at github.

Here are some examples on how to retrieve data from OpenERP 7 using php-oe-json

$oe = new PhpOeJson\OpenERP('http://localhost:8069', 'database_name'); 
$oe->login('admin', 'pwd');

// Get a list of records from a model.
$products = $oe->read(array(
   'model' => 'product.product',
   'fields' => array('name', 'id'),
   'limit' => 20,
   // XXXvlab: bug of openerp 7.0+ which will default domain to "None" if not set, and
   // override of ``_search`` doesn't support ``None`` value.
   'domain' => array(),
));
echo '<pre>';
print_r($products);

// Get a single record from a model.
$so = $oe->read(array(
   'model' => 'sale.order',
   'fields' => array('name', 'id'),
   'limit' => FALSE,
   'domain' => array(array('company_id', '=', 1), array('name', '=', 'SO002')),
));

print_r($so);

So where is the V7 documentation?

Martin
on 5/3/14, 7:30 PM

There isn't any apparently. My guess is that the php-oe-json author just sniffed into the openerp web module for figuring out how the xmlrpc calls were processed.

Francisco Luz
on 5/4/14, 5:30 PM
1

Martin

--Martin--
1978
| 5 6 8
Cornwall, Canada
--Martin--

Analysing, designing, coding and mentoring since 1975. Kilobytes to terabytes. Punch cards to punchy sites. My OpenERP video series: http://www.youtube.com/playlist?list=PLq7op4J183lX44ZlXPiHxUpRvmmRDtxye My Google Speadsheets --> OpenERP Data Pump project: http://martinhbramwell.github.io/GData_OpenERP_Data_Pump My email (with spaces removed) : mhb . warehouseman @ gmail . com

Martin
On 4/15/14, 7:29 PM

I would strongly recommend that you do not try to work with XMLRPC directly.

Have a look at this: Should I use [oerplib] OR [openerp-client-lib] ?

The documentation of oerplib may have an example of what you are trying to do.

Update : When I first started working with XMLRPC APIs, I always found it necessary to start a little library of convenience routines. I'd end up fiddling with it, adding little bits, thinking up cool things to do, etc. etc. Next, thing I knew I'd got yet more code to maintain and all the crap that goes with it. The best way to deal with THAT is to open source it and hope to get collaborators who also need that functionality. It's at the point that I discover a pre-existing library that's much better done than my own and that I should have been using from outset.

Can you post why? Philosophical, Technical, etc?

Bista Solutions US, Ray Carnes
on 4/15/14, 11:34 PM

My hope is to be able to communicate with OpenERP without having to use python. I will take a look at the links you provided. Thank you.

Francisco Luz
on 4/16/14, 12:27 AM

I played with oerplib and apparently it has what I need. Although it would be better if did not have to write my own intermediary python service.

Francisco Luz
on 4/16/14, 1:51 AM

What language are you using then?

Martin
on 4/16/14, 10:05 AM

PHP.......

Francisco Luz
on 4/16/14, 9:26 PM

Ok. Now it is clear why my answer is less than relevant. Thanks for flagging it as the right answer despite that. If you published a PHP version of oerplib.py on GitHub I expect you'd get some eager collaborators eventually, even if what you put there served exactly your needs and no more..

Martin
on 4/18/14, 9:20 AM

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

0 follower(s)

Stats

Asked: 4/15/14, 4:43 AM
Seen: 3157 times
Last updated: 3/16/15, 8:10 AM