Refactoring
* moves adding of deduction into Intervention and EcoAccount model * hardens against circular import issues
This commit is contained in:
@@ -12,6 +12,7 @@ from django.db import models, transaction
|
||||
from django.db.models import QuerySet
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import EcoAccountDeduction
|
||||
from intervention.managers import InterventionManager
|
||||
from intervention.models.legal import Legal
|
||||
from intervention.models.responsibility import Responsibility
|
||||
@@ -213,7 +214,7 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
""" Adds a new revocation to the intervention
|
||||
|
||||
Args:
|
||||
form (NewPaymentForm): The form holding the data
|
||||
form (NewRevocationModalForm): The form holding the data
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -249,6 +250,40 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
)
|
||||
return revocation
|
||||
|
||||
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_edit = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED
|
||||
)
|
||||
user_action_create = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
self.log.add(user_action_edit)
|
||||
self.modified = user_action_edit
|
||||
self.save()
|
||||
|
||||
deduction = EcoAccountDeduction.objects.create(
|
||||
intervention=self,
|
||||
account=form_data["account"],
|
||||
surface=form_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
return deduction
|
||||
|
||||
|
||||
class InterventionDocument(AbstractDocument):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user