[英]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:当使用 CookComputing (XML-RPC.net) 尝试在一个条件下搜索 mail.notification 模型时,它相当简单,因为您只需要调用:
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)]
.当您想要调用两个或多个条件搜索时,真正的问题就出现了 - 例如
[('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 [].
我试过传递一个包含两个对象的单个对象(一个带有partner_id,一个带有is_read) - 这会起作用,但Odoo也将其作为3对象域,在[]中添加partner_id。 Tried using string, tried using one object with 6 subargs - nothing seems to work.
尝试使用字符串,尝试使用一个带有 6 个子参数的对象 - 似乎没有任何效果。 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.尝试PortaCapena.OdooJsonRpcClient ,您可以使用存储库使用查询构建器创建高级过滤查询。 This library maps models from odoo to models in C#
这个库将模型从 odoo 映射到 C# 中的模型
https://github.com/patricoos/PortaCapena.OdooJsonRpcClient 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或使用 OdooFilter 查询
await repository
.Query()
.Where(OdooFilter.Create()
.GreaterThanOrEqual("write_date", new DateTime(2020, 12, 2))
.And()
.EqualTo("name", "Bioboxen 610l"))
.ToListAsync()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.