# 86 Proper log detail

* adds support for payment adding/deleting to intervention log
* adds support for deduction adding/deleting to intervention/ecoaccount log
* improves code snippets
* drops add_deduction() methods for ecoaccount and intervention in favor of simpler creation in NewDeductionModalForm
* adds messages
* adds/updates translations
This commit is contained in:
2022-02-02 15:16:25 +01:00
parent f224bbb5bd
commit a9215511ac
17 changed files with 289 additions and 266 deletions

View File

@@ -326,7 +326,7 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
Returns:
"""
self.intervention.mark_as_edited(user, request, edit_comment, reset_recorded)
return self.intervention.mark_as_edited(user, request, edit_comment, reset_recorded)
def is_ready_for_publish(self) -> bool:
""" Not inherited by RecordableObjectMixin

View File

@@ -9,10 +9,10 @@ import shutil
from django.urls import reverse
from user.models import User
from konova.utils.message_templates import DEDUCTION_REMOVED
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
from django.db import models, transaction
from django.db import models
from django.db.models import Sum, QuerySet
from django.utils.translation import gettext_lazy as _
@@ -22,7 +22,6 @@ from compensation.utils.quality import EcoAccountQualityChecker
from konova.models import ShareableObjectMixin, RecordableObjectMixin, AbstractDocument, BaseResource, \
generate_document_file_upload_path
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from user.models import UserActionLogEntry
class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin):
@@ -167,34 +166,6 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
)
return docs
def add_deduction(self, form):
""" Adds a new deduction to the intervention
Args:
form (NewDeductionModalForm): The form holding the data
Returns:
"""
form_data = form.cleaned_data
user = form.user
with transaction.atomic():
# Create log entry
user_action_create = UserActionLogEntry.get_created_action(user)
user_action_edit = UserActionLogEntry.get_edited_action(user)
self.log.add(user_action_edit)
self.modified = user_action_edit
self.save()
deduction = EcoAccountDeduction.objects.create(
intervention=form_data["intervention"],
account=self,
surface=form_data["surface"],
created=user_action_create,
)
return deduction
def is_ready_for_publish(self) -> bool:
""" Checks whether the data passes all constraints for being publishable
@@ -295,3 +266,9 @@ class EcoAccountDeduction(BaseResource):
def __str__(self):
return "{} of {}".format(self.surface, self.account)
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)
super().delete(*args, **kwargs)

View File

@@ -10,6 +10,8 @@ from django.db import models
from intervention.models import Intervention
from konova.models import BaseResource
from konova.utils.message_templates import PAYMENT_REMOVED
from user.models import UserActionLogEntry
class Payment(BaseResource):
@@ -35,3 +37,8 @@ class Payment(BaseResource):
ordering = [
"-amount",
]
def delete(self, user=None, *args, **kwargs):
if user is not None:
self.intervention.mark_as_edited(user, edit_comment=PAYMENT_REMOVED)
super().delete(*args, **kwargs)