diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index 581a7b3..ef21aa3 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -20,7 +20,7 @@ from compensation.models import CompensationDocument, EcoAccountDocument from intervention.inputs import CompensationActionTreeCheckboxSelectMultiple, \ CompensationStateTreeRadioSelect from konova.contexts import BaseContext -from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm +from konova.forms.modals import BaseModalForm, NewDocumentModalForm, RemoveModalForm from konova.models import DeadlineType from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, \ ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED diff --git a/compensation/migrations/0008_auto_20220815_0803.py b/compensation/migrations/0008_auto_20220815_0803.py new file mode 100644 index 0000000..a4d6313 --- /dev/null +++ b/compensation/migrations/0008_auto_20220815_0803.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1.3 on 2022-08-15 06:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('konova', '0014_resubmission'), + ('compensation', '0007_auto_20220531_1245'), + ] + + operations = [ + migrations.AddField( + model_name='compensation', + name='resubmission', + field=models.ManyToManyField(blank=True, null=True, related_name='_compensation_resubmission_+', to='konova.Resubmission'), + ), + migrations.AddField( + model_name='ecoaccount', + name='resubmission', + field=models.ManyToManyField(blank=True, null=True, related_name='_ecoaccount_resubmission_+', to='konova.Resubmission'), + ), + ] diff --git a/compensation/migrations/0009_auto_20220815_0803.py b/compensation/migrations/0009_auto_20220815_0803.py new file mode 100644 index 0000000..a7c00e6 --- /dev/null +++ b/compensation/migrations/0009_auto_20220815_0803.py @@ -0,0 +1,32 @@ +# Generated by Django 3.1.3 on 2022-08-15 06:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('konova', '0014_resubmission'), + ('compensation', '0008_auto_20220815_0803'), + ] + + operations = [ + migrations.RemoveField( + model_name='compensation', + name='resubmission', + ), + migrations.RemoveField( + model_name='ecoaccount', + name='resubmission', + ), + migrations.AddField( + model_name='compensation', + name='resubmissions', + field=models.ManyToManyField(blank=True, null=True, related_name='_compensation_resubmissions_+', to='konova.Resubmission'), + ), + migrations.AddField( + model_name='ecoaccount', + name='resubmissions', + field=models.ManyToManyField(blank=True, null=True, related_name='_ecoaccount_resubmissions_+', to='konova.Resubmission'), + ), + ] diff --git a/compensation/migrations/0010_auto_20220815_1030.py b/compensation/migrations/0010_auto_20220815_1030.py new file mode 100644 index 0000000..2d3f16e --- /dev/null +++ b/compensation/migrations/0010_auto_20220815_1030.py @@ -0,0 +1,24 @@ +# Generated by Django 3.1.3 on 2022-08-15 08:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('konova', '0014_resubmission'), + ('compensation', '0009_auto_20220815_0803'), + ] + + operations = [ + migrations.AlterField( + model_name='compensation', + name='resubmissions', + field=models.ManyToManyField(blank=True, related_name='_compensation_resubmissions_+', to='konova.Resubmission'), + ), + migrations.AlterField( + model_name='ecoaccount', + name='resubmissions', + field=models.ManyToManyField(blank=True, related_name='_ecoaccount_resubmissions_+', to='konova.Resubmission'), + ), + ] diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index 2e42ff7..b65d259 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -14,21 +14,22 @@ from user.models import User, Team from django.db import models, transaction from django.db.models import QuerySet, Sum from django.http import HttpRequest -from django.utils.translation import gettext_lazy as _ from compensation.managers import CompensationManager from compensation.models import CompensationState, CompensationAction from compensation.utils.quality import CompensationQualityChecker from konova.models import BaseObject, AbstractDocument, Deadline, generate_document_file_upload_path, \ - GeoReferencedMixin -from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE + GeoReferencedMixin, DeadlineType, ResubmitableObjectMixin from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, COMPENSATION_REMOVED_TEMPLATE, \ - DOCUMENT_REMOVED_TEMPLATE, COMPENSATION_EDITED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \ + DOCUMENT_REMOVED_TEMPLATE, DEADLINE_REMOVED, ADDED_DEADLINE, \ COMPENSATION_ACTION_REMOVED, COMPENSATION_STATE_REMOVED, INTERVENTION_HAS_REVOCATIONS_TEMPLATE from user.models import UserActionLogEntry -class AbstractCompensation(BaseObject, GeoReferencedMixin): +class AbstractCompensation(BaseObject, + GeoReferencedMixin, + ResubmitableObjectMixin + ): """ Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation, EMA or EcoAccount. @@ -226,6 +227,15 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin): request = self.set_geometry_conflict_message(request) return request + def get_finished_deadlines(self): + """ Getter for FINISHED-deadlines + + Returns: + queryset (QuerySet): The finished deadlines + """ + return self.deadlines.filter( + type=DeadlineType.FINISHED + ) class CEFMixin(models.Model): """ Provides CEF flag as Mixin diff --git a/compensation/models/eco_account.py b/compensation/models/eco_account.py index 3d48b69..42a202f 100644 --- a/compensation/models/eco_account.py +++ b/compensation/models/eco_account.py @@ -21,6 +21,7 @@ from compensation.models.compensation import AbstractCompensation, PikMixin from compensation.utils.quality import EcoAccountQualityChecker from konova.models import ShareableObjectMixin, RecordableObjectMixin, AbstractDocument, BaseResource, \ generate_document_file_upload_path +from konova.tasks import celery_send_mail_deduction_changed, celery_send_mail_deduction_changed_team class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin, PikMixin): @@ -161,6 +162,25 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix """ return reverse("compensation:acc:share", args=(self.id, self.access_token)) + def send_notification_mail_on_deduction_change(self, data_change: dict): + """ Sends notification mails for changes on the deduction + + Args: + data_change (): + + Returns: + + """ + # Send mail + shared_users = self.shared_users.values_list("id", flat=True) + for user_id in shared_users: + celery_send_mail_deduction_changed.delay(self.identifier, self.title, user_id, data_change) + + # Send mail + shared_teams = self.shared_teams.values_list("id", flat=True) + for team_id in shared_teams: + celery_send_mail_deduction_changed_team.delay(self.identifier, self.title, team_id, data_change) + class EcoAccountDocument(AbstractDocument): """ @@ -251,4 +271,4 @@ class EcoAccountDeduction(BaseResource): if user is not None: self.intervention.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED) self.account.mark_as_edited(user, edit_comment=DEDUCTION_REMOVED) - super().delete(*args, **kwargs) \ No newline at end of file + super().delete(*args, **kwargs) diff --git a/compensation/templates/compensation/detail/compensation/includes/controls.html b/compensation/templates/compensation/detail/compensation/includes/controls.html index 5be0b3e..4119480 100644 --- a/compensation/templates/compensation/detail/compensation/includes/controls.html +++ b/compensation/templates/compensation/detail/compensation/includes/controls.html @@ -12,6 +12,9 @@ {% if has_access %} + {% if is_default_member %}