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="value">
|
<col class="value">
|
||||||
<col class="desc">
|
<col class="desc">
|
||||||
{% if not category %}<col class="desc">{% endif %}
|
{% if not hide_category %}<col class="desc">{% endif %}
|
||||||
{% if not account %}<col class="desc">{% endif %}
|
{% if not hide_account %}<col class="desc">{% endif %}
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead>
|
<thead>
|
||||||
{% if new_transaction_url %}
|
{% if new_transaction_url %}
|
||||||
<tr class="new">
|
<tr class="new">
|
||||||
<td colspan="{% tr_colspan %}">
|
<td colspan="{{ ncol }}">
|
||||||
<a href="{{ new_transaction_url }}">{% translate "Create transaction" %}</a>
|
<a href="{{ new_transaction_url }}">{% translate "Create transaction" %}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -27,10 +27,10 @@
|
||||||
<th>{% translate "Expenses" %}</th>
|
<th>{% translate "Expenses" %}</th>
|
||||||
<th>{% translate "Income" %}</th>
|
<th>{% translate "Income" %}</th>
|
||||||
<th>{% translate "Trader" %}</th>
|
<th>{% translate "Trader" %}</th>
|
||||||
{% if not category %}
|
{% if not hide_category %}
|
||||||
<th>{% translate "Category" %}</th>
|
<th>{% translate "Category" %}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not account %}
|
{% if not hide_account %}
|
||||||
<th>{% translate "Account" %}</th>
|
<th>{% translate "Account" %}</th>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -61,14 +61,14 @@
|
||||||
<td class="value">{{ trans.value|pmvalue }}</td>
|
<td class="value">{{ trans.value|pmvalue }}</td>
|
||||||
{% if trans.value < 0 %}<td></td>{% endif %}
|
{% if trans.value < 0 %}<td></td>{% endif %}
|
||||||
<td>{{ trans.trader|default_if_none:"" }}</td>
|
<td>{{ trans.trader|default_if_none:"" }}</td>
|
||||||
{% if not category %}
|
{% if not hide_category %}
|
||||||
<td>
|
<td>
|
||||||
{% if trans.category %}
|
{% if trans.category %}
|
||||||
<a href="{{ trans.category.get_absolute_url }}">{{ trans.category.icon|remix }}{{ trans.category }}</a>
|
<a href="{{ trans.category.get_absolute_url }}">{{ trans.category.icon|remix }}{{ trans.category }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not account %}
|
{% if not hide_account %}
|
||||||
<td>
|
<td>
|
||||||
{% if trans.account %}
|
{% if trans.account %}
|
||||||
<a href="{{ trans.account.get_absolute_url }}">{{ trans.account.icon|remix }}{{ trans.account|default_if_none:"" }}</a>
|
<a href="{{ trans.account.get_absolute_url }}">{{ trans.account.icon|remix }}{{ trans.account|default_if_none:"" }}</a>
|
||||||
|
@ -78,14 +78,14 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="empty" colspan="{% tr_colspan %}">{% translate "No transaction" %}</td>
|
<td class="empty" colspan="{{ ncol }}">{% translate "No transaction" %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
{% if transactions_url %}
|
{% if transactions_url %}
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr class="more">
|
<tr class="more">
|
||||||
<td colspan="{% tr_colspan %}">
|
<td colspan="{{ ncol }}">
|
||||||
<a href="{{ transactions_url }}">{% translate "View all transactions" %}</a>
|
<a href="{{ transactions_url }}">{% translate "View all transactions" %}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -10,16 +10,25 @@ from ..utils import ac_url
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag("transaction/transaction_table.html")
|
@register.inclusion_tag("transaction/transaction_table.html", takes_context=True)
|
||||||
def transaction_table(transactions, **kwargs):
|
def transaction_table(context, transactions, n_max=None, **kwargs):
|
||||||
if (n_max := kwargs.get("n_max")) is not None:
|
if n_max is not None:
|
||||||
if transactions.count() <= n_max:
|
if transactions.count() <= n_max:
|
||||||
del kwargs["transactions_url"]
|
del kwargs["transactions_url"]
|
||||||
transactions = transactions[:n_max]
|
transactions = transactions[:n_max]
|
||||||
|
|
||||||
return kwargs | {
|
if "account" in context or "statement" in context:
|
||||||
"transactions": transactions,
|
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")
|
@register.inclusion_tag("transaction/invoice_table.html")
|
||||||
|
@ -54,13 +63,3 @@ def year_url(context, year, cls=""):
|
||||||
f"""<a class="{cls}" href="{url}">"""
|
f"""<a class="{cls}" href="{url}">"""
|
||||||
f"""<time datetime="{year}">{year}</time></a>"""
|
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