2021-07-01 13:36:07 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 04.12.20
|
|
|
|
|
|
|
|
"""
|
2021-07-26 10:23:09 +02:00
|
|
|
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
|
2021-07-01 13:36:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class NewCompensationForm(BaseForm):
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2021-07-26 10:23:09 +02:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class NewPaymentForm(BaseModalForm):
|
2021-07-26 11:29:05 +02:00
|
|
|
amount = forms.DecimalField(
|
|
|
|
min_value=0.00,
|
|
|
|
decimal_places=2,
|
2021-07-26 10:23:09 +02:00
|
|
|
label=_("Amount"),
|
|
|
|
label_suffix=_(""),
|
2021-07-26 11:29:05 +02:00
|
|
|
help_text=_("Amount in Euro"),
|
2021-07-26 10:23:09 +02:00
|
|
|
)
|
|
|
|
due = forms.DateField(
|
|
|
|
label=_("Due on"),
|
|
|
|
label_suffix=_(""),
|
2021-07-26 11:29:05 +02:00
|
|
|
help_text=_("Due on which date"),
|
2021-07-26 10:23:09 +02:00
|
|
|
widget=forms.DateInput(
|
|
|
|
attrs={
|
|
|
|
"type": "date",
|
|
|
|
"data-provide": "datepicker",
|
|
|
|
},
|
|
|
|
format="%d.%m.%Y"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
transfer_note = forms.CharField(
|
|
|
|
max_length=1000,
|
|
|
|
required=False,
|
|
|
|
label_suffix=_(""),
|
2021-07-26 11:29:05 +02:00
|
|
|
label=_("Transfer note"),
|
|
|
|
help_text=_("Note for money transfer")
|
2021-07-26 10:23:09 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2021-07-26 11:29:05 +02:00
|
|
|
self.intervention = self.instance
|
2021-07-26 10:23:09 +02:00
|
|
|
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
|