Payments add modal form

* adds modal form for adding payments
* generalizes generic_table_form.html for table-form-like usage in modal_form.html
* adds css enhancements for focused input fields
* adds BaseModalForm as specification to BaseForm, which inherits the BSModalForm class as well
* adds translations
This commit is contained in:
mipel
2021-07-26 10:23:09 +02:00
parent 8885f81770
commit 23afe2654e
14 changed files with 194 additions and 75 deletions
+52 -2
View File
@@ -5,10 +5,60 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 04.12.20
"""
from konova.forms import BaseForm
from django import forms
from django.db import transaction
from django.utils.translation import gettext_lazy as _
from compensation.models import Payment
from konova.forms import BaseForm, BaseModalForm
class NewCompensationForm(BaseForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
class NewPaymentForm(BaseModalForm):
amount = forms.FloatField(
min_value=0.01,
label=_("Amount"),
label_suffix=_(""),
)
due = forms.DateField(
required=False,
label=_("Due on"),
label_suffix=_(""),
widget=forms.DateInput(
attrs={
"type": "date",
"data-provide": "datepicker",
},
format="%d.%m.%Y"
)
)
transfer_note = forms.CharField(
max_length=1000,
required=False,
label_suffix=_(""),
label=_("Transfer note")
)
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("request", None).user
self.intervention = kwargs.pop("intervention", None)
super().__init__(*args, **kwargs)
self.form_title = _("Payment")
self.form_caption = _("Add a payment for intervention '{}'").format(self.intervention.title)
def save(self):
with transaction.atomic():
pay = Payment.objects.create(
created_by=self.user,
amount=self.cleaned_data.get("amount", -1),
due_on=self.cleaned_data.get("due", None),
comment=self.cleaned_data.get("transfer_note", None),
intervention=self.intervention,
)
return pay