Odoo Data Structure and Operations Guide

Author

Reads 147

A Group of People Sitting at the Table at a Business Meeting
Credit: pexels.com, A Group of People Sitting at the Table at a Business Meeting

Odoo's data structure is built on a PostgreSQL database, which is a powerful and flexible relational database management system.

Odoo's data structure is designed to be highly scalable and adaptable to meet the needs of growing businesses.

The core data structure in Odoo is based on the concept of models, which are essentially classes that represent a specific type of data, such as customers, products, or orders.

Each model in Odoo has a set of attributes, known as fields, which define the structure of the data and provide a way to interact with it.

One of the key features of Odoo's data structure is its use of inheritance, which allows for the creation of new models by inheriting from existing ones, reducing duplication and improving maintainability.

Odoo's data structure also supports the concept of many-to-many relationships, which enable the creation of complex relationships between different types of data.

In Odoo, data operations are performed using a combination of SQL queries and Python code, which provides a high degree of flexibility and customization.

Odoo's data structure and operations are highly customizable, allowing developers to tailor the system to meet the specific needs of their business.

A unique perspective: Erp System Odoo

Data Structure

Credit: youtube.com, Introducing the Odoo Data Model: Revolutionize Odoo Development

When working with Odoo data, it's essential to understand its structure. The main way to define data in Odoo is via XML data files.

These files have a broad structure that consists of any number of operation elements within the root element odoo. Operations can only refer to the result of operations defined previously.

Data files are executed sequentially, which means that each operation builds upon the previous one.

To give you a better idea, here's a simple breakdown of the structure:

  • Root element: odoo
  • Operation elements: any number within the root element

This structure ensures that data is properly organized and referenced, making it easier to manage and maintain.

Data Operations

Data operations in Odoo are designed to make data management efficient and scalable. Odoo's data operations allow for real-time data synchronization across different modules and systems. This means that data is always up-to-date and consistent, reducing errors and inconsistencies.

Odoo's data operations also provide advanced data analysis and reporting capabilities. With features like data visualization and filtering, users can quickly gain insights into their business operations and make data-driven decisions.

Odoo's data operations are built on a robust architecture that ensures data integrity and security. This means that data is protected from unauthorized access and modifications, ensuring that it remains accurate and reliable.

Shortcuts

Credit: youtube.com, SHORTCUT KEY DATA OPERATION

Data operations can be streamlined with the use of shortcuts. Some important structural models in Odoo are complex and involved, which is why data files provide a shorter alternative to defining them using record tags.

Data files can simplify the process of defining complex models. This is particularly useful for developers who need to create and manage large amounts of data.

Consider reading: Function Models

Core Operations

Core Operations are essential for managing data effectively.

Extracting field children as a single document is a key part of this process. This allows for a streamlined workflow and easier data management.

External IDs play a crucial role in Core Operations. The form %(external_id)s can be used to specify an external ID, which can be evaluated during the process.

%% can be used to output actual % signs, making it easier to work with data in various formats.

By following these steps, you can efficiently manage your data and ensure that it is accurate and up-to-date.

As SQL

Credit: youtube.com, Learn Basic SQL in 15 Minutes | Business Intelligence For Beginners | SQL Tutorial For Beginners 1/3

Importing data directly as SQL can be a viable option in certain situations. This approach can significantly speed up the import time for huge files, making it a good choice when working with massive datasets.

However, it's worth noting that using raw SQL can bypass important security features, such as ACLs, increasing the risk of injections.

There are some cases where importing as SQL makes sense, like when initializing the database or for complex imports like translations.

Here are some scenarios where importing as SQL might be necessary:

  • Initializing the database
  • Complex imports like translations
  • Huge files

Export

Exporting data from Odoo is a straightforward process that can be done from any field in any record. To start, activate the list view icon and select the records that need to be exported.

You can choose to export in two formats: .csv and .xls. .csv files separate items with commas, while .xls files hold information about all the worksheets in a file, including content and formatting.

Credit: youtube.com, Importing and Exporting Data | Getting Started

The Export Data pop-up window offers several options for exporting data. You can select the fields to export using the > (right arrow) icon to display more sub-field options, or use the Search bar to find specific fields.

To add fields to the Fields to export list, use the + (plus sign) icon button. You can also move fields up and down to change the order in which they are displayed in the exported file using the ↕️ (up-down arrow) icon.

