public async Task Get_WithSearch_And_Fields_And_Pagination_ShouldCallRpcWithCorrectParameters()
        {
            var requestParameters = new OdooSearchParameters(
                "res.partner",
                new OdooDomainFilter()
                .Filter("is_company", "=", true)
                .Filter("customer", "=", true)
                );

            var testPartners = new TestPartner[]
            {
                new TestPartner()
                {
                    comment    = false,
                    country_id = new object[] { 21, "Belgium" },
                    id         = 7,
                    name       = "Agrolait"
                },
                new TestPartner()
                {
                    comment    = false,
                    country_id = new object[] { 21, "Belgium" },
                    id         = 8,
                    name       = "Parmalait"
                }
            };

            var response = new JsonRpcResponse <TestPartner[]>();

            response.Id     = 1;
            response.Result = testPartners;

            await TestOdooRpcCall(new OdooRpcCallTestParameters <TestPartner[]>()
            {
                Validator = (p) =>
                {
                    Assert.Equal(7, p.args.Length);

                    dynamic args = p.args[5];
                    Assert.Equal(2, args[0].Length);
                    Assert.Equal(
                        new object[]
                    {
                        new object[] { "is_company", "=", true },
                        new object[] { "customer", "=", true }
                    },
                        args[0]
                        );
                    dynamic searchArgs = p.args[6];
                    Assert.Equal(0, searchArgs.offset);
                    Assert.Equal(5, searchArgs.limit);
                    Assert.Equal(new string[] { "name", "country_id", "comment" }, searchArgs.fields);
                },
                Model          = requestParameters.Model,
                Method         = "search_read",
                ExecuteRpcCall = () => RpcClient.Get <TestPartner[]>(requestParameters, new OdooFieldParameters(new string[] { "name", "country_id", "comment" }), new OdooPaginationParameters(0, 5)),
                TestResponse   = response
            });
        }
        public async Task Search_WithPaginationWithOrder_ShouldCallRpcWithCorrectParameters()
        {
            var requestParameters = new OdooSearchParameters(
                "res.partner",
                new OdooDomainFilter()
                .Filter("is_company", "=", true)
                .Filter("customer", "=", true)
                );

            var testResults = new long[] {
                7L, 18L, 12L, 14L, 17L, 19L
            };

            var response = new JsonRpcResponse <long[]>();

            response.Id     = 1;
            response.Result = testResults;

            await TestOdooRpcCall(new OdooRpcCallTestParameters <long[]>()
            {
                Model     = "res.partner",
                Method    = "search",
                Validator = (p) =>
                {
                    Assert.Equal(7, p.args.Length);

                    dynamic domainArgs = p.args[5];
                    Assert.Equal(2, domainArgs[0].Length);
                    Assert.Equal(
                        new object[]
                    {
                        new object[] { "is_company", "=", true },
                        new object[] { "customer", "=", true }
                    },
                        domainArgs[0]
                        );
                    dynamic pagArgs = p.args[6];
                    Assert.Equal(0, pagArgs.offset);
                    Assert.Equal(5, pagArgs.limit);
                    Assert.Equal("customer ASC, id ASC, name DESC", pagArgs.order);
                },
                ExecuteRpcCall = () => RpcClient.Search <long[]>(requestParameters, new OdooPaginationParameters(0, 5).OrderBy("customer").ThenBy("id").ThenByDescending("name")),
                TestResponse   = response
            });
        }
