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!)
| 関連投稿 | 返信 | ビュー | 活動 | |
|---|---|---|---|---|
|
|
1
10月 25
|
1110 | ||
|
|
2
10月 25
|
643 | ||
|
|
4
10月 25
|
3345 | ||
|
|
2
9月 25
|
2117 | ||
|
|
4
9月 25
|
7342 |