#88 Action detail codes
* adds codelist 1035 for compensation action detail codes * extends CompensationAction model * extends NewActionForm * extends detail view of compensation action related models * add/updates translations * adds autocomplete tests
This commit is contained in:
@@ -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="",
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -24,9 +24,12 @@
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<th class="w-25" scope="col">
|
||||
{% trans 'Action type' %}
|
||||
</th>
|
||||
<th class="w-25" scope="col">
|
||||
{% trans 'Action type details' %}
|
||||
</th>
|
||||
<th scope="col">
|
||||
{% trans 'Amount' context 'Compensation' %}
|
||||
</th>
|
||||
@@ -46,9 +49,14 @@
|
||||
<td class="align-middle">
|
||||
{{ action.action_type }}
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{% for detail in action.action_type_details.all %}
|
||||
<div class="mb-2" title="{{detail}}">{{detail.long_name}}</div>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="align-middle">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
||||
<td class="align-middle">{{ action.comment|default_if_none:"" }}</td>
|
||||
<td>
|
||||
<td class="align-middle">
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
|
||||
@@ -24,9 +24,12 @@
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
<th class="w-25" scope="col">
|
||||
{% trans 'Action type' %}
|
||||
</th>
|
||||
<th class="w-25" scope="col">
|
||||
{% trans 'Action type details' %}
|
||||
</th>
|
||||
<th scope="col">
|
||||
{% trans 'Amount' context 'Compensation' %}
|
||||
</th>
|
||||
@@ -46,9 +49,14 @@
|
||||
<td class="align-middle">
|
||||
{{ action.action_type }}
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{% for detail in action.action_type_details.all %}
|
||||
<div class="mb-2" title="{{detail}}">{{detail.long_name}}</div>
|
||||
{% endfor %}
|
||||
</td>
|
||||
<td class="align-middle">{{ action.amount|floatformat:2|intcomma }} {{ action.unit_humanize }}</td>
|
||||
<td class="align-middle">{{ action.comment|default_if_none:"" }}</td>
|
||||
<td>
|
||||
<td class="align-middle">
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:acc-action-remove' obj.id action.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove action' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
|
||||
Reference in New Issue
Block a user