Some fields, like the External ID field, may not appear in the Fields to export list unless they are manually added. However, the External ID field is still included in the export if the I want to update data (import-compatible export) checkbox is ticked.

To save export presets for recurring reports, select all the needed fields and click on the template drop-down menu. You can then create a new template and give it a unique name.

It's also helpful to know the field's external identifier, as this can help you only export the data that needs to be modified and re-imported.

Here are the main options for exporting data:

  • I want to update data (import-compatible export): This option limits the Fields to export list to only include fields that are able to be imported.
  • Export format: You can choose to export in .csv or .xls format.
  • Fields to export: Select the fields to export using the > (right arrow) icon or the Search bar.
  • Field order: Use the ↕️ (up-down arrow) icon to move fields up and down.
  • Save export presets: Create a new template and give it a unique name.

Data Management

Credit: youtube.com, Why Data Management is Critical for the Success of an Odoo Project

Data Management is a crucial aspect of Odoo data, allowing you to efficiently organize and clean your data. To access all available features, you'll need to install the Data Cleaning application, which consists of several modules, including Data Recycle, Data Cleaning, and Data Cleaning (merge).

These modules can be installed on different editions of Odoo, with Data Recycle available on the Community edition and Data Cleaning and Data Cleaning (merge) available only on the Enterprise edition. You can install the required modules by following the instructions in the Data Cleaning application.

Here's a summary of the modules you'll need to install:

By installing these modules and configuring them correctly, you'll be able to efficiently manage your Odoo data and keep it clean and organized.

Delete

Deleting data is a crucial aspect of data management, and it's essential to understand how to do it effectively.

The delete command is used to remove a specified record from a model.

Credit: youtube.com, BRUSHR - Data Management Update/Transform/Delete (3 of 3)

To delete a record, you'll need to specify the external ID of the record you want to remove.

This is a simple yet important step in maintaining a clean and organized dataset.

The external ID is a unique identifier assigned to each record, allowing you to pinpoint the exact record you want to delete.

By following these steps, you can ensure that your data stays up-to-date and accurate.

Recycle Record Rules

Recycle Record Rules are a powerful tool in the Data Cleaning application, allowing you to set conditions for how records are recycled.

To get started, navigate to Data Cleaning app ‣ Configuration ‣ Recycle Records. By default, no recycle record rules exist, so click the New button to create a new rule.

A recycle rule can target any model in the database, and you can choose to filter the records eligible for this rule. The number of eligible records is shown in the # record(s) link.

Credit: youtube.com, Webinar: When Data Becomes A Record Tackling Master Data Retention Question

To configure the rule, select a Time Field from the model to base the time (Delta) on. Then, type the length of time, which must be a whole number (e.g. 1), and select the unit of time (Days, Weeks, Months, or Years).

You can choose to either Archive or Delete records, and if Delete is selected, you can choose whether or not to Include Archived records in the rule. A recycle rule can be configured to delete archived leads and opportunities that were last updated a year ago, and with a specific lost reason.

Here's an example of a configuration:

This configuration will automatically delete archived leads and opportunities that were last updated a year ago, and with a specific lost reason, without notifying users.

Merge Duplicate Records

Merging duplicate records in Odoo is a straightforward process that can be done manually or automatically. To manually merge records, first choose a master record within the grouping of similar records. The master record acts as the base, at which any additional information from similar records are merged into.

Credit: youtube.com, How To Merge Duplicate Records For Clean Customer Data - Part 5️⃣

You can also choose not to set a master record, leaving Odoo to choose a record at random to merge into. Next, click the Merge button at the top of the similar records grouping. Then, click Ok to confirm the merge.

Once a record is merged, a message is logged in the chatter of the master record, describing the merge. Certain records, like Project tasks, are logged in the chatter with a link to the old record as a convenient reference of the merge.

To discard a grouping of similar records, click the DISCARD button. Upon doing so, the grouping is hidden from the list and archived. You can view discarded groupings by selecting the Discarded filter from the search bar.

Here's a step-by-step summary of the merge process:

Data Import

Data Import is a breeze in Odoo, thanks to its user-friendly interface. You can import data on any business object using either Excel (.xlsx) or CSV (.csv) formats.

Credit: youtube.com, Data Import Made Easy

