Refactoring #43

Merged
mpeltriaux merged 13 commits from Refactoring into master 2021-11-16 14:24:11 +01:00
2 changed files with 28 additions and 30 deletions
Showing only changes of commit 8e1c4446dd - Show all commits

View File

@ -101,6 +101,34 @@ class AbstractCompensation(BaseObject):
self.actions.add(comp_action) self.actions.add(comp_action)
return comp_action return comp_action
def add_state(self, form, is_before_state: bool) -> CompensationState:
""" Adds a new compensation state to the compensation
Args:
form (NewStateModalForm): The form, holding all relevant data
is_before_state (bool): Whether this is a new before_state or after_state
Returns:
"""
form_data = form.cleaned_data
user = form.user
with transaction.atomic():
user_action = UserActionLogEntry.get_edited_action(user, _("Added state"))
self.log.add(user_action)
self.modified = user_action
self.save()
state = CompensationState.objects.create(
biotope_type=form_data["biotope_type"],
surface=form_data["surface"],
)
if is_before_state:
self.before_states.add(state)
else:
self.after_states.add(state)
return state
def get_surface_after_states(self) -> float: def get_surface_after_states(self) -> float:
""" Calculates the compensation's/account's surface """ Calculates the compensation's/account's surface
@ -243,35 +271,6 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
) )
return docs return docs
def add_state(self, form, is_before_state: bool) -> CompensationState:
""" Adds a new compensation state to the compensation
Args:
form (NewStateModalForm): The form, holding all relevant data
is_before_state (bool): Whether this is a new before_state or after_state
Returns:
"""
form_data = form.cleaned_data
user = form.user
with transaction.atomic():
user_action = UserActionLogEntry.get_edited_action(user, _("Added state"))
self.log.add(user_action)
self.modified = user_action
self.save()
state = CompensationState.objects.create(
biotope_type=form_data["biotope_type"],
surface=form_data["surface"],
)
if is_before_state:
self.before_states.add(state)
else:
self.after_states.add(state)
return state
class CompensationDocument(AbstractDocument): class CompensationDocument(AbstractDocument):
""" """
Specializes document upload for revocations with certain path Specializes document upload for revocations with certain path

View File

@ -35,4 +35,3 @@ class Payment(BaseResource):
ordering = [ ordering = [
"-amount", "-amount",
] ]