Refactoring

* moves adding of revocation into Intervention model
pull/43/head
mpeltriaux 3 years ago
parent 60a50b304a
commit 9b531bc09e

@ -176,33 +176,7 @@ class NewRevocationModalForm(BaseModalForm):
}
def save(self):
with transaction.atomic():
created_action = UserActionLogEntry.objects.create(
user=self.user,
action=UserAction.CREATED
)
edited_action = UserActionLogEntry.objects.create(
user=self.user,
action=UserAction.EDITED
)
revocation = Revocation.objects.create(
date=self.cleaned_data["date"],
legal=self.instance.legal,
comment=self.cleaned_data["comment"],
created=created_action,
)
self.instance.modified = edited_action
self.instance.save()
self.instance.log.add(edited_action)
if self.cleaned_data["file"]:
RevocationDocument.objects.create(
title="revocation_of_{}".format(self.instance.identifier),
date_of_creation=self.cleaned_data["date"],
comment=self.cleaned_data["comment"],
file=self.cleaned_data["file"],
instance=revocation
)
revocation = self.instance.add_revocation(self)
return revocation

@ -15,7 +15,7 @@ from django.utils.translation import gettext_lazy as _
from intervention.managers import InterventionManager
from intervention.models.legal import Legal
from intervention.models.responsibility import Responsibility
from intervention.models.revocation import RevocationDocument
from intervention.models.revocation import RevocationDocument, Revocation
from intervention.utils.quality import InterventionQualityChecker
from konova.models import generate_document_file_upload_path, AbstractDocument, Geometry, BaseObject, ShareableObjectMixin, \
RecordableObjectMixin, CheckableObjectMixin
@ -209,6 +209,46 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
self.save()
return pay
def add_revocation(self, form):
""" Adds a new revocation to the intervention
Args:
form (NewPaymentForm): The form holding the data
Returns:
"""
form_data = form.cleaned_data
user = form.user
with transaction.atomic():
created_action = UserActionLogEntry.objects.create(
user=user,
action=UserAction.CREATED
)
edited_action = UserActionLogEntry.objects.create(
user=user,
action=UserAction.EDITED
)
revocation = Revocation.objects.create(
date=form_data["date"],
legal=self.legal,
comment=form_data["comment"],
created=created_action,
)
self.modified = edited_action
self.save()
self.log.add(edited_action)
if form_data["file"]:
RevocationDocument.objects.create(
title="revocation_of_{}".format(self.identifier),
date_of_creation=form_data["date"],
comment=form_data["comment"],
file=form_data["file"],
instance=revocation
)
return revocation
class InterventionDocument(AbstractDocument):
"""

Loading…
Cancel
Save