Improve transaction form
Default to no statement (fix #28) Add link to statement on statement transaction creation Fix textarea height
This commit is contained in:
parent
7478404d8a
commit
38ab298094
5 changed files with 32 additions and 11 deletions
|
@ -42,6 +42,9 @@ form {
|
||||||
|
|
||||||
&:has(> textarea) {
|
&:has(> textarea) {
|
||||||
grid-template-rows: min-content 1fr;
|
grid-template-rows: min-content 1fr;
|
||||||
|
textarea {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&:has(> input[type="checkbox"]) {
|
&:has(> input[type="checkbox"]) {
|
||||||
grid-template-columns: min-content 1fr;
|
grid-template-columns: min-content 1fr;
|
||||||
|
@ -68,6 +71,10 @@ form {
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> a {
|
||||||
|
padding: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
input,
|
input,
|
||||||
select,
|
select,
|
||||||
textarea {
|
textarea {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
|
from django.forms.widgets import Select
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from main.forms import NummiFileInput, NummiForm
|
from main.forms import NummiFileInput, NummiForm
|
||||||
from transaction.models import Transaction
|
from transaction.models import Transaction
|
||||||
|
@ -50,3 +51,7 @@ class StatementForm(NummiForm):
|
||||||
|
|
||||||
instance.transaction_set.add(*new_transactions, bulk=False)
|
instance.transaction_set.add(*new_transactions, bulk=False)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
class StatementSelect(Select):
|
||||||
|
template_name = "statement/forms/widgets/statement.html"
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{% load main_extras %}
|
||||||
|
{% if widget.attrs.disabled %}
|
||||||
|
{% for group_name, group_choices, group_index in widget.optgroups %}
|
||||||
|
{% for option in group_choices %}
|
||||||
|
{% if option.selected %}
|
||||||
|
<a href="{% url "statement" statement=option.value %}">{{ "file"|remix }}{{ option.label }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% include "django/forms/widgets/select.html" %}
|
||||||
|
{% endif %}
|
|
@ -2,6 +2,7 @@ import json
|
||||||
|
|
||||||
from category.forms import CategorySelect
|
from category.forms import CategorySelect
|
||||||
from main.forms import DatalistInput, NummiFileInput, NummiForm
|
from main.forms import DatalistInput, NummiFileInput, NummiForm
|
||||||
|
from statement.forms import StatementSelect
|
||||||
|
|
||||||
from .models import Invoice, Transaction
|
from .models import Invoice, Transaction
|
||||||
from .utils import get_datalist
|
from .utils import get_datalist
|
||||||
|
@ -22,6 +23,7 @@ class TransactionForm(NummiForm):
|
||||||
"description",
|
"description",
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
|
"statement": StatementSelect(),
|
||||||
"category": CategorySelect(),
|
"category": CategorySelect(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ from main.views import (
|
||||||
NummiUpdateView,
|
NummiUpdateView,
|
||||||
UserMixin,
|
UserMixin,
|
||||||
)
|
)
|
||||||
from statement.models import Statement
|
|
||||||
|
|
||||||
from .forms import InvoiceForm, TransactionForm
|
from .forms import InvoiceForm, TransactionForm
|
||||||
from .models import Invoice, Transaction
|
from .models import Invoice, Transaction
|
||||||
|
@ -23,23 +22,19 @@ class TransactionCreateView(NummiCreateView):
|
||||||
form_class = TransactionForm
|
form_class = TransactionForm
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
_queryset = Statement.objects.filter(user=self.request.user)
|
initial = super().get_initial()
|
||||||
if "statement" in self.kwargs:
|
if "statement" in self.kwargs:
|
||||||
self.statement = get_object_or_404(_queryset, pk=self.kwargs["statement"])
|
initial["statement"] = get_object_or_404(
|
||||||
else:
|
self.request.user.statement_set, pk=self.kwargs["statement"]
|
||||||
self.statement = _queryset.first()
|
)
|
||||||
return {"statement": self.statement}
|
|
||||||
|
return initial
|
||||||
|
|
||||||
def get_form_kwargs(self):
|
def get_form_kwargs(self):
|
||||||
if "statement" in self.kwargs:
|
if "statement" in self.kwargs:
|
||||||
return super().get_form_kwargs() | {"disable_statement": True}
|
return super().get_form_kwargs() | {"disable_statement": True}
|
||||||
return super().get_form_kwargs()
|
return super().get_form_kwargs()
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
if "statement" in self.kwargs:
|
|
||||||
return super().get_context_data(**kwargs) | {"statement": self.statement}
|
|
||||||
return super().get_context_data(**kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class InvoiceCreateView(NummiCreateView):
|
class InvoiceCreateView(NummiCreateView):
|
||||||
model = Invoice
|
model = Invoice
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue