Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

How to write a formula to get the expense accounts and analytic account code like '2%' 


Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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:

  1. Filter for expense accounts
  2. 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
  1. Navigate to Accounting → Reporting → Financial Reports
  2. Edit your "Profit and Loss (Challenger)" report
  3. 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%")]
  4. Set the Computation Engine to "Formula"
  5. Set Subformula to "sum" (to aggregate the results)
Key Notes About This Setup
  1. The =like operator is used for pattern matching where % is a wildcard
  2. The & (AND) operator combines both conditions
  3. 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:

  1. Generate the report
  2. Verify only expenses with analytic accounts starting with "2" are included
  3. 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!)

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
sie 25
60
0
sie 25
3
0
sie 25
86
0
cze 25
451
4
maj 25
2705