odooxml-rpcopenerp-7

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


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:

UPDATE 1

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


Solution

  • My answer at OpenERP Q & A, and by Martin H. Bramwell. Mine follows:

    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);