mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-13 12:23:44 +01:00
Account.displayed_exchange_currency holds the account/currency precedence for transactions, and shown_exchange_currency() expresses the same rule as a query expression for the insights and account totals, replacing the per-module checks.
14 lines
430 B
Python
14 lines
430 B
Python
from django.db.models import Case, F, When
|
|
|
|
|
|
def shown_exchange_currency(path):
|
|
"""Query expression for the exchange currency id at ``path`` (an account or a
|
|
currency lookup, such as ``"account__currency__"``), or NULL when that object
|
|
hides its exchanged amounts."""
|
|
return Case(
|
|
When(
|
|
**{f"{path}show_exchanged_amounts": True},
|
|
then=F(f"{path}exchange_currency"),
|
|
)
|
|
)
|