OdooJsonRpcClientTJ 1.0.0

dotnet add package OdooJsonRpcClientTJ --version 1.0.0
                    
NuGet\Install-Package OdooJsonRpcClientTJ -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OdooJsonRpcClientTJ" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OdooJsonRpcClientTJ" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="OdooJsonRpcClientTJ" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OdooJsonRpcClientTJ --version 1.0.0
                    
#r "nuget: OdooJsonRpcClientTJ, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OdooJsonRpcClientTJ@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OdooJsonRpcClientTJ&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=OdooJsonRpcClientTJ&version=1.0.0
                    
Install as a Cake Tool

OdooJsonRpcClient

License: MIT NuGet package Nuget example workflow example workflow badge

OdooJsonRpcClient is a C# library (.NET Standard) for communication with Odoo.

Installation

Use the package manager console, nuget package manager or check on NuGet.org

Install-Package PortaCapena.OdooJsonRpcClient

First steps

Start your work with check version of Odoo. To this request You need only a valid url address.

var config = new OdooConfig(
        apiUrl: "https://odoo-api-url.com", //  "http://localhost:8069"
        dbName: "odoo-db-name",
        userName: "admin",
        password: "admin"
        );

var odooClient = new OdooClient(config);
var versionResult = await odooClient.GetVersionAsync();

When U can connect to odoo, try use login method. (There is no need to use this method later. Logging is going on in the background e.g. OdooClient, OdooRepository)

var loginResult = await odooClient.LoginAsync();

If You have correct data to login, its time to get model that U intrested off.

var tableName = "product.product";
var modelResult = await odooClient.GetModelAsync(tableName);

var model = OdooModelMapper.GetDotNetModel(tableName, modelResult.Value);

Method GetModelAsync returns model with odoo specification. Method GetDotNetModel() from class OdooModelMapper returns string of class declaration that U can create and paste to Your project. Please don't use the models from the example project. Models are different depending on odoo version and added extensions.

[OdooTableName("product.product")]
[JsonConverter(typeof(OdooModelConverter))]
public class OdooProductProduct : IOdooModel
{
    [JsonProperty("id")]
    public long Id { get; set; }

    [JsonProperty("display_name")]
    public string DisplayName { get; set; }

    [JsonProperty("price")]
    public double? Price { get; set; }

    // product.template
    [JsonProperty("product_tmpl_id")]
    public int ProductTmplId { get; set; }
    
    [JsonProperty("activity_exception_decoration")]
    public ActivityExceptionDecorationOdooEnum? ActivityExceptionDecoration { get; set; }
    
    ...
}

[JsonConverter(typeof(StringEnumConverter))]
public enum ActivityExceptionDecorationOdooEnum
{
    [EnumMember(Value = "warning")]
    Alert = 1,

    [EnumMember(Value = "danger")]
    Error = 2,
}

OdooRepository

Read
var repository = new OdooRepository<ProductProductOdooModel>(config);
var products = await repository.Query().ToListAsync();

In Repository U can use OdooQueryBuilder to create queries.

  var products = await repository.Query()
                .Where(x => x.Name, OdooOperator.EqualsTo, "test product name")
                .Where(x => x.WriteDate, OdooOperator.GreaterThanOrEqualTo, new DateTime(2020, 12, 2))
                .Select(x => new
                {
                    x.Name,
                    x.Description,
                    x.WriteDate
                })
                .OrderByDescending(x => x.Id)
                .Take(10)
                .ToListAsync();
Create
var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel()
{
    Name = "test product name"
});

var result = await repository.CreateAsync(model);
Update

U can update only this fields that U are intrested in. For updating many records use UpdateRangeAsync.

var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel()
{
    Name = "test product name updated"
}); 
var result = await repository.UpdateAsync(model, productId);
Delete
var deleteProductResult = await repository.DeleteAsync(productId);

OdooClient

OdooRepository is a wrapper for OdooClient. This class give option for building more advanced requests or not implemented in this library.

