### Install OdooJsonRpcClient via NuGet Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Use the package manager console to install the library. ```bash Install-Package PortaCapena.OdooJsonRpcClient ``` -------------------------------- ### OdooRepository Basic Read Operations Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Demonstrates creating a repository and performing basic read operations like getting all records, the first or default, a single record by ID, and checking for existence or count. ```csharp var repository = new OdooRepository(config); var allProducts = await repository.Query().ToListAsync(); if (allProducts.Succeed) { foreach (var product in allProducts.Value) { Console.WriteLine($"ID: {product.Id}, Name: {product.Name}"); } } var firstProduct = await repository.Query().FirstOrDefaultAsync(); var singleProduct = await repository.Query().ById(5).SingleAsync(); var first = await repository.Query().ById(5).FirstAsync(); var anyResult = await repository.Query().AnyAsync(); Console.WriteLine($"Has products: {anyResult.Value}"); var countResult = await repository.Query().CountAsync(); Console.WriteLine($"Total products: {countResult.Value}"); ``` -------------------------------- ### Execute Complete CRUD Workflow Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt A comprehensive example demonstrating the full lifecycle of a record including creation, reading, updating, and deletion. ```csharp var config = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin" ); var odooClient = new OdooClient(config); // CREATE var createModel = OdooDictionaryModel.Create(() => new ResPartnerOdooModel() { Name = "Test Partner", CountryId = 20, City = "Test City", Zip = "12345", Street = "Test Street", CompanyType = CompanyTypeResPartnerOdooEnum.Individual }); var createResult = await odooClient.CreateAsync(createModel); if (!createResult.Succeed) { Console.WriteLine($"Create failed: {createResult.Error.Message}"); return; } var partnerId = createResult.Value; Console.WriteLine($"Created partner with ID: {partnerId}"); // READ var query = new OdooQuery(); query.Filters.EqualTo("id", partnerId); var readResult = await odooClient.GetAsync(query); if (readResult.Succeed && readResult.Value.Length > 0) { var partner = readResult.Value.First(); Console.WriteLine($"Read partner: {partner.Name}"); } // UPDATE createModel.Add(x => x.Name, "Updated Partner Name"); var updateResult = await odooClient.UpdateAsync(createModel, partnerId); if (updateResult.Succeed) { Console.WriteLine("Partner updated successfully"); } // Verify update var verifyResult = await odooClient.GetAsync(query); Console.WriteLine($"Updated name: {verifyResult.Value.First().Name}"); // DELETE var deleteResult = await odooClient.DeleteAsync(verifyResult.Value.First()); if (deleteResult.Succeed) { Console.WriteLine("Partner deleted successfully"); } ``` -------------------------------- ### Odoo JSON-RPC Request Example Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Example of the raw JSON structure used for Odoo search_read operations. ```json { "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" ] ] } } ``` -------------------------------- ### Define Odoo Model Class Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Example structure for a C# model class mapped to an Odoo table. ```C# [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 Select, Order, and Pagination Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Demonstrates selecting specific fields, ordering results in ascending or descending order, and implementing pagination using Skip and Take methods. ```csharp var repository = new OdooRepository(config); 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(); var page1 = await repository.Query() .OrderBy(x => x.Id) .Skip(0) .Take(20) .ToListAsync(); var page2 = await repository.Query() .OrderBy(x => x.Id) .Skip(20) .Take(20) .ToListAsync(); var sortedProducts = await repository.Query() .OrderBy(x => x.Name) .ThenOrderByDescending(x => x.WriteDate) .ToListAsync(); var simplifiedProducts = await repository.Query() .SelectSimplifiedModel() .ToListAsync(); ``` -------------------------------- ### Initialize Odoo Client and Check Version Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Configure the client with Odoo credentials and retrieve the server version. ```C# 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(); ``` -------------------------------- ### Define Create Models with IOdooCreateModel Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Implements IOdooCreateModel to explicitly define fields for creation, avoiding issues with default or null values. ```C# [OdooTableName("product.product")] public class OdooCreateProduct : IOdooCreateModel { [JsonProperty("name")] public string Name { get; set; } } ``` ```C# var model = new OdooCreateProduct() { Name = "Prod test Kg", }; var createResult = await repository.CreateAsync(model); ``` -------------------------------- ### Configure SSL and Authentication Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Set static properties on OdooClient to handle SSL certificate validation and Basic Authentication before initializing the client. ```csharp // Disable SSL certificate validation (for test environments) OdooClient.ValidateServerCertificate = false; // Enable Basic Authentication (htaccess) OdooClient.BasicAuthenticationUsernamePassword = "username:password"; // Create client after configuring static settings var odooClient = new OdooClient(config); var result = await odooClient.GetVersionAsync(); ``` -------------------------------- ### Configure Odoo connection settings Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Initialize OdooConfig with various parameters including timeouts, language, and timezone settings. ```csharp // Basic configuration var config = new OdooConfig( apiUrl: "https://odoo-api-url.com", // or "http://localhost:8069" dbName: "odoo-db-name", userName: "admin", password: "admin" ); // Configuration with timeout var configWithTimeout = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin", timeout: TimeSpan.FromMinutes(5) ); // Configuration with language var configWithLanguage = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin", language: "nl_BE" ); // Configuration with language and timezone var configWithTimezone = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin", language: "pl_PL", timezone: "Europe/Warsaw" ); ``` -------------------------------- ### OdooRepository Filtering with Where Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Shows how to filter records using various operators like equals, greater than, less than, like, and in. Includes querying by single or multiple IDs and using OdooFilter for OR conditions. ```csharp var repository = new OdooRepository(config); 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)) .ToListAsync(); var productById = await repository.Query() .ById(282) .FirstOrDefaultAsync(); var productsByIds = await repository.Query() .ByIds(1, 2, 3, 4, 5) .ToListAsync(); var filter = OdooFilter.Create() .Or() .EqualTo(x => x.Name, "My Company (San Francisco)") .EqualTo(x => x.Name, "PL Company"); var companyRepository = new OdooRepository(config); var companies = await companyRepository.Query() .Where(filter) .ToListAsync(); var stringFilter = OdooFilter.Create() .Or() .EqualTo("name", "Company A") .EqualTo("name", "Company B"); ``` -------------------------------- ### Flexible Model Creation with OdooDictionaryModel Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Create models dynamically without defining full C# classes, useful for partial updates or when working with varying field sets. Supports creation with expressions, dictionaries, and single fields. ```csharp // Create with expression var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { Name = "test name", Description = "test description", }); // Add fields conditionally if (condition) { model.Add(x => x.WriteDate, DateTime.Now); } // Create with table name using dictionary syntax 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(config); var createResult = await odooClient.CreateAsync(model2); // Create with single field var singleFieldModel = OdooDictionaryModel.Create( x => x.CombinationIndices, "value" ); // Create with enum value var enumModel = OdooDictionaryModel.Create( x => x.InvoicePolicy, InvoicingPolicyProductProductOdooEnum.DeliveredQuantities ); ``` -------------------------------- ### OdooRepository Deep Where - Querying Related Models Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Illustrates how to query records based on fields from related models using foreign key relationships, including single-level and two-level deep where clauses. ```csharp var repository = new OdooRepository(config); var products = await repository.Query() .Where( x => x.CompanyId, y => y.CountryCode, OdooOperator.EqualsTo, "BE") .FirstOrDefaultAsync(); var productsDeep = await repository.Query() .Where( x => x.PropertyAccountExpenseId, y => y.AccountSaleTaxId, z => z.CountryCode, OdooOperator.EqualsTo, "BE") .FirstOrDefaultAsync(); var productsWithCurrency = await repository.Query() .Where( x => x.CurrencyId, z => z.Name, OdooOperator.EqualsTo, "EUR") .ToListAsync(); ``` -------------------------------- ### Retrieve Odoo server version Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Use GetVersionAsync to verify connectivity and retrieve server version details. ```csharp var config = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin" ); var odooClient = new OdooClient(config); var versionResult = await odooClient.GetVersionAsync(); if (versionResult.Succeed) { Console.WriteLine($"Server Version: {versionResult.Value.ServerVersion}"); Console.WriteLine($"Server Serie: {versionResult.Value.ServerSerie}"); } else { Console.WriteLine($"Error: {versionResult.Error.Message}"); } ``` -------------------------------- ### Create Records via Repository Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Create a new record using OdooDictionaryModel. ```C# var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { Name = "test product name" }); var result = await repository.CreateAsync(model); ``` -------------------------------- ### Create Records with OdooRepository.CreateAsync Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Create new records in Odoo using strongly-typed models or dictionary models. Supports single record creation, conditional field additions, and batch creation. ```csharp var repository = new OdooRepository(config); // Create using OdooDictionaryModel with expression var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { Name = "test product name", UomId = 3, UomPoId = 3, CompanyId = 1 }); var result = await repository.CreateAsync(model); if (result.Succeed) { Console.WriteLine($"Created product with ID: {result.Value}"); } else { Console.WriteLine($"Error: {result.Error.Message}"); } // Add additional fields conditionally if (someCondition) { model.Add(x => x.Description, "Product description"); } // Create using IOdooCreateModel interface [OdooTableName("product.product")] public class OdooCreateProduct : IOdooCreateModel { [JsonProperty("name")] public string Name { get; set; } [JsonProperty("uom_id")] public long UomId { get; set; } [JsonProperty("uom_po_id")] public long UomPoId { get; set; } } var createModel = new OdooCreateProduct() { Name = "New Product", UomId = 3, UomPoId = 3 }; var createResult = await repository.CreateAsync(createModel); // Batch create multiple records var models = new List { new OdooCreateProduct { Name = "Product 1", UomId = 3, UomPoId = 3 }, new OdooCreateProduct { Name = "Product 2", UomId = 3, UomPoId = 3 } }; var batchResult = await repository.CreateAsync(models); // batchResult.Value contains array of created IDs ``` -------------------------------- ### OdooRepository.ActionAsync - Execute Odoo Actions Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Executes custom Odoo actions on models, such as confirming orders or triggering specific workflows. This can be done via the repository or directly using the OdooClient. ```APIDOC ## POST /api/models/{model_name}/actions/{action_name} ### Description Executes a custom Odoo action on a specified model. ### Method POST ### Endpoint /api/models/{model_name}/actions/{action_name} ### Parameters #### Path Parameters - **model_name** (string) - Required - The name of the Odoo model (e.g., 'sale.order'). - **action_name** (string) - Required - The name of the action to execute (e.g., 'action_confirm'). #### Query Parameters - **param** (any) - Required - The parameter for the action, typically a record ID or a list of IDs. ### Response #### Success Response (200) - **Succeed** (boolean) - Indicates if the action was executed successfully. - **Value** (object) - The result of the action. #### Response Example ```json { "Succeed": true, "Value": { ... action result ... } } ``` ``` -------------------------------- ### Configure OdooContext Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Sets request context parameters like language or time zone for Odoo operations. ```C# var context = new OdooContext("pl_PL"); context.Language = "nl_BE"; var id = await odooRepository.CreateAsync(model, context); ``` -------------------------------- ### Read Data with OdooRepository Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Retrieve records from Odoo using the repository pattern. ```C# var repository = new OdooRepository(config); var products = await repository.Query().ToListAsync(); ``` -------------------------------- ### Authenticate with Odoo server Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Authenticate using LoginAsync to retrieve a user UID, though this is typically handled automatically by the client. ```csharp var config = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin" ); var odooClient = new OdooClient(config); var loginResult = await odooClient.LoginAsync(); if (loginResult.Succeed) { Console.WriteLine($"Logged in successfully. User UID: {loginResult.Value}"); } else { Console.WriteLine($"Login failed: {loginResult.Error.Message}"); } ``` -------------------------------- ### Use OdooDictionaryModel for Dynamic Creation Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Provides an alternative to model classes for handling dynamic field sets or specific null/default value requirements. ```C# 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); ``` ```C# 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 - Language and Timezone Settings Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Manages request context, allowing you to set language, timezone, company information, and custom key-value pairs for localized and specific Odoo operations. ```APIDOC ## Context Management ### Description Set language, timezone, and other context values for requests to receive localized data. Context can be applied globally via configuration or per-request. ### Usage #### Applying Context to a Repository ```csharp var context = new OdooContext("nl_BE"); context.Timezone = "Europe/Warsaw"; var repository = new OdooRepository(config); var product = await repository.Query().ById(282).WithContext(context).FirstOrDefaultAsync(); ``` #### Applying Custom Context Keys ```csharp var productWithCustomContext = await repository.Query() .ById(282) .WithContext("custom_key", "custom_value") .WithContext("another_key", 123) .FirstOrDefaultAsync(); ``` #### Setting Context in Configuration ```csharp var configWithContext = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin", context: new OdooContext("nl_BE") { Timezone = "Europe/Brussels" } ); ``` ### Context Properties - **Language** (string) - The language code for localization (e.g., 'en_US', 'nl_BE'). - **Timezone** (string) - The timezone for date and time formatting (e.g., 'Europe/Warsaw'). - **ForceCompany** (integer) - The ID of the company to force for the request. - **AllowedCompanyId** (integer) - The ID of the company allowed for the request. - **[CustomKey]** (any) - Allows adding arbitrary key-value pairs to the context. ``` -------------------------------- ### Retrieve and Map Odoo Models Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Fetch model specifications and generate C# class declarations using OdooModelMapper. ```C# var tableName = "product.product"; var modelResult = await odooClient.GetModelAsync(tableName); var model = OdooModelMapper.GetDotNetModel(tableName, modelResult.Value); ``` -------------------------------- ### Build Complex Filters with OdooFilter Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Use OdooFilter to construct advanced filters with AND, OR, NOT operators and various comparison methods. Supports typed expressions and string-based filters. ```csharp var filter = OdooFilter.Create() .Or() .EqualTo(x => x.Name, "Product A") .EqualTo(x => x.Name, "Product B"); var stringFilter = OdooFilter.Create() .EqualTo("name", "Test Product") .GreaterThan("price", 100) .LessThanOrEqual("qty_available", 50); var likeFilter = OdooFilter.Create() .ILike(x => x.Name, "%widget%") // Case-insensitive .Like(x => x.Description, "%sale%"); // Case-sensitive var inFilter = OdooFilter.Create() .In(x => x.Id, new long[] { 1, 2, 3, 4, 5 }); var notInFilter = OdooFilter.Create() .NotIn(x => x.CategoryId, new long[] { 10, 20 }); var nullFilter = OdooFilter.Create() .NotBeNull(x => x.Description) .BeNull(x => x.BarCode); var complexFilter = OdooFilter.Create() .Or() .And() .EqualTo(x => x.Active, true) .GreaterThan(x => x.Price, 0) .EqualTo(x => x.Type, "product"); var repository = new OdooRepository(config); var results = await repository.Query() .Where(complexFilter) .ToListAsync(); ``` -------------------------------- ### Authenticate with Odoo Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Perform an explicit login request to the Odoo instance. ```C# var loginResult = await odooClient.LoginAsync(); ``` -------------------------------- ### Manage Odoo Context Settings Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Set language, timezone, and other context values for Odoo requests to receive localized data. Context can be applied per-operation or at the configuration level. ```csharp // Create context with language var context = new OdooContext("nl_BE"); // Set additional properties context.Language = "pl_PL"; context.Timezone = "Europe/Warsaw"; context.ForceCompany = 3; context.AllowedCompanyId = 1; // Use context in repository operations var repository = new OdooRepository(config); var id = await repository.CreateAsync(model, context); // Use context in query var product = await repository.Query() .ById(282) .WithContext(context) .FirstOrDefaultAsync(); // Add custom context key-value pairs in query var productWithCustomContext = await repository.Query() .ById(282) .WithContext("custom_key", "custom_value") .WithContext("another_key", 123) .FirstOrDefaultAsync(); ``` ```csharp // Set context at config level for all requests var configWithContext = new OdooConfig( apiUrl: "https://odoo-api-url.com", dbName: "odoo-db-name", userName: "admin", password: "admin", context: new OdooContext("nl_BE") { Timezone = "Europe/Brussels" } ); // Or modify context after config creation config.Context.Language = "nl_BE"; ``` -------------------------------- ### Update Records via Repository Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Update specific fields of an existing record. ```C# var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { Name = "test product name updated" }); var result = await repository.UpdateAsync(model, productId); ``` -------------------------------- ### Perform Model Actions Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Executes a specific action on an Odoo model, such as confirming a sale order. ```C# var repository = new OdooRepository(config); var confirmResult = await repository.ActionAsync("action_confirm", orderId); ``` -------------------------------- ### Perform Low-Level Odoo API Operations Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Use OdooClient for direct control over API calls, including typed and untyped data retrieval, record manipulation, and batch deletions. ```csharp var odooClient = new OdooClient(config); // Get all products as typed array var products = await odooClient.GetAsync(); // Get products with query var query = OdooQuery.Create() .Where(x => x.Id, OdooOperator.EqualsTo, 1) .Take(10); var filteredProducts = await odooClient.GetAsync(query); // Get products as dictionary (untyped) var dictProducts = await odooClient.GetAsync("product.product"); // Get count var count = await odooClient.GetCountAsync(query); // Create record var model = OdooDictionaryModel.Create(() => new ResPartnerOdooModel() { Name = "New Partner", CountryId = 20, City = "Brussels", CompanyType = CompanyTypeResPartnerOdooEnum.Company }); var createResult = await odooClient.CreateAsync(model); // Update record var updateModel = OdooDictionaryModel.Create(() => new ResPartnerOdooModel() { Name = "Updated Name" }); var updateResult = await odooClient.UpdateAsync(updateModel, createResult.Value); // Delete record var deleteResult = await odooClient.DeleteAsync("res.partner", createResult.Value); // Delete range var deleteRangeResult = await odooClient.DeleteRangeAsync("product.product", new long[] { 1, 2, 3 }); ``` -------------------------------- ### Query Odoo Data with OdooQueryBuilder Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Build complex queries using filtering, selection, and ordering. ```C# 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(); ``` -------------------------------- ### Generate C# model from Odoo table Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Retrieve table schema and generate corresponding C# class definitions using OdooModelMapper. ```csharp var odooClient = new OdooClient(config); var tableName = "product.product"; var modelResult = await odooClient.GetModelAsync(tableName); if (modelResult.Succeed) { // Generate C# class code from Odoo model definition var dotNetModelCode = OdooModelMapper.GetDotNetModel(tableName, modelResult.Value); Console.WriteLine(dotNetModelCode); } // Output example: // [OdooTableName("product.product")] // [JsonConverter(typeof(OdooModelConverter))] // public class ProductProductOdooModel : IOdooModel // { // [JsonProperty("id")] // public long Id { get; set; } // // [JsonProperty("display_name")] // public string DisplayName { get; set; } // // [JsonProperty("price")] // public double? Price { get; set; } // ... // } ``` -------------------------------- ### Apply Advanced Odoo Filters Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Constructs complex queries using OdooFilter with logical operators. ```C# var filter = OdooFilter.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(); ``` -------------------------------- ### Execute Deep Where Queries Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Performs relational filtering across multiple Odoo models. ```C# var repository = new OdooRepository(config); var products = await repository.Query() .Where( x => x.CompanyId, y => y.CountryCode, OdooOperator.EqualsTo, "BE") .FirstOrDefaultAsync(); ``` ```C# var products = await repository.Query() .Where( x => x.PropertyAccountExpenseId, y => y.AccountSaleTaxId, z => z.CountryCode, OdooOperator.EqualsTo, "BE") .FirstOrDefaultAsync(); ``` -------------------------------- ### Execute Odoo Actions Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Execute custom Odoo actions or server-side methods on models. This can be used for operations like confirming orders or triggering workflows. ```csharp // Confirm a sale order (convert quote to order) var saleOrderRepository = new OdooRepository(config); var orderId = 135; var confirmResult = await saleOrderRepository.ActionAsync("action_confirm", orderId); if (confirmResult.Succeed) { Console.WriteLine("Sale order confirmed successfully"); } // Cancel an order var cancelResult = await saleOrderRepository.ActionAsync("action_cancel", orderId); ``` ```csharp // Using OdooClient directly for actions var odooClient = new OdooClient(config); var actionResult = await odooClient.ActionAsync( tableName: "sale.order", action: "action_confirm", param: orderId ); ``` -------------------------------- ### OdooRepository.UpdateAsync - Update Records Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Updates existing records by ID, allowing for partial updates by specifying only the fields to be modified. Supports updating single or multiple records. ```APIDOC ## POST /api/records/{id} ### Description Updates existing records by ID, updating only the specified fields. ### Method POST ### Endpoint /api/records/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the record to update. #### Request Body - **model** (OdooDictionaryModel) - Required - An object containing the fields to update. ### Request Example ```json { "Name": "updated product name", "Active": false } ``` ### Response #### Success Response (200) - **Succeed** (boolean) - Indicates if the update operation was successful. - **Value** (object) - Contains the updated record data or confirmation. #### Response Example ```json { "Succeed": true, "Value": { ... updated record data ... } } ``` ``` -------------------------------- ### OdooRepository.DeleteAsync - Delete Records Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Deletes records from Odoo either by their unique ID or by providing the model instance. Supports deleting single or multiple records. ```APIDOC ## DELETE /api/records/{id} ### Description Deletes records by ID or by model instance. ### Method DELETE ### Endpoint /api/records/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the record to delete. #### Request Body - **model** (object) - Optional - The model instance of the record to delete. ### Response #### Success Response (200) - **Succeed** (boolean) - Indicates if the delete operation was successful. #### Response Example ```json { "Succeed": true } ``` ``` -------------------------------- ### Delete Records via Repository Source: https://github.com/intechnity-com/odoojsonrpcclient/blob/master/README.md Remove a record from Odoo by its ID. ```C# var deleteProductResult = await repository.DeleteAsync(productId); ``` -------------------------------- ### Update Odoo Records Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Update existing records by ID, specifying fields to modify. Supports single record updates, multiple records with the same values, and setting fields to null. ```csharp var repository = new OdooRepository(config); // Update single record var model = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { Name = "updated product name" }); var productId = 123; var result = await repository.UpdateAsync(model, productId); if (result.Succeed) { Console.WriteLine("Product updated successfully"); } ``` ```csharp // Update multiple records with same values var updateModel = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { Active = false }); var ids = new long[] { 1, 2, 3, 4, 5 }; var rangeResult = await repository.UpdateRangeAsync(updateModel, ids); ``` ```csharp // Set field to null var nullModel = OdooDictionaryModel.Create(() => new ProductProductOdooModel() { CompanyId = null }); await repository.UpdateAsync(nullModel, productId); ``` -------------------------------- ### Delete Odoo Records Source: https://context7.com/intechnity-com/odoojsonrpcclient/llms.txt Delete records from Odoo either by their unique ID, by a model instance, or by a collection of records. ```csharp var repository = new OdooRepository(config); // Delete by ID var deleteResult = await repository.DeleteAsync(productId); if (deleteResult.Succeed) { Console.WriteLine("Product deleted successfully"); } ``` ```csharp // Delete by model instance var product = (await repository.Query().ById(productId).FirstOrDefaultAsync()).Value; var deleteByModelResult = await repository.DeleteAsync(product); ``` ```csharp // Delete multiple records var products = (await repository.Query().ByIds(1, 2, 3).ToListAsync()).Value; var deleteRangeResult = await repository.DeleteRangeAsync(products); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.