Ejemplo n.º 1
0
        private OdooRpcRequest CreateReadRequest(OdooSessionInfo sessionInfo, OdooGetParameters getParams, OdooFieldParameters fieldParams)
        {
            List <object> requestArgs = new List <object>(
                new object[]
            {
                sessionInfo.Database,
                sessionInfo.UserId,
                sessionInfo.Password,
                getParams.Model,
                "read",
                new object[]
                {
                    getParams.Ids
                }
            }
                );

            if (fieldParams != null && fieldParams.Count > 0)
            {
                dynamic getOptions = new ExpandoObject();
                getOptions.fields = fieldParams.ToArray();
                requestArgs.Add(getOptions);
            }

            return(new OdooRpcRequest()
            {
                service = "object",
                method = "execute_kw",
                args = requestArgs.ToArray(),
                context = sessionInfo.UserContext
            });
        }
        public async Task Get_WithIds_ShouldCallRpcWithCorrectParameters()
        {
            var requestParameters = new OdooGetParameters("res.partner", new long[] { 7 });

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

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

            response.Id     = 1;
            response.Result = new TestPartner[] {
                testPartner
            };

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

                    Assert.Equal(1, args.Length);
                    Assert.Equal(requestParameters.Ids, args[0]);
                },
                Model          = requestParameters.Model,
                Method         = "read",
                ExecuteRpcCall = () => RpcClient.Get <TestPartner[]>(requestParameters),
                TestResponse   = response
            });
        }
Ejemplo n.º 3
0
        public Task <T> Get <T>(string model, long id)
        {
            var getParams = new OdooGetParameters(model);

            getParams.Ids.Add(id);

            return(this.Get <T>(getParams, new OdooFieldParameters()));
        }
Ejemplo n.º 4
0
        public async Task GetDepartments()
        {
            try
            {
                var reqParams = new OdooGetParameters("hr.department");
                reqParams.Ids.Add(6);
                //reqParams.Ids.Add(7);

                var fieldParams = new OdooFieldParameters();
                fieldParams.Add("name");
                fieldParams.Add("company_id");

                var departments = await this.OdooRpcClient.Get <JObject[]>(reqParams, fieldParams);

                Console.WriteLine(departments.FirstOrDefault());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message);
            }
        }
Ejemplo n.º 5
0
        public Task <T> Get <T>(OdooGetParameters getParams, OdooFieldParameters fieldParams)
        {
            var readCommand = new OdooReadCommand(CreateRpcClient());

            return(readCommand.Execute <T>(this.SessionInfo, getParams, fieldParams));
        }
Ejemplo n.º 6
0
 public Task <T> Get <T>(OdooGetParameters getParams)
 {
     return(Get <T>(getParams, new OdooFieldParameters()));
 }
Ejemplo n.º 7
0
 public Task <T> Execute <T>(OdooSessionInfo sessionInfo, OdooGetParameters getParams, OdooFieldParameters fieldParams)
 {
     return(InvokeRpc <T>(sessionInfo, CreateReadRequest(sessionInfo, getParams, fieldParams)));
 }