To get started, simply click the (gear) icon on the view of the object you want to import data into, and select Import records. Then, click Import Template for Customers to download a template and populate it with your company's data.

You can upload the downloaded template or your own file by following these steps:

  1. Click Upload Data File and select the desired file.
  2. Adjust the Formatting options as needed (for CSV files only).
  3. Ensure all data in the File Column is correctly mapped to the appropriate Odoo Field and free of errors.
  4. (Optional) Click Load Data File to reload the same file or upload a different one.
  5. Click Test to verify that the data is valid.
  6. Click Import.

Using the External ID (ID) can help you import relations between records. This unique identifier is especially helpful when updating imports or importing relation fields.

Get Started

To get started with data import in Odoo, you can import data on any business object using Excel (.xlsx) or CSV (.csv) formats. This includes contacts, products, bank statements, journal entries, and orders.

You can import data into Odoo by clicking the gear icon on the view of the object you want to import data into and selecting Import records. This will allow you to import data from a template or your own file.

Credit: youtube.com, Getting started with importing data in Python

To download a template, click Import Template for Customers at the center of the page. This template is preconfigured with data mapping, so you can import it with one click.

Here's a step-by-step guide to importing data into Odoo:

  1. Click Upload Data File and select the desired file.
  2. Adjust the Formatting options as needed (for CSV files only).
  3. Ensure all data in the File Column is correctly mapped to the appropriate Odoo Field and free of errors.
  4. (Optional) Click Load Data File to reload the same file or upload a different one.
  5. Click Test to verify that the data is valid.
  6. Click Import.

Remember to adjust the Formatting options if you're importing a CSV file, as this will ensure your data is imported correctly.

From Another Application

Importing data from another application can be a breeze, especially if you use a unique identifier like the External ID. This ID is a game-changer when it comes to importing data without creating duplicates.

Using the External ID is not mandatory, but it's highly recommended as it helps in many cases, such as updating imports and importing relation fields.

You can recreate relationships between different records by mapping the original unique identifier to the External ID column in Odoo. This is especially useful when importing records that link to each other.

Conflicts can occur if two records have the same External ID, so be sure to double-check for duplicates.

If this caught your attention, see: When Graphing Your Data It Is Important That You?

Data Relationships

Credit: youtube.com, Understand Relational Databases to Understand ODOO

When importing data into Odoo, it's essential to consider the relationships between objects. This can be achieved by using either the name of the related record or its ID, depending on the circumstances.

To import relation fields, you need to import the records of the related object first, from their own list menu. This ensures that the relationships are established correctly.

In cases where two records have the same name, you can use the ID to distinguish between them. This is done by adding /ID at the end of the column title, as shown in the example: ProductAttributes/Attribute/ID.

When importing many2many relationship fields, it's crucial to separate the tags with commas without any spacing. For instance, if a customer needs to be linked to both tags: Manufacturer and Retailer, then 'Manufacturer,Retailer' needs to be encoded in the same column of the CSV file.

Here's a list of tips to keep in mind when importing many2many relationship fields:

  • Separate the tags with commas without any spacing.
  • Use the exact format as shown in the example: 'Manufacturer,Retailer'.

To add related data in a One2many or a Many2many field, you can use the Command methods.

Data Fields

Credit: youtube.com, Relational fields | Odoo Studio

Data Fields are a crucial part of Odoo's data structure, allowing you to define values for records when creating or updating them. Each record can be composed of field tags, with a mandatory name attribute that defines the field to set.

You can use various methods to define the value itself, including setting an implicit False if no value is provided, which can be useful for clearing a field or avoiding default values. For relational fields, you can provide a domain to search the field's model and set the result as the field's value.

If you need to add related data in a One2many or Many2many field, you can use the Command methods, which allow you to create new records directly inside the field. This can be a powerful tool for managing complex data relationships.

Odoo also has a heuristic approach to determining the type of field for each column, based on the first ten lines of the file. However, this can sometimes fail or map the column to an unexpected field, so it's worth checking the Show fields of relation fields option to get a complete list of available fields.

Field

Manager Considering Project Strategy by the Task Board
Credit: pexels.com, Manager Considering Project Strategy by the Task Board

When creating a record, each field has a mandatory name attribute, which is the name of the field to set.

You can define a field's value using various methods, including setting an explicit value, using an implicit False to clear a field, or evaluating a domain to search for a value.

