Compensation detail view
* adds compensation detail view (WIP) * adds includes dir for related objects, similar to interventions * adds functionality for * adding/removing before_states * adding/removing after_states * adding/removing deadlines * adding/removing documents * refactors usage of BaseModalForm * holds now process_request() in base class for generic usage anywhere * adds __str__() method for some models * compensation__action is blank=True now * renamed tooltips * adds new routes for state/deadline/document handling inside of compensation/urls.py * adds precalculation of before/after_states for detail view, so users will see directly if there are missing states * removes unnecessary link for intervention detail payment * adds missing tooltips for check and record icon on detail views * refactors DeadlineTypeEnum into DeadlineType in konova/models.py, just as the django 3.x documentation suggests for model enumerations * UuidModel id field is not editable anymore in the admin interface * adds/updates translations
This commit is contained in:
+93
-2
@@ -9,9 +9,10 @@ from django import forms
|
||||
from django.db import transaction
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import Payment
|
||||
from compensation.models import Payment, CompensationState
|
||||
from konova.enums import UserActionLogEntryEnum
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
from konova.models import Deadline, DeadlineType
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -69,4 +70,94 @@ class NewPaymentForm(BaseModalForm):
|
||||
comment=self.cleaned_data.get("transfer_note", None),
|
||||
intervention=self.intervention,
|
||||
)
|
||||
return pay
|
||||
return pay
|
||||
|
||||
|
||||
class NewStateModalForm(BaseModalForm):
|
||||
biotope_type = forms.CharField(
|
||||
label=_("Biotope Type"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select the biotope type")
|
||||
)
|
||||
surface = forms.DecimalField(
|
||||
min_value=0.00,
|
||||
decimal_places=2,
|
||||
label=_("Surface"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("in m²")
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("New state")
|
||||
self.form_caption = _("Insert data for the new state")
|
||||
|
||||
def save(self, is_before_state: bool = False):
|
||||
with transaction.atomic():
|
||||
state = CompensationState.objects.create(
|
||||
biotope_type=self.cleaned_data["biotope_type"],
|
||||
surface=self.cleaned_data["surface"],
|
||||
)
|
||||
if is_before_state:
|
||||
self.instance.before_states.add(state)
|
||||
else:
|
||||
self.instance.after_states.add(state)
|
||||
return state
|
||||
|
||||
|
||||
class NewDeadlineModalForm(BaseModalForm):
|
||||
type = forms.ChoiceField(
|
||||
label=_("Deadline Type"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select the deadline type"),
|
||||
choices=DeadlineType.choices
|
||||
)
|
||||
date = forms.DateField(
|
||||
label=_("Date"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select date"),
|
||||
widget=forms.DateInput(
|
||||
attrs={
|
||||
"type": "date",
|
||||
"data-provide": "datepicker",
|
||||
},
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
)
|
||||
comment = forms.CharField(
|
||||
required=False,
|
||||
label=_("Comment"),
|
||||
label_suffix=_(""),
|
||||
help_text=_("Additional comment"),
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
"cols": 30,
|
||||
"rows": 5,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("New deadline")
|
||||
self.form_caption = _("Insert data for the new deadline")
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserActionLogEntryEnum.CREATED.value
|
||||
)
|
||||
deadline = Deadline.objects.create(
|
||||
type=self.cleaned_data["type"],
|
||||
date=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
created=action,
|
||||
)
|
||||
self.instance.deadlines.add(deadline)
|
||||
return deadline
|
||||
|
||||
|
||||
Reference in New Issue
Block a user