Refactoring

* moves add_state from compensation to AbstractCompensation
This commit is contained in:
mpeltriaux 2021-11-16 13:45:05 +01:00
parent 96caebcae1
commit e501512a63
2 changed files with 28 additions and 30 deletions

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",
] ]