If a field has no value provided, an implicit False will be set on the field, which can be used to clear a field or avoid using a default value.

For relational fields, the value should be a domain on the field's model, which will be evaluated to search for a value.

If a ref attribute is provided, its value must be a valid external id, which will be looked up and set as the field's value, mostly for Many2one and Reference fields.

You can also use type attributes to interpret and convert the field's content, such as ensuring it's a valid file path, setting it directly, base64-encoding it, converting it to an integer or float, or resolving a tuple or list.

Broaden your view: Filter Setting

Credit: youtube.com, WHONET - Creating new Data Fields & What is Supplemental Field List?

For more complex cases, you can use the eval attribute to evaluate a Python expression and set the result as the field's value.

In some cases, Odoo may not be able to determine the type of field for a column, so you may need to check the Show fields of relation fields option to get a complete list of fields available for each column.

Currency Numbers

Currency Numbers can be tricky, but Odoo has got you covered. It fully supports numbers with currency signs attached to them.

If you're working with numbers from different countries, you'll be happy to know that Odoo automatically detects which thousand/decimal separator is used. However, if a currency symbol unknown to Odoo is used, the import might crash.

Odoo recognizes numbers with a parenthesis to represent negative signs, and it's essential to place the currency symbol within the parenthesis for it to recognize the number as a negative currency value.

You can import numbers in various formats, including: 32.000,00, 32000,00, 32,000.00, -32000.00, (32000.00), $ 32.000,00, and (32000.00 €).

Here are some examples of supported numbers:

  • 32.000,00
  • 32000,00
  • 32,000.00
  • -32000.00
  • (32000.00)
  • $ 32.000,00
  • (32000.00 €)

It's worth noting that a () (parenthesis) around the number indicates that the number is a negative value.

Field Cleaning Rules

Credit: youtube.com, How to Create Field Cleaning Rules in Odoo 15 Data Cleaning Module | Odoo Functional Videos

Field cleaning rules are an essential part of maintaining clean and organized data fields. They run once every day by default as part of a scheduled action cron called "Data Cleaning: Clean Records".

You can configure field cleaning rules for each model in the database, and they can be run manually anytime. A default Contact rule exists to format and clean up the Contacts app records.

To create a new rule, navigate to the Data Cleaning app and select Configuration ‣ Field Cleaning. Then, select the New button to create a new rule. On the field cleaning rule form, choose a Model for this rule to target.

Next, configure at least one rule by clicking Add a line in the Rules section. A Create Rules popover window will appear with the following fields to configure: Select a Field To Clean from the model to assign to an action, and Choose one of the following Action options: Once a field and action are selected, click Save to close the Create Rules popover window.

Credit: youtube.com, How to Configure Field Cleaning Rules in Odoo 17 | Odoo 17 Data Cleaning Module | Odoo 17 Tutorials

The Cleaning Mode can be set to either Manual or Automatic. Manual mode requires each detected field to be manually cleaned and enables the Notify Users field. Automatic mode, on the other hand, automatically cleans fields without notifying users.

Here are the action options available for field cleaning rules:

  • Once a field and action are selected, click Save to close the Create Rules popover window.

Data Access

Accessing data in Odoo can be a bit tricky, but don't worry, I've got you covered. You should never access demo data outside of the demo data declaration, not even in tests. There are multiple ways to access the master/demo data, and one way is to use the env.ref method in python code.

This method returns the recordset linked to the xml_id you specify. It will call the ref method, and store the id of the record returned on the field related_id of the record of type tutorial.example with id id1.

If you need to get data from an Odoo database, you have a few options. You can use a direct database connection if you have access to the Odoo PostgreSQL database.

Alternatively, you can use the Odoo API, which is recommended if you don't have direct access to the database or need to perform operations like creating and updating records.

Broaden your view: Odoo Pos Kitchen Direct Prin

Data Conversion

Credit: youtube.com, Easy data import, export and migration with STML and Stimula

Data conversion is a crucial step in Odoo data management. It allows you to transform your data from one format to another, making it easier to work with and analyze.

Odoo offers a built-in data conversion tool that supports various file formats, including CSV, Excel, and JSON. This tool is user-friendly and can be easily accessed through the Odoo interface.

