#35 Sanity command
* refactors "toggling" of recorded/checked state * introduces mark_as_edited() for RecordableObjectMixin
This commit is contained in:
@@ -348,10 +348,7 @@ class EditInterventionForm(NewInterventionForm):
|
||||
self.instance.save()
|
||||
|
||||
# Uncheck and unrecord intervention due to changed data
|
||||
if self.instance.checked:
|
||||
self.instance.set_unchecked()
|
||||
if self.instance.recorded:
|
||||
self.instance.set_unrecorded(user)
|
||||
self.instance.mark_as_edited(user)
|
||||
|
||||
return self.instance
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ class CheckModalForm(BaseModalForm):
|
||||
|
||||
"""
|
||||
with transaction.atomic():
|
||||
self.instance.toggle_checked(self.user)
|
||||
self.instance.set_checked(self.user)
|
||||
|
||||
|
||||
class NewDeductionModalForm(BaseModalForm):
|
||||
|
||||
@@ -138,40 +138,33 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
)
|
||||
return revoc_docs, regular_docs
|
||||
|
||||
def toggle_recorded(self, user: User):
|
||||
""" Toggle the recorded state
|
||||
def set_unchecked(self):
|
||||
log_entry = super().set_unchecked()
|
||||
self.add_log_entry_to_compensations(log_entry)
|
||||
|
||||
For interventions the recorded action needs to be added to their compensation objects as well
|
||||
def set_checked(self, user: User) -> UserActionLogEntry:
|
||||
log_entry = super().set_checked(user)
|
||||
self.add_log_entry_to_compensations(log_entry)
|
||||
return log_entry
|
||||
|
||||
def set_unrecorded(self, user: User):
|
||||
log_entry = super().set_unrecorded(user)
|
||||
self.add_log_entry_to_compensations(log_entry)
|
||||
|
||||
def set_recorded(self, user: User) -> UserActionLogEntry:
|
||||
log_entry = super().set_recorded(user)
|
||||
self.add_log_entry_to_compensations(log_entry)
|
||||
return log_entry
|
||||
|
||||
def add_log_entry_to_compensations(self, log_entry: UserActionLogEntry):
|
||||
""" Adds the log entry to related compensations
|
||||
|
||||
Args:
|
||||
user (User): The performing user
|
||||
log_entry (UserActionLogEntry): The log entry
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
log_entry = super().toggle_recorded(user)
|
||||
|
||||
# Add this action to the linked compensation logs as well
|
||||
comps = self.compensations.all()
|
||||
for comp in comps:
|
||||
comp.log.add(log_entry)
|
||||
|
||||
def toggle_checked(self, user: User) -> UserActionLogEntry:
|
||||
""" Toggle the checked state
|
||||
|
||||
For interventions the checked action needs to be added to their compensation objects as well
|
||||
|
||||
Args:
|
||||
user (User): The performing user
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
log_entry = super().toggle_checked(user)
|
||||
# Leave if the log_entry is None (means "unchecked")
|
||||
if log_entry is None:
|
||||
return
|
||||
# Add this action to the linked compensation logs as well
|
||||
comps = self.compensations.all()
|
||||
for comp in comps:
|
||||
comp.log.add(log_entry)
|
||||
@@ -202,7 +195,8 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
self.log.add(edited_action)
|
||||
self.modified = edited_action
|
||||
self.save()
|
||||
return pay
|
||||
self.mark_as_edited(user)
|
||||
return pay
|
||||
|
||||
def add_revocation(self, form):
|
||||
""" Adds a new revocation to the intervention
|
||||
@@ -237,6 +231,7 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
file=form_data["file"],
|
||||
instance=revocation
|
||||
)
|
||||
self.mark_as_edited(user)
|
||||
return revocation
|
||||
|
||||
def add_deduction(self, form):
|
||||
@@ -266,8 +261,23 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
surface=form_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
self.mark_as_edited(user)
|
||||
return deduction
|
||||
|
||||
def mark_as_edited(self, performing_user: User):
|
||||
""" In case the object or a related object changed, internal processes need to be started, such as
|
||||
unrecord and uncheck
|
||||
|
||||
Args:
|
||||
performing_user (User): The user which performed the editing action
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
super().mark_as_edited(performing_user)
|
||||
if self.checked:
|
||||
self.set_unchecked()
|
||||
|
||||
|
||||
class InterventionDocument(AbstractDocument):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user