From 1786bd965b5130b1a98221d5d57dc24af4b52c5f Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Mon, 31 Jan 2022 10:14:46 +0100 Subject: [PATCH] # 89 Ecoaccount recorded state reset (fix) * fixes bug where recorded state of eco account has been reset, if a deduction is created from the detail view of the ecoaccount itself --- compensation/models/compensation.py | 6 ++++-- intervention/forms/modalForms.py | 2 +- intervention/models/intervention.py | 7 +++++-- konova/models/object.py | 7 +++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index 89d6dc2f..66035579 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -310,17 +310,19 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin): ) return docs - def mark_as_edited(self, user: User, request: HttpRequest = None, edit_comment: str = None): + def mark_as_edited(self, user: User, request: HttpRequest = None, edit_comment: str = None, reset_recorded: bool = True): """ Performs internal logic for setting the recordedd/checked state of the related intervention Args: user (User): The performing user request (HttpRequest): The performing request + edit_comment (str): Additional comment for the log entry + reset_recorded (bool): Whether the record-state of the object should be reset Returns: """ - self.intervention.mark_as_edited(user, request, edit_comment) + self.intervention.mark_as_edited(user, request, edit_comment, reset_recorded) def is_ready_for_publish(self) -> bool: """ Not inherited by RecordableObjectMixin diff --git a/intervention/forms/modalForms.py b/intervention/forms/modalForms.py index 063a912a..06997235 100644 --- a/intervention/forms/modalForms.py +++ b/intervention/forms/modalForms.py @@ -370,7 +370,7 @@ class NewDeductionModalForm(BaseModalForm): def save(self): deduction = self.instance.add_deduction(self) - self.instance.mark_as_edited(self.user, self.request) + self.instance.mark_as_edited(self.user, self.request, reset_recorded=False) return deduction diff --git a/intervention/models/intervention.py b/intervention/models/intervention.py index d1a11e40..398c00fa 100644 --- a/intervention/models/intervention.py +++ b/intervention/models/intervention.py @@ -250,17 +250,20 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec ) return deduction - def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None): + def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None, reset_recorded: bool = True): """ 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 + request (HttpRequest): The used request for this action + edit_comment (str): Additional comment for the log entry + reset_recorded (bool): Whether the record-state of the object should be reset Returns: """ - super().mark_as_edited(performing_user, request) + super().mark_as_edited(performing_user, request, edit_comment, reset_recorded) if self.checked: self.set_unchecked() diff --git a/konova/models/object.py b/konova/models/object.py index 78672b4e..723d0eb2 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -262,12 +262,15 @@ class RecordableObjectMixin(models.Model): return action - def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None): + def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None, reset_recorded: bool = True): """ 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 + request (HttpRequest): The used request for this action + edit_comment (str): Additional comment for the log entry + reset_recorded (bool): Whether the record-state of the object should be reset Returns: @@ -277,7 +280,7 @@ class RecordableObjectMixin(models.Model): self.log.add(action) self.save() - if self.recorded: + if self.recorded and reset_recorded: action = self.set_unrecorded(performing_user) self.log.add(action) if request: