Compensation action
* adds compensation action to compensation detail view * adds adding/removing logic for compensation action * adds bootstrap style to select fields in forms * refactors UnitEnum into UnitChoices using models.TextChoices (Django 3.x) * adds translations
This commit is contained in:
+69
-3
@@ -12,7 +12,7 @@ from django.http import HttpRequest
|
||||
from django.shortcuts import redirect, render
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import Payment, CompensationState
|
||||
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
|
||||
from konova.contexts import BaseContext
|
||||
from konova.forms import BaseForm, BaseModalForm
|
||||
from konova.models import Deadline, DeadlineType
|
||||
@@ -156,7 +156,12 @@ class NewDeadlineModalForm(BaseModalForm):
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select the deadline type"),
|
||||
choices=DeadlineType.choices
|
||||
choices=DeadlineType.choices,
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
"class": "custom-select"
|
||||
}
|
||||
)
|
||||
)
|
||||
date = forms.DateField(
|
||||
label=_("Date"),
|
||||
@@ -193,7 +198,7 @@ class NewDeadlineModalForm(BaseModalForm):
|
||||
with transaction.atomic():
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED.value
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
deadline = Deadline.objects.create(
|
||||
type=self.cleaned_data["type"],
|
||||
@@ -204,3 +209,64 @@ class NewDeadlineModalForm(BaseModalForm):
|
||||
self.instance.deadlines.add(deadline)
|
||||
return deadline
|
||||
|
||||
|
||||
class NewActionModalForm(BaseModalForm):
|
||||
action_type = forms.CharField(
|
||||
label=_("Action Type"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select the deadline type"),
|
||||
)
|
||||
unit = forms.ChoiceField(
|
||||
label=_("Unit"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Select the unit"),
|
||||
choices=UnitChoices.choices,
|
||||
widget=forms.Select(
|
||||
attrs={
|
||||
"class": "custom-select"
|
||||
}
|
||||
)
|
||||
)
|
||||
amount = forms.DecimalField(
|
||||
label=_("Amount"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
help_text=_("Insert the amount"),
|
||||
decimal_places=2,
|
||||
min_value=0.00,
|
||||
)
|
||||
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 action")
|
||||
self.form_caption = _("Insert data for the new action")
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
comp_action = CompensationAction.objects.create(
|
||||
action_type=self.cleaned_data["action_type"],
|
||||
amount=self.cleaned_data["amount"],
|
||||
unit=self.cleaned_data["unit"],
|
||||
created=user_action,
|
||||
)
|
||||
self.instance.actions.add(comp_action)
|
||||
return comp_action
|
||||
|
||||
|
||||
Reference in New Issue
Block a user