简体   繁体   中英

XML-RPC Odoo - C# multiple search conditions

When using CookComputing (XML-RPC.net) trying to search on mail.notification model with just one condition, it is rather simple, as you just have to call:

object[] args = new object[1];
object[] subargs = new object[3];
subargs[0] = "partner_id";
subargs[1] = "=";
subargs[2] = partner_id.ToString();
int[] message_count = odooNewProxy.Search(database, userId, odoo_password, "mail.notification", "search", args);

Where Search is defined like:

[XmlRpcMethod("execute")]
int[] Search(string dbName, int userId, string pwd, string model, string method, object[] filters);

and you will get a result right away. The real problem comes when you want to call a two-or-more conditional search - such as [('partner_id', '=', 3), ('is_read', '=', False)] . Does anyone have any clue on that? I've tried passing a single object containing two objects (one with partner_id, one with is_read) - that will work, but Odoo also takes that as a 3-objects domain, adding partner_id in []. Tried using string, tried using one object with 6 subargs - nothing seems to work. Any help will be appreciated.

Just try this way:

object[] args= new object[] {
    new object[] { "move_lines", "!=", null },
    new object[] { "state", "!=", "done"}
};
OdooAPI api = GetApiObject();
        object[] filter = new object[3];
        int id = 0;
        filter[0] = new object[3] { "supplier", "=", true };
        filter[1] = new object[3] { "active", "=", true };
        filter[2] = new object[3] { "ref", "=", internal_reference };

Try PortaCapena.OdooJsonRpcClient , U can create advanced filtering queries using query builder using repository. This library maps models from odoo to models in C#

https://github.com/patricoos/PortaCapena.OdooJsonRpcClient

var products = await repository.Query()
.Where(x => x.WriteDate, OdooOperator.GreaterThanOrEqualTo, new DateTime(2020, 12, 2))
.Where(x => x.Name, OdooOperator.EqualsTo, "Bioboxen 610l")
.Select(x => new
{
      x.Name,
      x.Description,
      x.WriteDate
})
.OrderByDescending(x => x.Id)
.Take(10)
.FirstOrDefaultAsync();

or using query with OdooFilter

await repository
.Query()
.Where(OdooFilter.Create()
     .GreaterThanOrEqual("write_date", new DateTime(2020, 12, 2))
     .And()
     .EqualTo("name", "Bioboxen 610l"))
.ToListAsync()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM