private OdooRpcRequest CreateGetRequest(OdooSessionInfo sessionInfo, OdooGetModelFieldsParameters parameters) { List <object> requestArgs = new List <object>( new object[] { sessionInfo.Database, sessionInfo.UserId, sessionInfo.Password, parameters.Model, "fields_get", new object[0] } ); dynamic fieldOptions = new ExpandoObject(); if (parameters.Attributes != null && parameters.Attributes.Count > 0) { fieldOptions.attributes = parameters.Attributes.ToArray(); } else { fieldOptions.attributes = new string[] { "string", "help", "type" }; } requestArgs.Add(fieldOptions); return(new OdooRpcRequest() { service = "object", method = "execute_kw", args = requestArgs.ToArray(), context = sessionInfo.UserContext }); }
public async Task GetDepartmentsFields() { try { var reqParams = new OdooGetModelFieldsParameters( "hr.department" ); var fields = await this.OdooRpcClient.GetModelFields <dynamic>(reqParams); fields.ToList().ForEach(f => Console.WriteLine(f)); } catch (Exception ex) { Console.WriteLine("Error getting partners from Odoo: {0}", ex.Message); } }
public async Task GetModelFields_ShouldCallRpcWithCorrectParameters() { var requestParameters = new OdooGetModelFieldsParameters( "res.partner", new OdooFieldParameters(new string[] { "string", "help", "type" }) ); Dictionary <string, dynamic> testResults = new Dictionary <string, dynamic>(); testResults["ean13"] = new { type = "char", help = "BarCode", @string = "EAN13" }; testResults["property_account_position"] = new { type = "many2one", help = "The fiscal position will determine taxes and accounts used for the partner.", @string = "Fiscal Position" }; var response = new JsonRpcResponse <Dictionary <string, dynamic> >(); response.Id = 1; response.Result = testResults; await TestOdooRpcCall(new OdooRpcCallTestParameters <Dictionary <string, dynamic> >() { Model = "res.partner", Method = "fields_get", Validator = (p) => { Assert.Equal(7, p.args.Length); dynamic args = p.args[5]; Assert.Equal(0, args.Length); }, ExecuteRpcCall = () => RpcClient.GetModelFields <dynamic>(requestParameters), TestResponse = response }); }
public Task <Dictionary <string, T> > Execute <T>(OdooSessionInfo sessionInfo, OdooGetModelFieldsParameters parameters) { return(InvokeRpc <Dictionary <string, T> >(sessionInfo, CreateGetRequest(sessionInfo, parameters))); }
public Task <Dictionary <string, T> > GetModelFields <T>(OdooGetModelFieldsParameters parameters) { var getCommand = new OdooGetModelFieldsCommand(CreateRpcClient()); return(getCommand.Execute <T>(this.SessionInfo, parameters)); }