@@ -12,6 +12,7 @@ from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_DETAIL_ID
|
||||
from compensation.managers import CompensationActionManager
|
||||
from konova.models import BaseResource
|
||||
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED
|
||||
|
||||
|
||||
class UnitChoices(models.TextChoices):
|
||||
@@ -75,3 +76,13 @@ class CompensationAction(BaseResource):
|
||||
if choice[0] == self.unit:
|
||||
return choice[1]
|
||||
return None
|
||||
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
from compensation.models import Compensation
|
||||
if user:
|
||||
comps = Compensation.objects.filter(
|
||||
actions__id__in=[self.id]
|
||||
).distinct()
|
||||
for comp in comps:
|
||||
comp.mark_as_edited(user, edit_comment=COMPENSATION_ACTION_REMOVED)
|
||||
super().delete(*args, **kwargs)
|
||||
@@ -21,7 +21,7 @@ from konova.models import BaseObject, AbstractDocument, Deadline, generate_docum
|
||||
GeoReferencedMixin
|
||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \
|
||||
DOCUMENT_REMOVED_TEMPLATE
|
||||
DOCUMENT_REMOVED_TEMPLATE, COMPENSATION_EDITED_TEMPLATE
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.get_created_action(user)
|
||||
edited_action = UserActionLogEntry.get_edited_action(user, _("Added deadline"))
|
||||
|
||||
deadline = Deadline.objects.create(
|
||||
type=form_data["type"],
|
||||
@@ -70,9 +69,7 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin):
|
||||
created=created_action,
|
||||
)
|
||||
|
||||
self.modified = edited_action
|
||||
self.save()
|
||||
self.log.add(edited_action)
|
||||
self.deadlines.add(deadline)
|
||||
return deadline
|
||||
|
||||
@@ -332,7 +329,9 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.intervention.mark_as_edited(user, request, edit_comment, reset_recorded)
|
||||
self.intervention.unrecord(user, request)
|
||||
action = super().mark_as_edited(user, edit_comment)
|
||||
return action
|
||||
|
||||
def is_ready_for_publish(self) -> bool:
|
||||
""" Not inherited by RecordableObjectMixin
|
||||
|
||||
@@ -273,5 +273,5 @@ class EcoAccountDeduction(BaseResource):
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
if user is not None:
|
||||
self.intervention.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED)
|
||||
self.account.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED, reset_recorded=False)
|
||||
self.account.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED)
|
||||
super().delete(*args, **kwargs)
|
||||
@@ -6,11 +6,13 @@ Created on: 16.11.21
|
||||
|
||||
"""
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID
|
||||
from compensation.managers import CompensationStateManager
|
||||
from konova.models import UuidModel
|
||||
from konova.utils.message_templates import COMPENSATION_STATE_REMOVED
|
||||
|
||||
|
||||
class CompensationState(UuidModel):
|
||||
@@ -45,3 +47,14 @@ class CompensationState(UuidModel):
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.biotope_type} | {self.surface} m²"
|
||||
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
from compensation.models import Compensation
|
||||
if user:
|
||||
comps = Compensation.objects.filter(
|
||||
Q(before_states__id__in=[self.id]) |
|
||||
Q(after_states__id__in=[self.id])
|
||||
).distinct()
|
||||
for comp in comps:
|
||||
comp.mark_as_edited(user, edit_comment=COMPENSATION_STATE_REMOVED)
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user