diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index ddf8502b..6436a7c8 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -21,7 +21,7 @@ from konova.contexts import BaseContext from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm from konova.models import DeadlineType from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, ADDED_DEADLINE, \ - ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED + ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED class NewPaymentForm(BaseModalForm): @@ -466,6 +466,33 @@ class NewActionModalForm(BaseModalForm): return action +class EditCompensationActionModalForm(NewActionModalForm): + action = None + + def __init__(self, *args, **kwargs): + self.action = kwargs.pop("action", None) + super().__init__(*args, **kwargs) + form_data = { + "action_type": self.action.action_type, + "action_type_details": self.action.action_type_details.all(), + "amount": self.action.amount, + "unit": self.action.unit, + "comment": self.action.comment, + } + self.load_initial_data(form_data) + + def save(self): + action = self.action + action.action_type = self.cleaned_data.get("action_type", None) + action.action_type_details.set(self.cleaned_data.get("action_type_details", [])) + action.amount = self.cleaned_data.get("amount", None) + action.unit = self.cleaned_data.get("unit", None) + action.comment = self.cleaned_data.get("comment", None) + action.save() + self.instance.mark_as_edited(self.user, self.request, edit_comment=COMPENSATION_ACTION_EDITED) + return action + + class NewCompensationDocumentModalForm(NewDocumentModalForm): document_model = CompensationDocument diff --git a/ema/templates/ema/detail/includes/actions.html b/ema/templates/ema/detail/includes/actions.html index 74f0564a..30e5e527 100644 --- a/ema/templates/ema/detail/includes/actions.html +++ b/ema/templates/ema/detail/includes/actions.html @@ -58,9 +58,12 @@ {{ action.comment }} - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/ema/urls.py b/ema/urls.py index 4008a69c..3e7092c6 100644 --- a/ema/urls.py +++ b/ema/urls.py @@ -19,11 +19,15 @@ urlpatterns = [ path('/remove', remove_view, name='remove'), path('/record', record_view, name='record'), path('/report', report_view, name='report'), + path('/state/new', state_new_view, name='new-state'), - path('/action/new', action_new_view, name='new-action'), path('/state//remove', state_remove_view, name='state-remove'), path('/state//edit', state_edit_view, name='state-edit'), + + path('/action/new', action_new_view, name='new-action'), + path('/action//edit', action_edit_view, name='action-edit'), path('/action//remove', action_remove_view, name='action-remove'), + path('/deadline//remove', deadline_remove_view, name='deadline-remove'), path('/deadline/new', deadline_new_view, name="new-deadline"), path('/share/', share_view, name='share'), diff --git a/ema/views.py b/ema/views.py index bc54631c..607d58df 100644 --- a/ema/views.py +++ b/ema/views.py @@ -7,7 +7,8 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \ - RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, EditCompensationStateModalForm + RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, EditCompensationStateModalForm, \ + EditCompensationActionModalForm from compensation.models import CompensationAction, CompensationState from ema.forms import NewEmaForm, EditEmaForm, NewEmaDocumentModalForm from ema.tables import EmaTable @@ -24,7 +25,8 @@ from konova.utils.documents import get_document, remove_document from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, \ - COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED + COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, \ + COMPENSATION_ACTION_EDITED from konova.utils.user_checks import in_group @@ -322,6 +324,30 @@ def action_new_view(request: HttpRequest, id: str): ) +@login_required +@conservation_office_group_required +@shared_access_required(Ema, "id") +def action_edit_view(request: HttpRequest, id: str, action_id: str): + """ Renders a form for editing an actions for an EMA + + Args: + request (HttpRequest): The incoming request + id (str): The EMA's id + action_id (str): The action id + + Returns: + + """ + ema = get_object_or_404(Ema, id=id) + action = get_object_or_404(CompensationAction, id=action_id) + form = EditCompensationActionModalForm(request.POST or None, instance=ema, action=action, request=request) + return form.process_request( + request, + msg_success=COMPENSATION_ACTION_EDITED, + redirect_url=reverse("ema:detail", args=(id,)) + "#related_data" + ) + + @login_required @conservation_office_group_required @shared_access_required(Ema, "id")