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

Is it possible to retrieve 2 fields of all entry within a model thru xml-rpc?

By
Nicolas C
on 3/19/13, 6:32 AM 1,875 views

Hello,

First, I'm brand new in xml-rpc so please apologize if my question seems dummy :S

I need to connect my company custom software to openerp. My company software manage products only by reference (used like primary key) and openerp use "ids".

In order to correctly update product fields within product.product, I try to build like a "gateway" between both of them. This way, I want to retrieve all tuple of "default_code" & "ids" from openerp. I'll then be able to build a "hash" for translating "my company primary key" in "openerp primary key" for all my other write action (update).

Is there a "list" method or something that made something like "select ids,default_code from product.product"

I tried to use the "read" xml-rpc call, but : - empty value for "fields" give me all fields for a specified ids. - empty value for "ids" give me nothing.

Maybe a "wildcard" exists for ids ? I tried "*" but get an error...

DataError: invalid input syntax for integer: "*"

here is a sample code :

#!/usr/bin/perl
use strict;
use warnings;
use Frontier::Client;
use Data::Dumper;

my($user) = 'admin';
my($pw) = 'admin';
my($db) = 'Base2';
my($model) = 'product.product';

#login
my $server_url = 'h t t p : / / localhost:8069/xmlrpc/common';
my $server = Frontier::Client->new('url' => $server_url);
my $uid = $server->call('login',$db,$user,$pw);

my $server_url = 'h t t p : / / localhost:8069/xmlrpc/object';
my $server = Frontier::Client->new('url' => $server_url);

my $data = $server->call('execute',$db, $uid, $pw, $model, 'read', '*', '');

print Dumper($data);

Thank you in advance for any tips, advice, solution ;)

1

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/19/13, 8:04 AM

You first have to obtain the ids. You can do this with the search method like this:

my $ids = $server->call('execute',$db, $uid, $pw, $model, 'search', []);

I am not a Perl expert, so maybe the [] is not correct. [] should denote an empty array. (Maybe you can use '' instead)

Afterward you can execute the read method:

my $data = $server->call('execute',$db, $uid, $pw, $model, 'read', $ids, '');

If you want to only see certain fields you have to pass an array with the field names instead of the ''.

Thank you for your help. I dealed with the perl syntax but keep your "idea" : 1) make a search on all ids (using ' ') 2) use theses ids within read method.

Nicolas C
on 3/19/13, 11:09 AM
0
Nicolas C
On 3/19/13, 11:17 AM

Thank you yo Andreas I have the solution.

1st => search all ids 2nd => read the selected fields on the whole list of ids.

Only 2 rpc-xml requests :o)

Here is my code now :

#!/usr/bin/perl
use strict;
use warnings;
use Frontier::Client;
use Data::Dumper;

my($user) = 'admin';
my($pw) = 'admin';
my($db) = 'Base2';
my($model) = 'product.product';

#login
my $server_url = 'h t t p : / / localhost:8069/xmlrpc/common';
my $server = Frontier::Client->new('url' => $server_url);
my $uid = $server->call('login',$db,$user,$pw);

my $server_url = 'h t t p : / / localhost:8069/xmlrpc/object';
my $server = Frontier::Client->new('url' => $server_url);

# 1) search all ids
my $ids = $server->call('execute',$db, $uid, $pw, $model, 'search', '');

# 2) read the whole range of ids with required field only :
my $fields = ['name', 'default_code', 'ids'];
my $data = $server->call('execute',$db, $uid, $pw, $model, 'read', $ids, $fields);

print Dumper($data);
0

saad

--saad--
1008
| 5 4 8
Casablanca, Morocco
--saad--
saad
On 3/19/13, 8:05 AM

Use a search function with empty args to get all ids :

my $ids = $server->call('execute',$db, $uid, $pw, $model, 'search', []); 
my $fields = ['name','defaut_code']; 
my $data = $server->call('execute',$db, $uid, $pw, $model, 'read', $ids, $fields); 
print Dumper($data);

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: 3/19/13, 6:32 AM
Seen: 1875 times
Last updated: 3/16/15, 8:10 AM