Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
9650 Visualizzazioni

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

Avatar
Abbandona
Risposta migliore

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 ''.

Avatar
Abbandona
Autore

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.

Risposta migliore

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);
Avatar
Abbandona
Autore Risposta migliore

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);
Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
4
ott 17
28047
3
lug 25
2696
1
ott 24
1928
1
apr 24
1997
0
set 23
1580