How to Add Filters to Accounting Reports in Odoo 18: Complete Step by Step Guide
By Braincuber Team
Published on March 20, 2026
In Odoo 18, customizing accounting reports is essential for businesses that need tailored financial insights. One of the most powerful customizations you can make is to add filters to accounting reports, allowing users to narrow down results based on specific criteria like accounts, dates, or other custom filters. This complete tutorial will guide you through the process of adding a customizable account filter to accounting reports in Odoo 18.
What You'll Learn:
- How to add custom filter fields to account.report model
- Implementing backend logic for filter initialization and domain handling
- Creating XML views for filter interface customization
- Building QWeb templates for interactive filter dropdowns
- Configuring manifest files for proper module loading
- Testing and validating custom accounting report filters
Understanding Custom Accounting Report Filters
Custom filters in Odoo 18 accounting reports provide enhanced flexibility for financial analysis by allowing users to narrow down data based on specific criteria. By implementing account filters, you can create more focused reports that display only the relevant financial data for specific accounts, departments, or business units. This customization is particularly valuable for organizations with complex chart of accounts or those requiring specialized reporting for different stakeholders.
Step 1: Creating the Account Report Model Extension
The first step in adding a custom filter is to modify the model. In this case, we will be adding a field to the account.report model, which is responsible for defining accounting reports in Odoo. This field will serve as the custom filter, allowing users to select specific accounts when generating financial reports.
Create account_report.py Model File
Create a file named account_report.py inside your models folder. In this file, we need to inherit the account.report model and add the filter_account field.
Add Boolean Filter Field
We need to add a Boolean field to the account.report model. This field will control whether the Account filter is applied to the report.
from odoo import api, fields, models
class AccountReport(models.Model):
_inherit = 'account.report'
filter_account = fields.Boolean(
string="Accounts",
compute=lambda x: x._compute_report_option_filter('filter_account'),
readonly=False,
store=True,
depends=['root_report_id', 'section_main_report_ids'],
)
Field Explanation
The filter_account field is a Boolean that determines whether the account filter is applied to the report. The compute property ensures this field is calculated automatically using the method _compute_report_option_filter('filter_account'), which checks if the filter should be active. The depends property ensures the field is recalculated whenever related fields change.
To ensure that the changes we made to the model are recognized by Odoo, we need to import our account_report.py file in the __init__.py file. The __init__.py file is used to initialize Python modules in your custom module.
Step 2: Configuring Module Imports
In the models folder, there is another __init__.py file. You need to import your model file (like account_report.py) into this file. Additionally, in the root of your module, there is also an __init__.py file where you need to import the models folder.
Models Folder __init__.py
Import your model file into the models folder's __init__.py file to make it available to the module.
Root Module __init__.py
Import the models folder in the root __init__.py file so that all models are loaded together.
# models/__init__.py
from . import account_report
# __init__.py (root)
from . import models
Step 3: Creating XML Views for Filter Interface
After adding the filter field to the model, the next step is to make this field visible and usable in the Odoo user interface. We do this by modifying XML views. We need to create or modify an XML file that defines how the filter_account field will appear in the user interface.
Create View XML File
Create an XML file like account_report_views.xml in the views directory to define the form view inheritance.
Add Field to Form View
Add the filter_account field to the accounting report form view using XPath inheritance.
account.report.form.view.inherit.account.filter
account.report
XML Structure Explanation
After placing the view file in the correct folder, we need to tell Odoo to load it by adding it to the data section of the manifest.py file. The XPath expression positions the filter_account field after the existing filter_partner field.
Now, users will be able to see and configure the Account filter option directly within the report interface. This allows for greater flexibility, as the filter can be customized based on the specific accounts they want to include in their reports.
Step 4: Implementing Backend Filter Logic
After adding the field for the filter in the model, the next step is to define the logic for how the filter options are initialized and handled. This is achieved through two important methods: _init_options_account and _get_options_domain. These methods set up the logic for managing and applying the account filter based on the user's selection.
Initialize Filter Options
The _init_options_account method is responsible for setting up filter options based on the user's selection.
Create Filter Domain
The _get_options_accounts_domain method creates a domain to filter report data based on selected accounts.
def _init_options_account(self, options, previous_options):
if not self.filter_account:
return
options['account'] = True
previous_account_ids = previous_options.get('account_ids') or []
selected_account_ids = [int(partner) for partner in previous_account_ids]
# search instead of browse so that record rules apply and filter out ones user does not have access to
selected_accounts = selected_account_ids and self.env['account.account'].with_context(active_test=False).search([('id', 'in', selected_account_ids)]) or self.env['account.account']
options['selected_account_ids'] = selected_accounts.mapped('name')
options['account_ids'] = selected_accounts.ids
@api.model
def _get_options_accounts_domain(self, options):
domain = []
if options.get('account_ids'):
account_ids = [int(account) for account in options['account_ids']]
domain.append(('account_id', 'in', account_ids))
return domain
def _get_options_domain(self, options, date_scope):
self.ensure_one()
domain = super()._get_options_domain(options, date_scope)
domain += self._get_options_accounts_domain(options)
return domain
Method Functions
The _init_options_account method checks whether the filter is enabled and retrieves selected accounts. The _get_options_accounts_domain method creates a domain condition to filter data by selected account IDs. The _get_options_domain method combines the account filter with existing report filters.
Step 5: Creating QWeb Templates for Filter UI
Now that we've completed the backend logic for the account filter, the next step is to make the filter available in the report's user interface. For this, we use a QWeb template to define how the account filter will appear and function in the UI.
Main Filter Template
Extend the existing report filter template and insert the new account filter using XPath.
Account Dropdown Template
Create a template for the dropdown menu with MultiRecordSelector for account selection.
Filter Extension Template
This template extends the existing report filter interface and adds the account filter dropdown with proper conditional rendering.
Interactive Dropdown
The dropdown template uses Odoo's Dropdown component and MultiRecordSelector for an intuitive user experience.
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="account_filter.accountingReportAccountFilter"
t-inherit="account_reports.AccountReportFiltersCustomizable"
t-inherit-mode="extension">
<xpath expr="//t[@t-if='controller.filters.show_period_comparison']"
position="after">
<t t-if="'account' in controller.options">
<div id="filter_account" class="filter_account">
<t t-call="account_reports.AccountReportFilterAccounts"/>
</div>
</t>
</xpath>
</t>
</templates>
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t t-name="account_reports.AccountReportFilterAccounts">
<Dropdown
menuClass="'account_report_filter account'">
<button class="btn btn-secondary">
<i class="fa fa-folder-open me-1"/>Accounts
</button>
<t t-set-slot="content">
<div class="dropdown-item gap-2 align-items-center">
<label>Accounts</label>
<MultiRecordSelector t-props="getMultiRecordSelectorProps('account.account', 'account_ids')"/>
</div>
</t>
</Dropdown>
</t>
</templates>
Template Integration
The first template extends the existing report filter interface, while the second template defines the actual dropdown structure with MultiRecordSelector for account selection.
Step 6: Configuring Manifest File
Now that we have defined the necessary views and templates for the account filter, the next step is to make sure these files are loaded properly in Odoo. To do that, we need to include them in the __manifest__.py file of our custom module.
Basic Manifest Structure
Define module dependencies and data files for proper loading.
Asset Configuration
Include static files for frontend components in the assets section.
{
'name': 'Account filter in Financial report',
'version': '18.0.1.0.0',
'depends': ['account', 'account_reports'],
'data': [
'views/account_report_views.xml',
],
'assets': {
'web.assets_backend': [
'account_filter/static/src/components/**/*',
],
},
}
Manifest Configuration
The manifest file defines module dependencies, data files, and assets. The data section includes our view files, while assets include any frontend components needed for the filter interface.
Step 7: Testing and Validating the Filter
After successfully installing the module, you will see an option to enable the Account Filter in each accounting report. This allows you to filter reports by accounts directly from the report interface.
Enable Account Filter
Once you enable the Account Filter option, you will see the filter appear directly in the corresponding accounting report.
Select Accounts for Filtering
Once the Account Filter is enabled, you can select corresponding accounts directly from the filter dropdown, and it filters the report correspondingly.
| Filter Feature | Description |
|---|---|
| Account Filter Option | Boolean field to enable/disable account filtering in reports |
| Multi-Record Selector | Interactive dropdown for selecting multiple accounts |
| Domain Filtering | Automatic domain application based on selected accounts |
Testing Best Practices
Test the filter with different account selections to ensure proper functionality. Verify that the domain filtering works correctly and that reports only show data for selected accounts.
With these steps completed, you now have the ability to filter accounting reports by specific accounts, providing a more focused and personalized way to analyze financial data. This feature enhances the flexibility of Odoo's reporting system, making it easier to generate meaningful insights based on account-specific data.
Advanced Filter Customization Options
Beyond the basic account filter implementation, you can extend this functionality to create more sophisticated filtering options for your accounting reports. Consider these advanced customization possibilities:
Date Range Filters
Add custom date range filters alongside account filters for more granular reporting periods.
Analytic Account Filters
Implement analytic account filtering for department-based reporting and cost center analysis.
Custom Field Filters
Add filters based on custom account fields specific to your business requirements.
Saved Filter Presets
Implement saved filter configurations for frequently used reporting combinations.
Frequently Asked Questions
How do I add multiple filters to the same accounting report?
You can add multiple Boolean fields to the account.report model and create corresponding domain methods for each filter. Combine them in the _get_options_domain method to apply all filters simultaneously.
Can I filter accounting reports by custom account fields?
Yes, you can modify the domain logic to include custom account fields. Update the _get_options_accounts_domain method to filter based on any account field available in your chart of accounts.
How do I make the account filter mandatory for certain reports?
Set the filter_account field's default value to True in the model definition or override the default method to force the filter to be enabled for specific report types.
What permissions are needed for account filtering?
Users need read access to the account.account model to filter reports. The domain logic uses search() method which automatically applies record rules and access restrictions.
How can I export filtered report data?
Use Odoo's built-in export functionality or create a custom wizard that applies the same filter domain and exports the results to Excel or CSV format.
Need Help with Odoo 18 Accounting Customization?
Our experts can help you implement custom accounting filters and enhance your financial reporting capabilities.
