All Projects → patricoos → PortaCapena.OdooJsonRpcClient

patricoos / PortaCapena.OdooJsonRpcClient

Licence: MIT license
Odoo Client Json Rpc

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to PortaCapena.OdooJsonRpcClient

HardwareInformation
.NET Standard Cross-Platform Hardware Information Gatherer
Stars: ✭ 37 (-5.13%)
Mutual labels:  nuget, dotnet-standard
Pluralize.NET
📘 Pluralize or singularize any English word.
Stars: ✭ 50 (+28.21%)
Mutual labels:  nuget, dotnet-standard
covidtrackerapiwrapper
CovidSharp is a crossplatform C# API wrapper for the Coronavirus tracking API (https://github.com/ExpDev07/coronavirus-tracker-api)
Stars: ✭ 11 (-71.79%)
Mutual labels:  nuget, dotnet-standard
cv4pve-api-dotnet
Proxmox VE Client API .Net C#
Stars: ✭ 25 (-35.9%)
Mutual labels:  nuget, dotnet-standard
Kcp
KCP C#版。线程安全,运行时无alloc,对gc无压力。
Stars: ✭ 294 (+653.85%)
Mutual labels:  nuget, dotnet-standard
Vanara
A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
Stars: ✭ 544 (+1294.87%)
Mutual labels:  nuget, dotnet-standard
Tusdotnet
.NET server implementation of the Tus protocol for resumable file uploads. Read more at https://tus.io
Stars: ✭ 298 (+664.1%)
Mutual labels:  nuget, dotnet-standard
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (+210.26%)
Mutual labels:  nuget, dotnet-standard
commission
Odoo Commission Management
Stars: ✭ 97 (+148.72%)
Mutual labels:  odoo
Fissoft.EntityFramework.Fts
Full Text Search for Microsoft SQL Server with Entity Framework
Stars: ✭ 55 (+41.03%)
Mutual labels:  nuget
toolbox
dein ToolBox - C# .Net Library with utilities like: command line, files, log, platform, shell, system, transform and validation [ Win+Mac+Linux ]
Stars: ✭ 46 (+17.95%)
Mutual labels:  dotnet-standard
radiator
Hive Ruby API Client
Stars: ✭ 49 (+25.64%)
Mutual labels:  rpc-client
BlazorTimeline
Responsive, vertical timeline component.
Stars: ✭ 56 (+43.59%)
Mutual labels:  nuget
Gatekeeper
Lightweight library in C# for implementing roles-based access control (RBAC). With Gatekeeper, you can define users, roles, resources, and permissions, and authorize requests.
Stars: ✭ 25 (-35.9%)
Mutual labels:  nuget
DNZ.SEOChecker
SEO Checker and Recommander Plugin (like wordpress Yoast) for ASP.NET Core.
Stars: ✭ 18 (-53.85%)
Mutual labels:  dotnet-standard
TypewriterCli
Typewriter NetCore version with command line interface and single file processing.
Stars: ✭ 20 (-48.72%)
Mutual labels:  dotnet-standard
WatsonCluster
A simple C# class using Watson TCP to enable a one-to-one high availability cluster.
Stars: ✭ 18 (-53.85%)
Mutual labels:  nuget
DomainResult
Tiny package for decoupling domain operation results from IActionResult and IResult types of ASP.NET Web API
Stars: ✭ 23 (-41.03%)
Mutual labels:  nuget
documentation
Odoo documentation sources
Stars: ✭ 457 (+1071.79%)
Mutual labels:  odoo
Merkurius
Portable Deep Learning Library for .NET
Stars: ✭ 58 (+48.72%)
Mutual labels:  dotnet-standard

PortaCapena.OdooJsonRpcClient

License: MIT NuGet package Nuget example workflow example workflow badge

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

Porta Capena - Odoo Partner

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(productId, model);

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);

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].