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:
How to write a formula to get the expense accounts and analytic account code like '2%'

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:
For your formula field in the P&L report, you'll want to combine two conditions:
The correct domain syntax would be:
["&", ("account_id.account_type", "=", "expense"), ("analytic_distribution.code", "=like", "2%")]["&", ("account_id.account_type", "=", "expense"), ("analytic_distribution.code", "=like", "2%")]If you have issues with the analytic distribution filter, try this alternative:
["&", ("account_id.account_type", "=", "expense"), ("analytic_account_id.code", "=like", "2%")]After saving:
🚀 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!)
Create an account today to enjoy exclusive features and engage with our awesome community!
Înscrie-te| Related Posts | Răspunsuri | Vizualizări | Activitate | |
|---|---|---|---|---|
|
1
oct. 25
|
1328 | |||
|
2
oct. 25
|
797 | |||
|
4
oct. 25
|
3738 | |||
|
2
sept. 25
|
2406 | |||
|
4
sept. 25
|
7813 |
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.