diff --git a/codelist/management/commands/update_codelist.py b/codelist/management/commands/update_codelist.py index aa6e45a9..85c90324 100644 --- a/codelist/management/commands/update_codelist.py +++ b/codelist/management/commands/update_codelist.py @@ -13,7 +13,8 @@ from codelist.models import KonovaCode, KonovaCodeList from codelist.settings import CODELIST_INTERVENTION_HANDLER_ID, CODELIST_CONSERVATION_OFFICE_ID, \ CODELIST_REGISTRATION_OFFICE_ID, CODELIST_BIOTOPES_ID, CODELIST_LAW_ID, CODELIST_COMPENSATION_HANDLER_ID, \ CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, \ - CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID + CODELIST_BASE_URL, CODELIST_PROCESS_TYPE_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \ + CODELIST_COMPENSATION_ACTION_DETAIL_ID from konova.management.commands.setup import BaseKonovaCommand from konova.settings import PROXIES @@ -38,6 +39,7 @@ class Command(BaseKonovaCommand): CODELIST_COMPENSATION_HANDLER_ID, CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_CLASS_ID, + CODELIST_COMPENSATION_ACTION_DETAIL_ID, CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID, CODELIST_PROCESS_TYPE_ID, ] diff --git a/codelist/settings.py b/codelist/settings.py index 012dc9b4..598a3a66 100644 --- a/codelist/settings.py +++ b/codelist/settings.py @@ -20,6 +20,7 @@ CODELIST_PROCESS_TYPE_ID = 44382 # CLVerfahrenstyp CODELIST_COMPENSATION_HANDLER_ID = 1052 # CLEingreifer CODELIST_COMPENSATION_ACTION_ID = 1026 # CLMassnahmedetail +CODELIST_COMPENSATION_ACTION_DETAIL_ID = 1035 # CLZusatzmerkmal CODELIST_COMPENSATION_ACTION_CLASS_ID = 1034 # CLMassnahmeklasse CODELIST_COMPENSATION_ADDITIONAL_TYPE_ID = 1028 # CLMassnahmetyp, CEF and stuff CODELIST_COMPENSATION_FUNDING_ID = 1049 # CLKombimassnahme diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index c70d52a3..dd9f4c70 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -14,7 +14,8 @@ from django.shortcuts import render from django.utils.translation import pgettext_lazy as _con, gettext_lazy as _ from codelist.models import KonovaCode -from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID +from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \ + CODELIST_COMPENSATION_ACTION_DETAIL_ID from compensation.models import CompensationDocument, EcoAccountDocument from konova.contexts import BaseContext from konova.forms import BaseModalForm, NewDocumentForm @@ -300,6 +301,23 @@ class NewActionModalForm(BaseModalForm): } ), ) + action_type_details = forms.ModelMultipleChoiceField( + label=_("Action Type detail"), + label_suffix="", + required=False, + help_text=_("Select the action type detail"), + queryset=KonovaCode.objects.filter( + is_archived=False, + is_leaf=True, + code_lists__in=[CODELIST_COMPENSATION_ACTION_DETAIL_ID], + ), + widget=autocomplete.ModelSelect2Multiple( + url="codes-compensation-action-detail-autocomplete", + attrs={ + "data-placeholder": _("Action Type detail"), + } + ), + ) unit = forms.ChoiceField( label=_("Unit"), label_suffix="", diff --git a/compensation/models/action.py b/compensation/models/action.py index 35d4c3f7..95fe2807 100644 --- a/compensation/models/action.py +++ b/compensation/models/action.py @@ -9,7 +9,7 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from codelist.models import KonovaCode -from codelist.settings import CODELIST_COMPENSATION_ACTION_ID +from codelist.settings import CODELIST_COMPENSATION_ACTION_ID, CODELIST_COMPENSATION_ACTION_DETAIL_ID from compensation.managers import CompensationActionManager from konova.models import BaseResource @@ -39,7 +39,18 @@ class CompensationAction(BaseResource): "code_lists__in": [CODELIST_COMPENSATION_ACTION_ID], "is_selectable": True, "is_archived": False, - } + }, + related_name='+', + ) + action_type_details = models.ManyToManyField( + KonovaCode, + blank=True, + limit_choices_to={ + "code_lists__in": [CODELIST_COMPENSATION_ACTION_DETAIL_ID], + "is_selectable": True, + "is_archived": False, + }, + related_name='+', ) amount = models.FloatField() unit = models.CharField(max_length=100, null=True, blank=True, choices=UnitChoices.choices) diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index 46ea4520..8147203f 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -95,6 +95,8 @@ class AbstractCompensation(BaseObject, GeoReferencedMixin): comment=form_data["comment"], created=user_action, ) + comp_action_details = form_data["action_type_details"] + comp_action.action_type_details.set(comp_action_details) self.actions.add(comp_action) return comp_action diff --git a/compensation/templates/compensation/detail/compensation/includes/actions.html b/compensation/templates/compensation/detail/compensation/includes/actions.html index 92cf45ff..648e777a 100644 --- a/compensation/templates/compensation/detail/compensation/includes/actions.html +++ b/compensation/templates/compensation/detail/compensation/includes/actions.html @@ -24,9 +24,12 @@ - + @@ -46,9 +49,14 @@ + -
+ {% trans 'Action type' %} + {% trans 'Action type details' %} + {% trans 'Amount' context 'Compensation' %} {{ action.action_type }} + {% for detail in action.action_type_details.all %} +
{{detail.long_name}}
+ {% endfor %} +
{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }} {{ action.comment|default_if_none:"" }} + {% if is_default_member and has_access %}