Introduction
If you have ever set a quantity on a sales order, tracked how many days a task has been open, or configured a priority score on a lead, you have used an Integer field in Odoo. It is one of the most common field types in the Odoo data model, and yet it is often underestimated.
Understanding how the Integer field works matters for business users who configure forms, for developers writing custom modules, and for consultants designing data models for their clients.
This guide covers what the Integer field stores, how it behaves in the Odoo framework and interface, how to create or customize it with Odoo Studio or Python, along with practical use cases and things to watch out for.
What is the Integer Field in Odoo
In the Odoo ORM, the Integer field is designed to store whole numbers. No decimal places, no fractions. It maps directly to an INTEGER column in PostgreSQL, which is a 4-byte signed integer supporting values from roughly -2 billion to +2 billion.
From the user perspective, an Integer field appears as a simple numeric input in forms and as a number column in list views. It is the right choice for anything that must be counted in whole units: quantities, scores, durations in days, sequence numbers, or any metric where half a unit does not make sense.
Here is a typical definition in a Python module:
from odoo import fields, models
class ProjectTask(models.Model):
_inherit = 'project.task'
estimated_hours = fields.Integer(
string='Estimated Hours',
default=0,
)
The string parameter controls the label shown in the interface. The default parameter sets the value automatically when a new record is created.
In Odoo Studio, this field type is listed simply as Integer. When created through Studio, it gets an x_studio_ prefix. When created via Python or the XML-RPC API, you choose the technical name yourself.
How the Field Works
When you define an Integer field in Odoo, the framework automatically creates the corresponding database column during module installation or upgrade. You do not need to write SQL migrations manually.
At the database level, the column is typed as INTEGER in PostgreSQL. The Odoo ORM takes care of type coercion, so if the user enters nothing, the field returns 0 rather than None or False. This is an important distinction compared to other field types like Float or Char, which can return False when empty.
Key Field Attributes
Here are the most important properties you can configure on an Integer field:
- string: The label shown to users in the interface.
- default: The value automatically assigned to new records. Defaults to
0if not specified. - required: Makes the field mandatory. Since the default is already
0, this is most useful when you want to block saving with a zero value. - readonly: Prevents users from editing the value directly in the interface.
- index: Creates a PostgreSQL index on the column, speeding up filters and searches on that field.
- compute: Links a Python method that calculates the field value dynamically from other fields.
- store: Combined with
compute, controls whether the computed value is saved in the database or recalculated on the fly. - copy: Controls whether the value is carried over when duplicating a record.
- groups: Restricts visibility of the field to specific user groups.
How It Appears in Views
In form views, an Integer field renders as a numeric input box. Odoo automatically adds thousand separators for readability when displaying larger numbers.
In list views, Integer fields appear as plain numbers, right-aligned by convention. In search views, they support equals, greater than, and less than filters.
You can pair an Integer field with specific widgets in views to change how it looks. The priority widget, for example, turns an Integer field into clickable stars. The progressbar widget can display an Integer value as a progress bar when combined with a maximum value.
Interaction with the Odoo ORM
From a developer perspective, reading and writing Integer fields is straightforward. The value is always a Python int. Empty Integer fields return 0, which means you should be careful when writing conditions that check for absence of a value. A zero and an empty field look the same unless you design around it.
Integer fields also work naturally in computed fields and in domain filters used by views, server actions, and automated actions throughout the Odoo framework.
Business Use Cases
The Integer field shows up across nearly every module in Odoo. Here are five practical scenarios where it plays a central role.
1. CRM: Lead Scoring
Sales teams often want to prioritize leads based on a score. You can add a custom Integer field called Lead Score on the CRM opportunity model. Sales representatives update the score manually, or an automated action calculates it based on criteria like company size, budget, or engagement level.
This makes it easy to sort your pipeline by score and focus on the most promising opportunities.
2. Sales: Minimum Order Quantities
In the Sales and Inventory modules, Integer fields control minimum order quantities on products or pricelists. Setting a minimum of 10 units on a product ensures that the system blocks orders below that threshold, saving back-and-forth with customers later.
3. Inventory: Reorder Rules
Reorder rules in Odoo rely entirely on Integer fields for minimum quantity and maximum quantity thresholds. When stock drops below the minimum, Odoo automatically triggers a replenishment order up to the defined maximum. Getting these values right is critical for avoiding both stockouts and overstock situations.
4. Project Management: Story Points and Effort Estimates
Teams using Odoo Project for agile workflows often add a custom Integer field for story points or estimated hours. This field appears on tasks in kanban or list view and helps the team track capacity and velocity across sprints.
5. Accounting: Payment Terms Days
Payment terms in Odoo Accounting use Integer fields to define the number of days allowed for payment. Net 30, Net 60, or custom terms are all configured through Integer values. These values feed directly into invoice due date calculations, which makes accuracy here important for cash flow management.
Creating or Customizing the Integer Field
There are two main ways to add an Integer field to an Odoo model: using Odoo Studio without writing code, or defining it directly in Python for more control.
Using Odoo Studio
Odoo Studio is the no-code and low-code tool built into Odoo for customizing fields and views. To add an Integer field through Studio:
- Open the form where you want to add the field.
- Activate Studio from the top-right menu.
- In the field list on the left, drag the Integer field type onto your form.
- Set the field label, choose whether it is required, and configure the default value.
- Save and exit Studio.
Studio creates the field with an x_studio_ prefix automatically and stores the definition in ir.model.fields. The field is immediately available in forms and list views.
Using Python (Technical Customization)
For developers building custom modules or performing Odoo development with more control, the Integer field is defined directly in a Python model class:
from odoo import fields, models
class CrmLead(models.Model):
_inherit = 'crm.lead'
x_lead_score = fields.Integer(
string='Lead Score',
default=0,
index=True,
help='Score from 0 to 100 used to prioritize opportunities',
)
After defining the field in code, run odoo-bin -u your_module to apply the changes to the database. The column is created automatically.
Using the XML-RPC API
You can also create an Integer field remotely using the Odoo XML-RPC API. This is useful for automated deployments or when working without direct server access:
field_id = models.execute_kw(
ODOO_DB, uid, ODOO_API_KEY,
'ir.model.fields', 'create',
[{
'name': 'x_lead_score',
'field_description': 'Lead Score',
'model_id': crm_lead_model_id,
'ttype': 'integer',
'state': 'manual',
}]
)
The ttype value for Integer fields is simply 'integer'. The state must be 'manual' to indicate a custom field rather than a module-defined one.
Adding a Computed Integer Field
Computed Integer fields are powerful for deriving values automatically. For example, counting the number of tasks linked to a project:
class Project(models.Model):
_inherit = 'project.project'
open_task_count = fields.Integer(
string='Open Tasks',
compute='_compute_open_task_count',
store=True,
)
def _compute_open_task_count(self):
for project in self:
project.open_task_count = self.env['project.task'].search_count([
('project_id', '=', project.id),
('stage_id.fold', '=', False),
])
Setting store=True saves the value in the database, making it available for filtering and sorting in list views without recalculating it every time.
Best Practices
Here are practical tips for getting the most out of Integer fields in your Odoo data model.
Use Integer for Counts and Whole-Unit Quantities
Choose Integer when the value must always be a whole number and decimals would not make sense. For anything involving money, measurements, or quantities that can be fractional, use the Float or Monetary field type instead.
Set a Sensible Default
Integer fields default to 0 in Odoo. In many cases that is fine, but think through whether zero is a meaningful value for your use case. If zero means something specific (such as no score assigned yet), you may want to handle that explicitly in your business logic or add a helper Boolean field to track whether the value has been set.
Add an Index When You Filter on the Field
If you plan to filter, sort, or group by an Integer field frequently, add index=True in the field definition. This creates a database index and can significantly speed up queries on large datasets. The tradeoff is a small increase in storage and write time, which is almost always worth it for fields used in search conditions.
Use store=True for Computed Integer Fields
If you define a computed Integer field that users need to filter or sort on in list views, always set store=True. Without it, Odoo cannot use the field in domain filters, and grouping by it will not work as expected.
Document Your Ranges
When an Integer field has a meaningful range, like a score from 0 to 100, document that in the help parameter. This text appears as a tooltip in the interface and saves users from guessing what values are valid.
Think Twice Before Using Integer for IDs or References
If you need to reference another record, use a Many2one field instead of storing an ID in an Integer field manually. Many2one fields give you built-in navigation, cascading rules, and proper ORM integration. An Integer holding a raw ID is fragile and bypasses the Odoo framework.
Common Pitfalls
These are the mistakes that come up most often when working with Integer fields in Odoo.
Confusing Integer with Float
A common mistake is using an Integer field where a Float field would be more appropriate. If your users will ever need to enter 1.5, 0.25, or any fractional value, Integer is the wrong choice. Odoo will silently truncate decimal input, which leads to data loss and user confusion. Use Float for quantities that can be fractional, and Monetary for currency values.
Assuming Zero Means Empty
Because Integer fields always return 0 when not set, there is no way to distinguish between a record where the field was never filled in and one where someone intentionally entered zero. If this distinction matters for your workflow, add a Boolean field like has_score alongside the Integer, or use a Float field with a False default instead.
Not Adding an Index on Frequently Filtered Fields
If you add an Integer field and later use it as a filter in views or automated actions, forgetting to add index=True can slow down list views noticeably on larger databases. It is easier to add the index from the start than to optimize later.
Using Integer to Store Decimal-Based Ratios
Sometimes developers store percentages as Integer fields, writing 75 to mean 75%. This works until someone needs 72.5%, at which point the field breaks the requirement. If there is any chance a percentage or ratio will need decimal precision, use Float from the beginning.
Forgetting store=True on Computed Fields Used in Filters
This is one of the most common mistakes in Odoo development. A computed Integer field without store=True cannot be used in domain filters, automated actions, or list view group-by operations. Always think about where the field will be used before deciding whether to store it.
Conclusion
The Integer field is a fundamental building block in the Odoo data model. It looks simple, and in most cases it is. But knowing its specific behaviors, like the fact that empty fields return 0 and computed fields need store=True to work in filters, helps you avoid the kinds of bugs and design issues that are easy to introduce and harder to fix later.
Whether you are configuring Odoo for a sales team, building a custom module, or designing reorder rules for a warehouse, Integer fields will show up at every step. Understanding how they work in the Odoo ORM, how to create them with Studio or Python, and when to use them versus Float or Monetary is part of what makes an Odoo implementation solid and maintainable.
If you are working on an Odoo customization and want to make sure your data model is built the right way from the start, this kind of foundational knowledge pays off over the entire lifetime of the project.
Work with an Odoo Expert
At Dasolo, we help companies implement, customize, and optimize Odoo across all modules and industries. Whether you need to design a clean data model, build custom fields and workflows, or connect Odoo to external systems through the API, we bring the experience to do it right.
If you have questions about your Odoo setup or want to discuss a project, reach out to our team. We are happy to help.