Data conversion is also essential for integrating Odoo with other applications and services. By converting your data into a compatible format, you can seamlessly connect with other systems and enhance your business operations.

The data conversion process in Odoo involves selecting the source and target formats, specifying the conversion rules, and executing the conversion. This process is typically done in a few steps, making it a straightforward task.

You can also use Odoo's data conversion tool to migrate data from other applications to Odoo. This is especially useful when transitioning to Odoo from another ERP system.

Data IDs

Credit: youtube.com, Odoo V14 - How To Update Data With External_ID

Data IDs are essential in Odoo, and understanding them can make a big difference in your data management.

In Odoo, a field that defines a relationship with another object, such as a country of a contact, can be imported using three different mechanisms.

Only one mechanism should be used per field, and Odoo proposes three different fields to import: Country, Country/Database ID, and Country/External ID.

Here are the details of each:

You can see these mechanisms in action with the example of referencing the country of a contact: Belgium, 21, and base.be.

The XML id contains the name of the record, along with the module in which it is defined, the model defining it, and the id of it.

Data Images

You can import image files along with your uploaded CSV or Excel file. This is useful for adding visual content to your data.

To get started, add the image file names to the relevant Image column in your data file. Make sure the image file names match the uploaded image files. If you're importing a large number of images, you can specify the maximum batch size in megabytes to prevent the system from becoming overloaded.

Credit: youtube.com, How to Import Images in Odoo 18 | Odoo 18 New Features

The Files to import section is enabled if your product template has an Image column with all fields populated. This is a requirement for importing images.

You can also set a delay after each batch to prevent the system from becoming overloaded. The default delay meets the RPC/API call limit defined in the Odoo Cloud - Acceptable Use Policy.

Here's a quick summary of the steps to import image files:

  1. Add image file names to the relevant Image column in your data file.
  2. Upload your data file or reload it by clicking Load Data File.
  3. Click Upload your files under the Files to import section.
  4. Select the relevant image files.
  5. Click Test to verify that all data is valid.
  6. Click Import.

Data Records

A record in Odoo is defined by the "record" function, which is used to create or update a database record. This function has several attributes that you need to consider.

To create a record, you need to specify the name of the model to create. For example, if you're creating a customer record, you would specify the "res.partner" model.

You should also provide an external identifier for the record, which is strongly recommended. This identifier will be used to refer to the record in subsequent definitions.

Credit: youtube.com, How to import Data in Odoo ERP? Mastering the Odoo v17 Import Record Feature

For record creation, the external identifier allows subsequent definitions to either modify or refer to this record. For record modification, the external identifier specifies the record to modify.

The "record" function also requires a context to use when creating the record. This context will determine how the record is created.

In update mode, you can choose whether the record should be created if it doesn’t exist. By default, this setting is True, meaning the record will be created if it doesn’t exist.

Here are the attributes of the "record" function in a concise list:

  • Name of the model to create (or update)
  • External identifier for the record
  • Context to use when creating the record
  • In update mode, whether the record should be created if it doesn’t exist

Data Templates

Data templates are a crucial part of importing data into Odoo. You can import templates from the import tool, which includes common data such as contacts, products, and bank statements.

To use a template, simply open it with any spreadsheet software like Microsoft Office, OpenOffice, or Google Drive. Once you've downloaded the template, you can start modifying it to fit your needs.

Credit: youtube.com, Odoo BI - Spreadsheet and Dashboard for efficient reporting

You can add, remove, and sort columns to best fit the data structure. It's strongly advised not to remove the External ID (ID) column, as this can cause issues with importing data.

To set a unique ID to every record, drag down the ID sequencing in the External ID (ID) column. This ensures that each record has a distinct identifier.

If you add a new column, Odoo may not be able to map it automatically. However, you can map it manually when you test the import. To do this, search the drop-down menu for the corresponding field and use its label in the import file.

A useful way to find the proper column names to import is to export a sample file using the fields that should be imported. This ensures that the column names are accurate and will work for future imports.

Kellie Hessel

Junior Writer

Kellie Hessel is a rising star in the world of journalism, with a passion for uncovering the stories that shape our world. With a keen eye for detail and a knack for storytelling, Kellie has established herself as a go-to writer for industry insights and expert analysis. Kellie's areas of expertise include the insurance industry, where she has developed a deep understanding of the complex issues and trends that impact businesses and individuals alike.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.