#112 WIP: Restructure CompensationAction
* changes action_type from ForeignKey into M2M * adds migration * changes form widget * WIP: changes rendering on detail view of compensation * TEST NOT CHECKED YET!
This commit is contained in:
@@ -405,7 +405,7 @@ class NewActionModalForm(BaseModalForm):
|
||||
|
||||
"""
|
||||
from compensation.models import UnitChoices
|
||||
action_type = forms.ModelChoiceField(
|
||||
action_type = forms.ModelMultipleChoiceField(
|
||||
label=_("Action Type"),
|
||||
label_suffix="",
|
||||
required=True,
|
||||
@@ -415,7 +415,7 @@ class NewActionModalForm(BaseModalForm):
|
||||
is_leaf=True,
|
||||
code_lists__in=[CODELIST_COMPENSATION_ACTION_ID],
|
||||
),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
widget=autocomplete.ModelSelect2Multiple(
|
||||
url="codes-compensation-action-autocomplete",
|
||||
attrs={
|
||||
"data-placeholder": _("Action"),
|
||||
@@ -496,7 +496,7 @@ class EditCompensationActionModalForm(NewActionModalForm):
|
||||
self.action = kwargs.pop("action", None)
|
||||
super().__init__(*args, **kwargs)
|
||||
form_data = {
|
||||
"action_type": self.action.action_type,
|
||||
"action_type": self.action.action_type.all(),
|
||||
"action_type_details": self.action.action_type_details.all(),
|
||||
"amount": self.action.amount,
|
||||
"unit": self.action.unit,
|
||||
@@ -506,7 +506,7 @@ class EditCompensationActionModalForm(NewActionModalForm):
|
||||
|
||||
def save(self):
|
||||
action = self.action
|
||||
action.action_type = self.cleaned_data.get("action_type", None)
|
||||
action.action_type.set(self.cleaned_data.get("action_type", []))
|
||||
action.action_type_details.set(self.cleaned_data.get("action_type_details", []))
|
||||
action.amount = self.cleaned_data.get("amount", None)
|
||||
action.unit = self.cleaned_data.get("unit", None)
|
||||
|
||||
Reference in New Issue
Block a user