Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
5631 Zobrazení

Hi There,

we are newbies and need to access the database via API, to get data for our own scripts. I can read out all the partners with their attributs from res.partner but when I read products I only get the name. All the other attributes are empty. Of course they are not empty in Odoo himself. And the names of the attributes do macht these which you can see in the list, when you are in dev mode. I don´t know how to get access to the other Fields in product.product or product.template

So this is how I do it in PHP.

$user_id=connect();
print "<br>Login Status: ".$user_id;
print "<hr>";
$client = new xmlrpc_client($server_url.'object');
$keys = array (
            new xmlrpcval(
                    array(new xmlrpcval('name' , "string"),
                                new xmlrpcval('!=',"string"),
                                new xmlrpcval("","string")
                                ),"array"             
                    ),
            );
//////////////////////////////////////////////////////////
//$table = 'res.partner'; WORKS
//$field_list = array("name|string","email|string","street|string","city|string", "zip|string","sale_order_count|integer", "contact_address|string","property_stock_customer|string","property_product_pricelist|string","parent_name|string"); WORKS

$table = 'product.template'; //OR 'product.product'
$field_list = array("price|float","name|string","color|integer","qty_available|float","sale_ok|boolean","type|selection"); //////////////////////////////////////////////////////////

for($g = 0; $g < count($field_list); $g++){
if(stristr($field_list[$g],'|')){$fieldparts=explode('|',$field_list[$g]);$field_list[$g]=$fieldparts[0];$fieldtype=$fieldparts[1];}else{$fieldtype='string';}
    array_push($fieldobjects, new xmlrpcval($field_list[$g], $fieldtype));
}

$result=search($client,$table,'id',$keys,$fieldobjects);

for($i = 0; $i < count($result); $i++){
print "#".$i."<br>";
            $result[$i]->me['struct'];
            for($g = 0; $g < count($field_list); $g++){
                print $field_list[$g].": <span style='color:red'>".@$result[$i]->me['struct'][$field_list[$g]]->me['string']."</span><br>";
            }
            print "<hr>";

    }

What am I doing wrong, why I can´t get the other fields?

Thanks a lot, Martin

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
zář 22
3017
1
zář 20
7279
1
bře 15
10495
1
dub 24
1503
0
led 23
5779