sauljabin / xmlrpcwsc-dotnet

XML-RPC Web Service Client C# implementation
GNU Lesser General Public License v3.0
34 stars 21 forks source link

How to search_read odoo's certain model? #4

Closed akira32chen closed 2 years ago

akira32chen commented 5 years ago

I want to reach this goal as below: Could somebody know how to write by using C#?

models.execute_kw(db, uid, password,
    'res.partner', 'search_read',
    [[['is_company', '=', True], ['customer', '=', True]]],
    {'fields': ['name', 'country_id', 'comment'], 'limit': 5})
fjarboleda-lm commented 3 years ago

A example will be clear enough? `-------------------------------------------------------------------------------------------- var client = new XmlRpcClient(); client.Url = Url; // https://odoo.whatever.com:443/xmlrpc/2 client.Path = "object";

        var restrito = XmlRpcParameter.AsArray(
                            XmlRpcParameter.AsArray(
                                XmlRpcParameter.AsArray("is_company", "=", true),
                                XmlRpcParameter.AsArray("is_blacklisted", "=", true)
                                // customer doesn't exist Maybe "company_type" = "person"
                           ));

        // Really restrito  is a List<object>(){ List<object>() { ...  }}
        //  and every restriction is List<object> with 3 items, 
        //          field name, string with a operator and filter value. 

        var modif = XmlRpcParameter.AsStruct(
                            XmlRpcParameter.AsMember("fields", 
                                    XmlRpcParameter.AsArray("name", "country_id", "comment")),
                            XmlRpcParameter.AsMember("limit", 5)
                            );

        // Really modif  is a Dictionary<string,object>
        //  and fields is a List<object>() { ... } and limit a [key, value]

        XmlRpcRequest requestSearch = new XmlRpcRequest("execute_kw");
        requestSearch.AddParams(db, uid, password, "res.partner", "search_read",
                                                        restrito, modif );

        var responseSearch = client.Execute(requestSearch);

        var str = responseSearch.GetString();

`

sauljabin commented 2 years ago

thanks @fjarboleda-lm