diff --git a/nummi/transaction/templates/transaction/transaction_table.html b/nummi/transaction/templates/transaction/transaction_table.html index 6e34f14..4879d3f 100644 --- a/nummi/transaction/templates/transaction/transaction_table.html +++ b/nummi/transaction/templates/transaction/transaction_table.html @@ -9,13 +9,13 @@ - {% if not category %}{% endif %} - {% if not account %}{% endif %} + {% if not hide_category %}{% endif %} + {% if not hide_account %}{% endif %} {% if new_transaction_url %} - + {% translate "Create transaction" %} @@ -27,10 +27,10 @@ {% translate "Expenses" %} {% translate "Income" %} {% translate "Trader" %} - {% if not category %} + {% if not hide_category %} {% translate "Category" %} {% endif %} - {% if not account %} + {% if not hide_account %} {% translate "Account" %} {% endif %} @@ -61,14 +61,14 @@ {{ trans.value|pmvalue }} {% if trans.value < 0 %}{% endif %} {{ trans.trader|default_if_none:"" }} - {% if not category %} + {% if not hide_category %} {% if trans.category %} {{ trans.category.icon|remix }}{{ trans.category }} {% endif %} {% endif %} - {% if not account %} + {% if not hide_account %} {% if trans.account %} {{ trans.account.icon|remix }}{{ trans.account|default_if_none:"" }} @@ -78,14 +78,14 @@ {% empty %} - {% translate "No transaction" %} + {% translate "No transaction" %} {% endfor %} {% if transactions_url %} - + {% translate "View all transactions" %} diff --git a/nummi/transaction/templatetags/transaction_extras.py b/nummi/transaction/templatetags/transaction_extras.py index 7817cfb..e2311a0 100644 --- a/nummi/transaction/templatetags/transaction_extras.py +++ b/nummi/transaction/templatetags/transaction_extras.py @@ -10,16 +10,25 @@ from ..utils import ac_url register = template.Library() -@register.inclusion_tag("transaction/transaction_table.html") -def transaction_table(transactions, **kwargs): - if (n_max := kwargs.get("n_max")) is not None: +@register.inclusion_tag("transaction/transaction_table.html", takes_context=True) +def transaction_table(context, transactions, n_max=None, **kwargs): + if n_max is not None: if transactions.count() <= n_max: del kwargs["transactions_url"] transactions = transactions[:n_max] - return kwargs | { - "transactions": transactions, - } + if "account" in context or "statement" in context: + kwargs.setdefault("hide_account", True) + if "category" in context: + kwargs.setdefault("hide_category", True) + + ncol = 8 + if kwargs.get("hide_account"): + ncol -= 1 + if kwargs.get("hide_category"): + ncol -= 1 + + return kwargs | {"transactions": transactions, "ncol": ncol} @register.inclusion_tag("transaction/invoice_table.html") @@ -54,13 +63,3 @@ def year_url(context, year, cls=""): f"""""" f"""""" ) - - -@register.simple_tag(takes_context=True) -def tr_colspan(context): - ncol = 8 - if context.get("category"): - ncol -= 1 - if context.get("account"): - ncol -= 1 - return ncol