Search code examples
phpapiodooodoo-15

Odoo Api Externe


I'm trying to search in db odoo with api extern using php So my first code is


$url = 'http://localhost:Port';

$url_auth = $url.'/xmlrpc/2/common';

$url_exec = $url.'/xmlrpc/2/object';

$username = 'username';

$password = 'password';

$db = 'dbname';

require_once('ripcord/ripcord.php');

$common = ripcord::client($url_auth);

$models = ripcord::client($url_exec);

$uid = $common->authenticate($db, $username, $password, array()); 

$customer_ids = $models->execute_kw( $db, $uid,$password,    

                                                    'project.project', 

                                                'search', 

                                                array( array('name', '=', 'Sanda') ) );

This code is working well But I working to make a changes on it, I want that search it will be working on: that the name is start with 's' for exemple and I don't need more information about the rest of name How can I do this Thank you for helping me


Solution

  • You can work with search operator =like and the postgres wildcards % for any character or _ for exactly one character.

    So for your example "beginning with s" the domain would be ('name', '=like', 's%'). The operator =like is search case-sensitive.

    If you want to search case-insensitive use the operator =ilike: ('name', '=ilike', 's%').

    More about the operators and the search domains

    Hint: Using like or ilike without the leading = will tell Odoo to surround the search term with % wildcards. Which for the "beginning with s" search could find more and not wanted search results.