Refactoring
* renames model ResponsibilityData into Responsibility * renames model LegalData into Legal * moves form->object saving logic into model * refactors NewDocumentForm into special types for intervention, compensation, eco account and ema *
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from intervention.models import Intervention, ResponsibilityData, LegalData, Revocation, InterventionDocument
|
||||
from intervention.models import Intervention, Responsibility, Legal, Revocation, InterventionDocument
|
||||
from konova.admin import AbstractDocumentAdmin
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class RevocationAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
admin.site.register(Intervention, InterventionAdmin)
|
||||
admin.site.register(ResponsibilityData, ResponsibilityAdmin)
|
||||
admin.site.register(LegalData, LegalAdmin)
|
||||
admin.site.register(Responsibility, ResponsibilityAdmin)
|
||||
admin.site.register(Legal, LegalAdmin)
|
||||
admin.site.register(Revocation, RevocationAdmin)
|
||||
admin.site.register(InterventionDocument, InterventionDocumentAdmin)
|
||||
|
||||
@@ -17,7 +17,7 @@ from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_PROCESS_TYPE_ID, CODELIST_LAW_ID, \
|
||||
CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID
|
||||
from intervention.inputs import GenerateInput
|
||||
from intervention.models import Intervention, LegalData, ResponsibilityData
|
||||
from intervention.models import Intervention, Legal, Responsibility
|
||||
from konova.forms import BaseForm, SimpleGeomForm
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
@@ -220,7 +220,7 @@ class NewInterventionForm(BaseForm):
|
||||
)
|
||||
|
||||
# Create legal data object (without M2M laws first)
|
||||
legal_data = LegalData.objects.create(
|
||||
legal_data = Legal.objects.create(
|
||||
registration_date=registration_date,
|
||||
binding_date=binding_date,
|
||||
process_type=_type,
|
||||
@@ -229,7 +229,7 @@ class NewInterventionForm(BaseForm):
|
||||
legal_data.laws.set(laws)
|
||||
|
||||
# Create responsible data object
|
||||
responsibility_data = ResponsibilityData.objects.create(
|
||||
responsibility_data = Responsibility.objects.create(
|
||||
registration_office=registration_office,
|
||||
conservation_office=conservation_office,
|
||||
registration_file_number=registration_file_number,
|
||||
|
||||
@@ -14,8 +14,8 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import EcoAccount, EcoAccountDeduction
|
||||
from intervention.inputs import TextToClipboardInput
|
||||
from intervention.models import Revocation, RevocationDocument, Intervention
|
||||
from konova.forms import BaseModalForm
|
||||
from intervention.models import Revocation, RevocationDocument, Intervention, InterventionDocument
|
||||
from konova.forms import BaseModalForm, NewDocumentForm
|
||||
from konova.utils.general import format_german_float
|
||||
from konova.utils.messenger import Messenger
|
||||
from konova.utils.user_checks import is_default_group_only
|
||||
@@ -409,4 +409,8 @@ class NewDeductionModalForm(BaseModalForm):
|
||||
surface=self.cleaned_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
return deduction
|
||||
return deduction
|
||||
|
||||
|
||||
class NewInterventionDocumentForm(NewDocumentForm):
|
||||
document_model = InterventionDocument
|
||||
|
||||
@@ -9,7 +9,9 @@ import shutil
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.gis.db import models
|
||||
from django.db import transaction
|
||||
from django.db.models import QuerySet
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_REGISTRATION_OFFICE_ID, CODELIST_CONSERVATION_OFFICE_ID, CODELIST_LAW_ID, \
|
||||
@@ -19,10 +21,10 @@ from intervention.utils.quality import InterventionQualityChecker
|
||||
from konova.models import BaseObject, Geometry, UuidModel, BaseResource, AbstractDocument, \
|
||||
generate_document_file_upload_path, RecordableObject, CheckableObject, ShareableObject
|
||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT
|
||||
from user.models import UserActionLogEntry
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
|
||||
class ResponsibilityData(UuidModel):
|
||||
class Responsibility(UuidModel):
|
||||
"""
|
||||
Holds intervention data about responsible organizations and their file numbers for this case
|
||||
|
||||
@@ -68,7 +70,7 @@ class Revocation(BaseResource):
|
||||
Holds revocation data e.g. for intervention objects
|
||||
"""
|
||||
date = models.DateField(null=True, blank=True, help_text="Revocation from")
|
||||
legal = models.ForeignKey("LegalData", null=False, blank=False, on_delete=models.CASCADE, help_text="Refers to 'Widerspruch am'", related_name="revocations")
|
||||
legal = models.ForeignKey("Legal", null=False, blank=False, on_delete=models.CASCADE, help_text="Refers to 'Widerspruch am'", related_name="revocations")
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
@@ -137,7 +139,7 @@ class RevocationDocument(AbstractDocument):
|
||||
pass
|
||||
|
||||
|
||||
class LegalData(UuidModel):
|
||||
class Legal(UuidModel):
|
||||
"""
|
||||
Holds intervention legal data such as important dates, laws or responsible handler
|
||||
"""
|
||||
@@ -175,14 +177,14 @@ class Intervention(BaseObject, ShareableObject, RecordableObject, CheckableObjec
|
||||
Interventions are e.g. construction sites where nature used to be.
|
||||
"""
|
||||
responsible = models.OneToOneField(
|
||||
ResponsibilityData,
|
||||
Responsibility,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Holds data on responsible organizations ('Zulassungsbehörde', 'Eintragungsstelle')"
|
||||
)
|
||||
legal = models.OneToOneField(
|
||||
LegalData,
|
||||
Legal,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
@@ -322,6 +324,40 @@ class Intervention(BaseObject, ShareableObject, RecordableObject, CheckableObjec
|
||||
for comp in comps:
|
||||
comp.log.add(log_entry)
|
||||
|
||||
def add_payment(self, form):
|
||||
""" Adds a new payment to the intervention
|
||||
|
||||
Args:
|
||||
form (NewPaymentForm): The form holding the data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
from compensation.models import Payment
|
||||
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,
|
||||
comment=_("Added payment"),
|
||||
)
|
||||
pay = Payment.objects.create(
|
||||
created=created_action,
|
||||
amount=form_data.get("amount", -1),
|
||||
due_on=form_data.get("due", None),
|
||||
comment=form_data.get("comment", None),
|
||||
intervention=self,
|
||||
)
|
||||
self.log.add(edited_action)
|
||||
self.modified = edited_action
|
||||
self.save()
|
||||
return pay
|
||||
|
||||
|
||||
class InterventionDocument(AbstractDocument):
|
||||
"""
|
||||
|
||||
@@ -24,7 +24,7 @@ class InterventionQualityChecker(AbstractQualityChecker):
|
||||
self.valid = len(self.messages) == 0
|
||||
|
||||
def _check_responsible_data(self):
|
||||
""" Checks data quality of related ResponsibilityData
|
||||
""" Checks data quality of related Responsibility
|
||||
|
||||
Args:
|
||||
self.messages (dict): Holds error messages
|
||||
@@ -55,7 +55,7 @@ class InterventionQualityChecker(AbstractQualityChecker):
|
||||
self._add_missing_attr_name(_("Responsible data"))
|
||||
|
||||
def _check_legal_data(self):
|
||||
""" Checks data quality of related LegalData
|
||||
""" Checks data quality of related Legal
|
||||
|
||||
Args:
|
||||
self.messages (dict): Holds error messages
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.shortcuts import render
|
||||
|
||||
from intervention.forms.forms import NewInterventionForm, EditInterventionForm
|
||||
from intervention.forms.modalForms import ShareInterventionModalForm, NewRevocationModalForm, \
|
||||
CheckModalForm, NewDeductionModalForm
|
||||
CheckModalForm, NewDeductionModalForm, NewInterventionDocumentForm
|
||||
from intervention.models import Intervention, Revocation, InterventionDocument, RevocationDocument
|
||||
from intervention.tables import InterventionTable
|
||||
from konova.contexts import BaseContext
|
||||
@@ -123,7 +123,7 @@ def new_document_view(request: HttpRequest, id: str):
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = NewDocumentForm(request.POST or None, request.FILES or None, instance=intervention, user=request.user)
|
||||
form = NewInterventionDocumentForm(request.POST or None, request.FILES or None, instance=intervention, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Document added")
|
||||
|
||||
Reference in New Issue
Block a user