Odoo Help

0

Can get only the name of product when reading via API and PHP

By
Martin Wasala
on 3/3/15, 6:07 AM 715 views

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

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 3/3/15, 6:07 AM
Seen: 715 times
Last updated: 3/16/15, 8:10 AM