IOdooCreateModel

If we create an object instance that we want to pass to odoo but do not fill all fields, they will be automatically assigned default values (Create and update methods). In this case is impossible to distinguish whether we want to set null value or not touch this property. The first solution for that is create models based on odoo model with only fields that we want to use. To that use IOdooCreateModel interface. To not create multiple models use OdooDictionaryModel.

[OdooTableName("product.product")]
public class OdooCreateProduct : IOdooCreateModel
{
    [JsonProperty("name")]
    public string Name { get; set; }
}
var model = new OdooCreateProduct()
{
     Name = "Prod test Kg",
};

var createResult = await repository.CreateAsync(model);

OdooDictionaryModel

This class is second solution for the problem of passing models with default or null values to odoo.

var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel()
{
    Name = "test name",
    Description = "test description",
});

if(condition)
    model.Add(x => x.WriteDate, new DateTime());

var createResult = await odooRepository.CreateAsync(model);

or

 var model2 = new OdooDictionaryModel("res.partner") {
                { "name", "test name" },
                { "country_id", 20 },
                { "city", "test city" },
                { "zip", "12345" },
                { "street", "test address" },
                { "company_type", "company" },
            };
var odooClient = new OdooClient(TestConfig);

var createResult = await odooClient.CreateAsync(model2);

OdooContext

Context is mainly used to send to odoo values such as language or time zone, but U can use it for more advanced requests. U can set it in OdooConfig for multiple usage or only once adding it to request as parameter (also in repository query).

var context = new OdooContext("pl_PL");
context.Language = "nl_BE";

var id = await odooRepository.CreateAsync(model, context);

Advanced queries

To make Your queries faster use Select method and get only fields that U are interested of. If U reduced the amount of field in your models use SelectSimplifiedModel().

OdooFilter

For more advanced queries U can use OdooFilter or OdooFilterOfT. To use or try:

var filter = OdooFilter<ResCompanyOdooModel>.Create()
                .Or()
                .EqualTo(x => x.Name, "My Company (San Francisco)")
                .EqualTo(x => x.Name, "PL Company");    

var filter = OdooFilter.Create()
                .Or()
                .EqualTo("name", "My Company (San Francisco)")
                .EqualTo("name", "PL Company");

var products = await repository.Query()
               .Where(filter)
               .ToListAsync();

Deep where

Get ProductProductOdooModel where CountryCode is "BE" in ResCompanyOdooModel (CompanyId)

var repository = new OdooRepository<ProductProductOdooModel>(config);
var products = await repository.Query()
               .Where<ResCompanyOdooModel>(
                  x => x.CompanyId, 
                     y => y.CountryCode, OdooOperator.EqualsTo, "BE")
               .FirstOrDefaultAsync();
var products = await repository.Query()
               .Where<ResCompanyOdooModel, AccountTaxOdooModel>(
                  x => x.PropertyAccountExpenseId, 
                     y => y.AccountSaleTaxId, 
                        z => z.CountryCode, OdooOperator.EqualsTo, "BE")
               .FirstOrDefaultAsync();

Odoo Request and Result models examples

Request
{
   "id":948165322,
   "jsonrpc":"2.0",
   "method":"call",
   "params":{
      "service":"object",
      "method":"execute",
      "args":[
         "odoo_db_name",
         2,
         "odoo_user_name",
         "product.product",
         "search_read",
         [
            [
               "name",
               "=",
               "Bioboxen 610l"
            ],
            [
               "write_date",
               ">=",
               "2020-12-02 00:00:00"
            ]
         ],
         [
            "name",
            "description",
            "write_date"
         ]
      ]
   }
}
Result
{
   "jsonrpc":"2.0",
   "id":948165322,
   "result":[
      {
         "id":324,
         "name":"Bioboxen 610l",
         "description":false,
         "write_date":"2020-12-02 08:47:08"
      }
   ]
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 144 2/25/2025