Fix transaction table (fix #33)
This commit is contained in:
parent
38ab298094
commit
f203d1db46
2 changed files with 24 additions and 25 deletions
|
@ -9,13 +9,13 @@
|
|||
<col class="value">
|
||||
<col class="value">
|
||||
<col class="desc">
|
||||
{% if not category %}<col class="desc">{% endif %}
|
||||
{% if not account %}<col class="desc">{% endif %}
|
||||
{% if not hide_category %}<col class="desc">{% endif %}
|
||||
{% if not hide_account %}<col class="desc">{% endif %}
|
||||
</colgroup>
|
||||
<thead>
|
||||
{% if new_transaction_url %}
|
||||
<tr class="new">
|
||||
<td colspan="{% tr_colspan %}">
|
||||
<td colspan="{{ ncol }}">
|
||||
<a href="{{ new_transaction_url }}">{% translate "Create transaction" %}</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -27,10 +27,10 @@
|
|||
<th>{% translate "Expenses" %}</th>
|
||||
<th>{% translate "Income" %}</th>
|
||||
<th>{% translate "Trader" %}</th>
|
||||
{% if not category %}
|
||||
{% if not hide_category %}
|
||||
<th>{% translate "Category" %}</th>
|
||||
{% endif %}
|
||||
{% if not account %}
|
||||
{% if not hide_account %}
|
||||
<th>{% translate "Account" %}</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
|
@ -61,14 +61,14 @@
|
|||
<td class="value">{{ trans.value|pmvalue }}</td>
|
||||
{% if trans.value < 0 %}<td></td>{% endif %}
|
||||
<td>{{ trans.trader|default_if_none:"" }}</td>
|
||||
{% if not category %}
|
||||
{% if not hide_category %}
|
||||
<td>
|
||||
{% if trans.category %}
|
||||
<a href="{{ trans.category.get_absolute_url }}">{{ trans.category.icon|remix }}{{ trans.category }}</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if not account %}
|
||||
{% if not hide_account %}
|
||||
<td>
|
||||
{% if trans.account %}
|
||||
<a href="{{ trans.account.get_absolute_url }}">{{ trans.account.icon|remix }}{{ trans.account|default_if_none:"" }}</a>
|
||||
|
@ -78,14 +78,14 @@
|
|||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td class="empty" colspan="{% tr_colspan %}">{% translate "No transaction" %}</td>
|
||||
<td class="empty" colspan="{{ ncol }}">{% translate "No transaction" %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% if transactions_url %}
|
||||
<tfoot>
|
||||
<tr class="more">
|
||||
<td colspan="{% tr_colspan %}">
|
||||
<td colspan="{{ ncol }}">
|
||||
<a href="{{ transactions_url }}">{% translate "View all transactions" %}</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -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"""<a class="{cls}" href="{url}">"""
|
||||
f"""<time datetime="{year}">{year}</time></a>"""
|
||||
)
|
||||
|
||||
|
||||
@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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue