How to write a formula to get the expense accounts and analytic account code like '2%'
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilitat
- Inventari
- PoS
- Project
- MRP
This question has been flagged
You cannot use analytic_account_id.code in a domain when working with analytic distribution in Odoo because analytic_distribution is a JSON field, not a relational field.
If you want to filter records based on analytic account, you can use a domain like this:
Here, 9 is the ID of the analytic account. The 'in' operator checks if the specified analytic account ID exists in the analytic_distribution JSON field.
Hello Mahmoud,
Based on your screenshot, you're trying to create a financial report that filters expenses by analytic account codes starting with "2". Here's how to properly set this up:
The Domain Filter You Need
For your formula field in the P&L report, you'll want to combine two conditions:
- Filter for expense accounts
- Filter for analytic distribution codes starting with "2"
The correct domain syntax would be:
["&", ("account_id.account_type", "=", "expense"), ("analytic_distribution.code", "=like", "2%")]
Step-by-Step Implementation
- Navigate to Accounting → Reporting → Financial Reports
- Edit your "Profit and Loss (Challenger)" report
- For the expense line you want to filter:
- Click on the line (e.g., "Operating Costs")
- Under "Expressions", select "balance"
- In the "Formula" field, enter:
["&", ("account_id.account_type", "=", "expense"), ("analytic_distribution.code", "=like", "2%")]
- Set the Computation Engine to "Formula"
- Set Subformula to "sum" (to aggregate the results)
Key Notes About This Setup
- The =like operator is used for pattern matching where % is a wildcard
- The & (AND) operator combines both conditions
- Account types in Odoo 15+ use these main categories:
- income
- expense
- asset
- liability
- equity
Alternative Approach (If Above Doesn't Work)
If you have issues with the analytic distribution filter, try this alternative:
["&", ("account_id.account_type", "=", "expense"), ("analytic_account_id.code", "=like", "2%")]
Testing Your Report
After saving:
- Generate the report
- Verify only expenses with analytic accounts starting with "2" are included
- Check your analytic account codes actually follow this pattern (you can view them in Accounting → Configuration → Analytic Accounts)
🚀 Did This Solve Your Problem?
If this answer helped you save time, money, or frustration, consider:
✅ Upvoting (👍) to help others find it faster
✅ Marking as "Best Answer" if it resolved your issue
Your feedback keeps the Odoo community strong! 💪
(Need further customization? Drop a comment—I’m happy to refine the solution!)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Registrar-seRelated Posts | Respostes | Vistes | Activitat | |
---|---|---|---|---|
|
0
d’ag. 25
|
3 | ||
|
0
d’ag. 25
|
73 | ||
|
0
de juny 25
|
448 | ||
|
4
de maig 25
|
2685 | ||
|
2
de maig 25
|
6116 |