diff --git a/.gitignore b/.gitignore index 4e4341c..e43de7a 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,9 @@ UpgradeLog*.htm *.pidb *.*sdf *.ipch + +# Vscode user-specific files +.vscode/ + +# appsetting envs +appsettings.*.json \ No newline at end of file diff --git a/README.md b/README.md index 5250dd6..eaaeac6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OdooRpc.CoreCLR.Client -Simple [Odoo JSON-RPC](https://www.odoo.com/documentation/9.0/api_integration.html) Client for [.Net Core 1.0](https://www.microsoft.com/net/core). +Simple [Odoo JSON-RPC](https://www.odoo.com/documentation/9.0/api_integration.html) Client for [.Net Core 3.1](https://www.microsoft.com/net/core). Inspired by https://github.com/saidimu/odoo and https://github.com/osiell/odoorpc. @@ -37,9 +37,16 @@ You will need nuget.exe on your path and set the NuGet API Key before you can pu ```Shell nuget.exe setApiKey 76d7xxxx-xxxx-xxxx-xxxx-eabb8b0cxxxx -nuget.exe push .\build\OdooRpc.CoreCLR.Client.0.0.1.nupkg +nuget.exe push .\build\OdooRpc.CoreCLR.Client.V3.2.2.0.nupkg ``` ### Samples +All updated to work with dotnetcore 3.1 -*TODO* +1. update the appsettings.json file (note: enter the host without protocol prefix, and set the use of ssl) +2. Alternative 1, create an appsettings.Development.json file and optionally other env settings files, which you don't want source controlled. +Then run the sample project with `DOTNETCORE_ENVIRONMENT=Development dotnet run` +3. Alernative 2, use env variables instead of appsetting values when starting the sample project. Example: +`OdooConnection__Host=my.odoohost.com OdooConnection__Password=mypassword dotnet run` + +The above commands are for UNIX, if you are on windows, command-line env vars are set like `set ENV_VAR=value && dotnet run` diff --git a/src/OdooRpc.CoreCLR.Client.Samples/OdooRpc.CoreCLR.Client.Samples.csproj b/src/OdooRpc.CoreCLR.Client.Samples/OdooRpc.CoreCLR.Client.Samples.csproj index 63cc630..0eea203 100644 --- a/src/OdooRpc.CoreCLR.Client.Samples/OdooRpc.CoreCLR.Client.Samples.csproj +++ b/src/OdooRpc.CoreCLR.Client.Samples/OdooRpc.CoreCLR.Client.Samples.csproj @@ -1,22 +1,27 @@ - Simple Odoo JSON-RPC Client for .Net Core 1.0 + Simple Odoo JSON-RPC Client for .Net Core 3.1 vmlf01;trafaelsilva - netcoreapp2.0 + netcoreapp3.1 OdooRpc.CoreCLR.Client.Samples Exe OdooRpc.CoreCLR.Client.Samples odoo;openerp;dotnet code;json-rpc;dotnet https://github.com/vmlf01/OdooRpc.CoreCLR.Client - https://github.com/vmlf01/OdooRpc.CoreCLR.Client/blob/master/LICENSE + https://github.com/vmlf01/OdooRpc.CoreCLR.Client/blob/master/LICENSE git https://github.com/vmlf01/OdooRpc.CoreCLR.Client - 1.0.4 + + + + + + diff --git a/src/OdooRpc.CoreCLR.Client.Samples/Program.cs b/src/OdooRpc.CoreCLR.Client.Samples/Program.cs index eaed408..5981c11 100644 --- a/src/OdooRpc.CoreCLR.Client.Samples/Program.cs +++ b/src/OdooRpc.CoreCLR.Client.Samples/Program.cs @@ -1,196 +1,40 @@ using System; using System.IO; -using System.Linq; using System.Threading.Tasks; - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -using OdooRpc.CoreCLR.Client.Interfaces; +using Microsoft.Extensions.Configuration; using OdooRpc.CoreCLR.Client.Models; -using OdooRpc.CoreCLR.Client.Models.Parameters; namespace OdooRpc.CoreCLR.Client.Samples { public class Program { - public static void Main(string[] args) + public static async Task Main(string[] args) { Console.WriteLine("Starting..."); + var configuration = LoadConfiguration(); + var odooConnection = configuration.GetSection("OdooConnection").Get(); - var p = new Program(); - p.LoginToOdoo().Wait(); - //p.GetDepartments().Wait(); - //p.SearchDepartments().Wait(); - //p.GetDepartmentsFields().Wait(); - //p.GetAllDepartments().Wait(); - //p.CreateDeleteDepartment().Wait(); - p.GetMetadata().Wait(); - Console.WriteLine("Done! Press a key to exit..."); - Console.ReadKey(); - } - - private OdooConnectionInfo OdooConnection; - private IOdooRpcClient OdooRpcClient; - - public Program() - { - LoadSettings(); - } - - private void LoadSettings() - { - try - { - var settings = JsonConvert.DeserializeObject(File.ReadAllText("appsettings.json")); - this.OdooConnection = settings["OdooConnection"].ToObject(); - } - catch (Exception ex) - { - Console.WriteLine("Error reading app settings: {0}", ex.Message); - } - } - - public async Task LoginToOdoo() - { - try - { - this.OdooRpcClient = new OdooRpcClient(this.OdooConnection); - - var odooVersion = await this.OdooRpcClient.GetOdooVersion(); - - Console.WriteLine("Odoo Version: {0} - {1}", odooVersion.ServerVersion, odooVersion.ProtocolVersion); - - await this.OdooRpcClient.Authenticate(); - - if (this.OdooRpcClient.SessionInfo.IsLoggedIn) - { - Console.WriteLine("Login successful => User Id: {0}", this.OdooRpcClient.SessionInfo.UserId); - } - else - { - Console.WriteLine("Login failed"); - } - } - catch (Exception ex) - { - Console.WriteLine("Error connecting to Odoo: {0}", ex.Message); - } - } - - public async Task GetAllDepartments() - { - try - { - var fieldParams = new OdooFieldParameters(); - fieldParams.Add("name"); - fieldParams.Add("company_id"); - fieldParams.Add("color"); - - var departments = await this.OdooRpcClient.GetAll("hr.department", fieldParams, new OdooPaginationParameters().OrderByDescending("name")); - - Console.WriteLine(departments.FirstOrDefault()); - } - catch (Exception ex) - { - Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message); - } - } - - public async Task GetDepartments() - { - try - { - var reqParams = new OdooGetParameters("hr.department"); - reqParams.Ids.Add(6); - //reqParams.Ids.Add(7); + // var client = new SampleClient(odooConnection); + // await client.LoginToOdoo(); + // await client.GetMetadata(); - var fieldParams = new OdooFieldParameters(); - fieldParams.Add("name"); - fieldParams.Add("company_id"); - - var departments = await this.OdooRpcClient.Get(reqParams, fieldParams); - - Console.WriteLine(departments.FirstOrDefault()); - } - catch (Exception ex) - { - Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message); - } + // test your calls here + Console.WriteLine("Done!"); } - public async Task SearchDepartments() + private static IConfiguration LoadConfiguration() { - try - { - var reqParams = new OdooSearchParameters( - "hr.department", - new OdooDomainFilter().Filter("name", "like", "SIC") - ); + var environment = Environment.GetEnvironmentVariable("DOTNETCORE_ENVIRONMENT") ?? "Development"; + Console.WriteLine($"Loading config for environment: {environment}"); - var count = await this.OdooRpcClient.SearchCount(reqParams); - var departments = await this.OdooRpcClient.Search(reqParams, new OdooPaginationParameters(0, 1)); + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile($"appsettings.json") + .AddJsonFile($"appsettings.{environment}.json", true) + .AddEnvironmentVariables(); + IConfiguration configuration = builder.Build(); - Console.WriteLine(departments.FirstOrDefault()); - } - catch (Exception ex) - { - Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message); - } + return configuration; } - - public async Task GetDepartmentsFields() - { - try - { - var reqParams = new OdooGetModelFieldsParameters( - "hr.department" - ); - - var fields = await this.OdooRpcClient.GetModelFields(reqParams); - - fields.ToList().ForEach(f => Console.WriteLine(f)); - } - catch (Exception ex) - { - Console.WriteLine("Error getting partners from Odoo: {0}", ex.Message); - } - } - - public async Task CreateDeleteDepartment() - { - try - { - var id = await this.OdooRpcClient.Create("hr.department", new - { - name = "test" - }); - - Console.WriteLine(id); - - await this.OdooRpcClient.Delete("hr.department", id); - } - catch (Exception ex) - { - Console.WriteLine("Error getting partners from Odoo: {0}", ex.Message); - } - } - - public async Task GetMetadata() - { - try - { - var metaParams = new OdooMetadataParameters("res.groups", new System.Collections.Generic.List() { 4 }); - - var resp = await this.OdooRpcClient.GetMetadata(metaParams); - - Console.WriteLine(resp.FirstOrDefault().ExternalId); - } - catch (Exception ex) - { - Console.WriteLine("Error getting metadata from Odoo: {0}", ex.Message); - } - } - } } \ No newline at end of file diff --git a/src/OdooRpc.CoreCLR.Client.Samples/SampleClient.cs b/src/OdooRpc.CoreCLR.Client.Samples/SampleClient.cs new file mode 100644 index 0000000..98deab0 --- /dev/null +++ b/src/OdooRpc.CoreCLR.Client.Samples/SampleClient.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using OdooRpc.CoreCLR.Client; +using OdooRpc.CoreCLR.Client.Interfaces; +using OdooRpc.CoreCLR.Client.Models; +using OdooRpc.CoreCLR.Client.Models.Parameters; + +namespace OdooRpc.CoreCLR.Client.Samples +{ + public class SampleClient + { + public OdooConnectionInfo ConnectionInfo { get; private set; } + public IOdooRpcClient OdooRpcClient { get; private set; } + + public SampleClient(OdooConnectionInfo connectionInfo) + { + ConnectionInfo = connectionInfo; + } + + // needs to be called before any other method + public async Task LoginToOdoo() + { + try + { + this.OdooRpcClient = new OdooRpcClient(this.ConnectionInfo); + + var odooVersion = await this.OdooRpcClient.GetOdooVersion(); + + Console.WriteLine("Odoo Version: {0} - {1}", odooVersion.ServerVersion, odooVersion.ProtocolVersion); + + await this.OdooRpcClient.Authenticate(); + + if (this.OdooRpcClient.SessionInfo.IsLoggedIn) + { + Console.WriteLine("Login successful => User Id: {0}", this.OdooRpcClient.SessionInfo.UserId); + } + else + { + Console.WriteLine("Login failed"); + } + } + catch (Exception ex) + { + Console.WriteLine("Error connecting to Odoo: {0}", ex.Message); + } + } + + public async Task GetAllDepartments() + { + try + { + var fieldParams = new OdooFieldParameters(); + fieldParams.Add("name"); + fieldParams.Add("company_id"); + fieldParams.Add("color"); + + var departments = await this.OdooRpcClient.GetAll("hr.department", fieldParams, new OdooPaginationParameters().OrderByDescending("name")); + + Console.WriteLine(departments.FirstOrDefault()); + } + catch (Exception ex) + { + Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message); + } + } + + 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(reqParams, fieldParams); + + Console.WriteLine(departments.FirstOrDefault()); + } + catch (Exception ex) + { + Console.WriteLine("Error getting departments from Odoo: {0}", ex.Message); + } + } + + 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(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 GetDepartmentsFields() + { + try + { + var reqParams = new OdooGetModelFieldsParameters( + "hr.department" + ); + + var fields = await this.OdooRpcClient.GetModelFields(reqParams); + + fields.ToList().ForEach(f => Console.WriteLine(f)); + } + catch (Exception ex) + { + Console.WriteLine("Error getting partners from Odoo: {0}", ex.Message); + } + } + + public async Task CreateDeleteDepartment() + { + try + { + var id = await this.OdooRpcClient.Create("hr.department", new + { + name = "test" + }); + + Console.WriteLine(id); + + await this.OdooRpcClient.Delete("hr.department", id); + } + catch (Exception ex) + { + Console.WriteLine("Error getting partners from Odoo: {0}", ex.Message); + } + } + + public async Task GetMetadata() + { + try + { + var metaParams = new OdooMetadataParameters("res.groups", new System.Collections.Generic.List() { 4 }); + + var resp = await this.OdooRpcClient.GetMetadata(metaParams); + + Console.WriteLine(resp.FirstOrDefault().ExternalId); + } + catch (Exception ex) + { + Console.WriteLine("Error getting metadata from Odoo: {0}", ex.Message); + } + } + + } +} \ No newline at end of file diff --git a/src/OdooRpc.CoreCLR.Client.Samples/appsettings.json b/src/OdooRpc.CoreCLR.Client.Samples/appsettings.json index 57709c3..f01aa58 100644 --- a/src/OdooRpc.CoreCLR.Client.Samples/appsettings.json +++ b/src/OdooRpc.CoreCLR.Client.Samples/appsettings.json @@ -2,6 +2,7 @@ "OdooConnection": { "Host": "", "Port": 0, + "IsSSL": false, "Database": "", "Username": "", "Password": "" diff --git a/src/OdooRpc.CoreCLR.Client/Interfaces/IOdooRpcClient.cs b/src/OdooRpc.CoreCLR.Client/Interfaces/IOdooRpcClient.cs index 5b78dd0..c7bbf10 100644 --- a/src/OdooRpc.CoreCLR.Client/Interfaces/IOdooRpcClient.cs +++ b/src/OdooRpc.CoreCLR.Client/Interfaces/IOdooRpcClient.cs @@ -35,6 +35,7 @@ public interface IOdooRpcClient Task ExecWorkFlow(string model, string method, long id); Task Create(string model, T newRecord); + Task> CreateMulti(string model, T newRecord); Task CreateDynamic(string model, string method, T newRecord); Task Delete(string model, long id); diff --git a/src/OdooRpc.CoreCLR.Client/Internals/Commands/OdooCreateCommand.cs b/src/OdooRpc.CoreCLR.Client/Internals/Commands/OdooCreateCommand.cs index f0b1d1e..8356c00 100644 --- a/src/OdooRpc.CoreCLR.Client/Internals/Commands/OdooCreateCommand.cs +++ b/src/OdooRpc.CoreCLR.Client/Internals/Commands/OdooCreateCommand.cs @@ -2,6 +2,7 @@ using OdooRpc.CoreCLR.Client.Internals.Interfaces; using OdooRpc.CoreCLR.Client.Models; using JsonRpc.CoreCLR.Client.Interfaces; +using System.Collections.Generic; namespace OdooRpc.CoreCLR.Client.Internals.Commands { @@ -17,6 +18,11 @@ public Task Execute(OdooSessionInfo sessionInfo, string model, T newRec return InvokeRpc(sessionInfo, CreateCreateRequest(sessionInfo, model, newRecord)); } + public Task> ExecuteMulti(OdooSessionInfo sessionInfo, string model, T newRecord) + { + return InvokeRpc>(sessionInfo, CreateCreateRequest(sessionInfo, model, newRecord)); + } + private OdooRpcRequest CreateCreateRequest(OdooSessionInfo sessionInfo, string model, object newRecord) { return new OdooRpcRequest() diff --git a/src/OdooRpc.CoreCLR.Client/OdooRpc.CoreCLR.Client.csproj b/src/OdooRpc.CoreCLR.Client/OdooRpc.CoreCLR.Client.csproj index ceb127f..5b3d6eb 100644 --- a/src/OdooRpc.CoreCLR.Client/OdooRpc.CoreCLR.Client.csproj +++ b/src/OdooRpc.CoreCLR.Client/OdooRpc.CoreCLR.Client.csproj @@ -1,28 +1,27 @@ - Simple Odoo JSON-RPC Client for .Net Core 2.0. Fork from https://github.com/vmlf01/OdooRpc.CoreCLR.Client - LORDofDOOM;vmlf01;trafaelsilva - netstandard2.0 + Simple Odoo JSON-RPC Client, adapted to .Net Core 3.1. Fork from https://github.com/vmlf01/OdooRpc.CoreCLR.Client + Stann + netcoreapp3.1 OdooRpc.CoreCLR.Client - OdooRpc.CoreCLR.Client.V2 + OdooRpc.CoreCLR.Client.V3 odoo;openerp;dotnet code;json-rpc;dotnet - https://github.com/GathSystemsOdoo/OdooRpc.CoreCLR.Client - https://github.com/GathSystemsOdoo/OdooRpc.CoreCLR.Client/blob/master/LICENSE + https://github.com/stann1/OdooRpc.CoreCLR.Client + LICENSE git - https://github.com/GathSystemsOdoo/OdooRpc.CoreCLR.Client - 2.0.0 + https://github.com/stann1/OdooRpc.CoreCLR.Client + 2.2.0 true - LORDofDOOM;vmlf01;trafaelsilva + Hollso.com - - - - - + + + + diff --git a/src/OdooRpc.CoreCLR.Client/OdooRpcClient.cs b/src/OdooRpc.CoreCLR.Client/OdooRpcClient.cs index 65e25da..8758d47 100644 --- a/src/OdooRpc.CoreCLR.Client/OdooRpcClient.cs +++ b/src/OdooRpc.CoreCLR.Client/OdooRpcClient.cs @@ -144,6 +144,12 @@ public Task Create(string model, T newRecord) return createCommand.Execute(this.SessionInfo, model, newRecord); } + public Task> CreateMulti(string model, T newRecord) + { + var createCommand = new OdooCreateCommand(CreateRpcClient()); + return createCommand.ExecuteMulti(this.SessionInfo, model, newRecord); + } + public Task CreateDynamic(string model, string method, T id) { var createCommand = new OdooCreateDynamicCommand(CreateRpcClient()); diff --git a/tests/OdooRpc.CoreCLR.Client.Tests/OdooRpc.CoreCLR.Client.Tests.csproj b/tests/OdooRpc.CoreCLR.Client.Tests/OdooRpc.CoreCLR.Client.Tests.csproj index e27100c..0afb8ce 100644 --- a/tests/OdooRpc.CoreCLR.Client.Tests/OdooRpc.CoreCLR.Client.Tests.csproj +++ b/tests/OdooRpc.CoreCLR.Client.Tests/OdooRpc.CoreCLR.Client.Tests.csproj @@ -1,9 +1,9 @@ - Simple Odoo JSON-RPC Client for .Net Core 1.0 + Simple Odoo JSON-RPC Client for .Net Core 3.1 vmlf01;trafaelsilva - netcoreapp1.0 + netcoreapp3.1 OdooRpc.CoreCLR.Client.Tests OdooRpc.CoreCLR.Client.Tests true @@ -12,7 +12,6 @@ https://github.com/vmlf01/OdooRpc.CoreCLR.Client/blob/master/LICENSE git https://github.com/vmlf01/OdooRpc.CoreCLR.Client - 1.0.4 @@ -20,9 +19,9 @@ - - - + + +