Add visibility on invoices

Add links to invoices on transaction tables
Added invoices and has_invoice properties to transactions
This commit is contained in:
Edgar P. Burkhart 2022-12-21 09:38:17 +01:00
parent 7895210aea
commit 996f6a9f18
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
5 changed files with 19 additions and 4 deletions

View file

@ -59,6 +59,14 @@ class Transaction(models.Model):
def __str__(self): def __str__(self):
return f"{self.date} {self.name}" return f"{self.date} {self.name}"
@property
def invoices(self):
return Invoice.objects.filter(transaction=self)
@property
def has_invoice(self):
return self.invoices.count() > 0
class Meta: class Meta:
ordering = ["-date"] ordering = ["-date"]
verbose_name = _("Transaction") verbose_name = _("Transaction")

View file

@ -11,6 +11,7 @@
.table.col4 {grid-template-columns: repeat(4, auto)} .table.col4 {grid-template-columns: repeat(4, auto)}
.table.col5 {grid-template-columns: repeat(5, auto)} .table.col5 {grid-template-columns: repeat(5, auto)}
.table.col6 {grid-template-columns: repeat(6, auto)} .table.col6 {grid-template-columns: repeat(6, auto)}
.table.col1-6 {grid-template-columns: min-content repeat(6, auto)}
.table > div { .table > div {
display: contents; display: contents;

View file

@ -1,8 +1,9 @@
{% load main_extras %} {% load main_extras %}
{% load i18n %} {% load i18n %}
<div id="transactions" class="table col6"> <div id="transactions" class="table col1-6">
<div class="header"> <div class="header">
<strong class="attach center"><i class="fa fa-paperclip"></i></strong>
<strong class="date center">{% translate "Date" %}</strong> <strong class="date center">{% translate "Date" %}</strong>
<strong class="name">{% translate "Name" %}</strong> <strong class="name">{% translate "Name" %}</strong>
<strong class="value center">{% translate "Value" %}</strong> <strong class="value center">{% translate "Value" %}</strong>
@ -12,6 +13,13 @@
</div> </div>
{% for trans in transactions %} {% for trans in transactions %}
<div class="transaction {% cycle 'w' 'g' %}"> <div class="transaction {% cycle 'w' 'g' %}">
<span class="attach center">
{% for invoice in trans.invoices %}
<a href="{% url "invoice" invoice.id %}">
<i class="fa fa-paperclip"></i>
</a>
{% endfor %}
</span>
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span> <span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span> <span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
<span class="value num right">{{ trans.value|pmvalue }}</span> <span class="value num right">{{ trans.value|pmvalue }}</span>

View file

@ -22,7 +22,7 @@
<h2>{% translate "Invoices" %}</h2> <h2>{% translate "Invoices" %}</h2>
<div id="invoices"> <div id="invoices">
{% for inv in invoices %} {% for inv in transaction.invoices %}
<div class="invoice"> <div class="invoice">
<a href="{% url 'invoice' inv.id %}">{{ inv.name }}</a> <a href="{% url 'invoice' inv.id %}">{{ inv.name }}</a>
<a href="{% url 'del_invoice' transaction.id inv.id %}" <a href="{% url 'del_invoice' transaction.id inv.id %}"

View file

@ -53,7 +53,6 @@ class TransactionListView(LoginRequiredMixin, ListView):
def transaction(request, uuid=None): def transaction(request, uuid=None):
_form = None _form = None
_inv_form = None _inv_form = None
_invoices = []
if request.method == "GET": if request.method == "GET":
if uuid is None: if uuid is None:
_transaction = Transaction() _transaction = Transaction()
@ -79,7 +78,6 @@ def transaction(request, uuid=None):
{ {
"transaction": _transaction, "transaction": _transaction,
"form": _form or TransactionForm(instance=_transaction), "form": _form or TransactionForm(instance=_transaction),
"invoices": _invoices or Invoice.objects.filter(transaction=_transaction),
"invoice_form": _inv_form "invoice_form": _inv_form
or InvoiceForm(instance=Invoice(transaction=_transaction)), or InvoiceForm(instance=Invoice(transaction=_transaction)),
}, },