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.

0

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

By
Martin Wasala
on 3/3/15, 6:07 AM 584 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

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

1 follower(s)

Stats

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