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
- Buchhaltung
- Lager
- PoS
- Project
- MRP
Diese Frage wurde gekennzeichnet
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!)
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!
Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!
RegistrierenVerknüpfte Beiträge | Antworten | Ansichten | Aktivität | |
---|---|---|---|---|
|
0
Aug. 25
|
3 | ||
|
0
Aug. 25
|
79 | ||
|
0
Juni 25
|
448 | ||
|
4
Mai 25
|
2693 | ||
|
2
Mai 25
|
6124 |