Ejemplo n.º 3
0
        public async Task SearchDepartments()
        {
            try
            {
                var reqParams = new OdooSearchParameters(
                    "hr.department",
                    new OdooDomainFilter().Filter("name", "like", "SIC")
                    );

                var count = await this.OdooRpcClient.SearchCount(reqParams);

                var departments = await this.OdooRpcClient.Search <long[]>(reqParams, new OdooPaginationParameters(0, 1));

                Console.WriteLine(departments.FirstOrDefault());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message);
            }
        }
        public async Task Search_ShouldCallRpcWithCorrectParameters()
        {
            var requestParameters = new OdooSearchParameters(
                "res.partner",
                new OdooDomainFilter()
                .Filter("is_company", "=", true)
                .Filter("customer", "=", true)
                );

            var testResults = new long[] {
                7L, 18L, 12L, 14L, 17L, 19L
            };

            var response = new JsonRpcResponse <long[]>();

            response.Id     = 1;
            response.Result = testResults;

            await TestOdooRpcCall(new OdooRpcCallTestParameters <long[]>()
            {
                Model     = "res.partner",
                Method    = "search",
                Validator = (p) =>
                {
                    Assert.Equal(6, p.args.Length);

                    dynamic args = p.args[5];
                    Assert.Equal(2, args[0].Length);
                    Assert.Equal(
                        new object[]
                    {
                        new object[] { "is_company", "=", true },
                        new object[] { "customer", "=", true }
                    },
                        args[0]
                        );
                },
                ExecuteRpcCall = () => RpcClient.Search <long[]>(requestParameters),
                TestResponse   = response
            });
        }
Ejemplo n.º 5
0
        public Task <T> Get <T>(OdooSearchParameters getParams, OdooFieldParameters fieldParams, OdooPaginationParameters pagParams)
        {
            var searchReadCommand = new OdooSearchCommand(CreateRpcClient());

            return(searchReadCommand.Execute <T>(this.SessionInfo, getParams, fieldParams, pagParams));
        }
Ejemplo n.º 6
0
 public Task <T> Get <T>(OdooSearchParameters getParams, OdooPaginationParameters pagParams)
 {
     return(Get <T>(getParams, new OdooFieldParameters(), pagParams));
 }
Ejemplo n.º 7
0
        public Task <long> SearchCount(OdooSearchParameters searchParams)
        {
            var searchCommand = new OdooSearchCommand(CreateRpcClient());

            return(searchCommand.ExecuteCount(this.SessionInfo, searchParams));
        }
Ejemplo n.º 8
0
        public Task <T> Search <T>(OdooSearchParameters searchParams, OdooPaginationParameters pagParams)
        {
            var searchCommand = new OdooSearchCommand(CreateRpcClient());

            return(searchCommand.Execute <T>(this.SessionInfo, searchParams, pagParams));
        }
Ejemplo n.º 9
0
        private OdooRpcRequest CreateSearchRequest(OdooSessionInfo sessionInfo, string method, OdooSearchParameters searchParams, OdooFieldParameters fieldParams, OdooPaginationParameters pagParams)
        {
            List <object> requestArgs = new List <object>(
                new object[]
            {
                sessionInfo.Database,
                sessionInfo.UserId,
                sessionInfo.Password,
                searchParams.Model,
                method,
                new object[]
                {
                    searchParams.DomainFilter.ToFilterArray()
                }
            }
                );

            dynamic searchOptions    = new ExpandoObject();
            bool    useSearchOptions = false;

            if (fieldParams != null && fieldParams.Count > 0)
            {
                searchOptions.fields = fieldParams.ToArray();
                useSearchOptions     = true;
            }

            if (pagParams != null && pagParams.IsDefined())
            {
                pagParams.AddToParameters(searchOptions);
                useSearchOptions = true;
            }

            if (useSearchOptions)
            {
                requestArgs.Add(searchOptions);
            }

            return(new OdooRpcRequest()
            {
                service = "object",
                method = "execute_kw",
                args = requestArgs.ToArray(),
                context = sessionInfo.UserContext
            });
        }
Ejemplo n.º 10
0
 public Task <T> Execute <T>(OdooSessionInfo sessionInfo, OdooSearchParameters searchParams, OdooFieldParameters fieldParams, OdooPaginationParameters pagParams)
 {
     return(InvokeRpc <T>(sessionInfo, CreateSearchRequest(sessionInfo, "search_read", searchParams, fieldParams, pagParams)));
 }
Ejemplo n.º 11
0
 public Task <long> ExecuteCount(OdooSessionInfo sessionInfo, OdooSearchParameters searchParams)
 {
     return(InvokeRpc <long>(sessionInfo, CreateSearchRequest(sessionInfo, "search_count", searchParams, null, null)));
 }