2
votes

i'm using this class for accessing odoo through PHP XMLRPC. Everything works fine almost. I can't search many2one fields just by placing the id of the referenced record. I guess there should be a special way to code the many2one id in the search. EG: searching in product.supplierinfo by the product_tmpl_id using this code i get emtpy array returned:

$rpc->searchread(array(array("product_tmpl_id","=","3673")),"product.supplierinfo");

Searching for the record by id i get this result:

$rpc->read(array(1),"", "product.supplierinfo");
Array
(
    [0] => Array
        (
            [create_uid] => Array
                (
                    [0] => xxxxx
                    [1] => xxxxx xxxxx
                )

            [product_code] => 
            [create_date] => 2016-06-22 11:08:00
            [name] => Array
                (
                    [0] => 1438
                    [1] => Provider one
                )

            [product_uom] => Array
                (
                    [0] => 1
                    [1] => Unit(s)
                )

            [sequence] => 1
            [product_name] => 
            [__last_update] => 2016-06-22 11:42:28
            [company_id] => Array
                (
                    [0] => 1
                    [1] => Company Name
                )

            [write_uid] => Array
                (
                    [0] => xxxx
                    [1] => xxxxxx xxxxx
                )

            [delay] => 1
            [write_date] => 2016-06-22 11:42:28
            [pricelist_ids] => Array
                (
                )

            [display_name] => Provider One
            [min_qty] => 0
            [qty] => 0
            [product_tmpl_id] => Array
                (
                    [0] => 3673
                    [1] => Product Name
                )

            [id] => 1
        )

)

How should i code the id of a many2one field? Any help will be appreciated.

1
I'm not used to php but i'm wondering why the ID in your search array (first code snippet) is defined as string?CZoellner
@CZoellner thanks for your answer, as far as i know this does not affect since i can do this and find the record correctly $rpc->read(array(array("id","=","1")),array() ,"product.supplierinfo");rekobeko

1 Answers

3
votes

Finally i had the solution. As @czoellner suggested was a problem was the type of the ID was a string and must be an integer. So, this code worked fine.

$rpc->searchread(array(array("product_tmpl_id","=",3673)),"product.supplierinfo");

On the other hand must consider the issue between the id of the product.product and the id of the product.template because they are differents. The table product.supplierinfo uses the id of product.template instead product.product. That causes for searching through the table produc.supplierinfo is necessary to find first the product_tmpl_id of the product to refer to the product. So for finding a all the providers of a product:

#search it by id
$prod_odoo = $rpc->read(array(1),"product.product",array());
#every search returns a 2 dimension array
$prod_suppliers = $rpc->searchread(array(array("product_tmpl_id","=",(int)$prod_odoo[0]["product_tmpl_id"][0])),"product.supplierinfo");

Hope this helps.