diff --git a/compensation/forms/forms.py b/compensation/forms/forms.py index 95bb87d9..5959f53a 100644 --- a/compensation/forms/forms.py +++ b/compensation/forms/forms.py @@ -64,7 +64,7 @@ class AbstractCompensationForm(BaseForm): widget=autocomplete.ModelSelect2Multiple( url="codes-compensation-funding-autocomplete", attrs={ - "data-placeholder": _("Funding by..."), + "data-placeholder": _("Click for selection"), } ), ) @@ -101,7 +101,7 @@ class NewCompensationForm(AbstractCompensationForm): widget=autocomplete.ModelSelect2( url="interventions-autocomplete", attrs={ - "data-placeholder": _("Intervention"), + "data-placeholder": _("Click for selection"), "data-minimum-input-length": 3, } ), @@ -236,6 +236,7 @@ class NewEcoAccountForm(AbstractCompensationForm): widget=autocomplete.ModelSelect2( url="codes-conservation-office-autocomplete", attrs={ + "data-placeholder": _("Click for selection") } ), ) @@ -264,23 +265,10 @@ class NewEcoAccountForm(AbstractCompensationForm): } ) ) - surface = forms.DecimalField( - min_value=0.00, - decimal_places=2, - label=_("Available Surface"), - label_suffix="", - help_text=_("The amount that can be used for deductions"), - widget=forms.NumberInput( - attrs={ - "class": "form-control", - } - ) - ) field_order = [ "identifier", "title", "conservation_office", - "surface", "conservation_file_number", "handler", "fundings", @@ -307,7 +295,6 @@ class NewEcoAccountForm(AbstractCompensationForm): title = self.cleaned_data.get("title", None) fundings = self.cleaned_data.get("fundings", None) handler = self.cleaned_data.get("handler", None) - deductable_surface = self.cleaned_data.get("surface", None) conservation_office = self.cleaned_data.get("conservation_office", None) conservation_file_number = self.cleaned_data.get("conservation_file_number", None) comment = self.cleaned_data.get("comment", None) @@ -331,7 +318,7 @@ class NewEcoAccountForm(AbstractCompensationForm): identifier=identifier, title=title, responsible=responsible, - deductable_surface=deductable_surface, + deductable_surface=0.00, created=action, geometry=geometry, comment=comment, @@ -341,4 +328,94 @@ class NewEcoAccountForm(AbstractCompensationForm): # Add the log entry to the main objects log list acc.log.add(action) - return acc \ No newline at end of file + return acc + + +class EditEcoAccountForm(NewEcoAccountForm): + surface = forms.DecimalField( + min_value=0.00, + decimal_places=2, + label=_("Available Surface"), + label_suffix="", + required=False, + help_text=_("The amount that can be used for deductions"), + widget=forms.NumberInput( + attrs={ + "class": "form-control", + "placeholder": "0,00" + } + ) + ) + field_order = [ + "identifier", + "title", + "conservation_office", + "surface", + "conservation_file_number", + "handler", + "fundings", + "comment", + ] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.form_title = _("Edit Eco-Account") + + self.action_url = reverse("compensation:acc-edit", args=(self.instance.id,)) + self.cancel_redirect = reverse("compensation:acc-open", args=(self.instance.id,)) + + # Initialize form data + form_data = { + "identifier": self.instance.identifier, + "title": self.instance.title, + "surface": self.instance.deductable_surface, + "handler": self.instance.responsible.handler, + "conservation_office": self.instance.responsible.conservation_office, + "conservation_file_number": self.instance.responsible.conservation_file_number, + "fundings": self.instance.fundings.all(), + "comment": self.instance.comment, + } + disabled_fields = [] + self.load_initial_data( + form_data, + disabled_fields + ) + + def save(self, user: User, geom_form: SimpleGeomForm): + with transaction.atomic(): + # Fetch data from cleaned POST values + identifier = self.cleaned_data.get("identifier", None) + title = self.cleaned_data.get("title", None) + fundings = self.cleaned_data.get("fundings", None) + handler = self.cleaned_data.get("handler", None) + surface = self.cleaned_data.get("surface", None) + conservation_office = self.cleaned_data.get("conservation_office", None) + conservation_file_number = self.cleaned_data.get("conservation_file_number", None) + comment = self.cleaned_data.get("comment", None) + + # Create log entry + action = UserActionLogEntry.objects.create( + user=user, + action=UserAction.EDITED, + ) + # Process the geometry form + geometry = geom_form.save(action) + + # Update responsible data + self.instance.responsible.handler = handler + self.instance.responsible.conservation_office = conservation_office + self.instance.responsible.conservation_file_number = conservation_file_number + self.instance.responsible.save() + + # Update main oject data + self.instance.identifier = identifier + self.instance.title = title + self.instance.deductable_surface = surface + self.instance.geometry = geometry + self.instance.comment = comment + self.instance.save() + self.instance.fundings.set(fundings) + + # Add the log entry to the main objects log list + self.instance.log.add(action) + return self.instance diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index 1ae0ad05..2cc10643 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -36,7 +36,8 @@ class NewPaymentForm(BaseModalForm): help_text=_("in Euro"), widget=forms.NumberInput( attrs={ - "class": "form-control" + "class": "form-control", + "placeholder": "0,00", } ) ) @@ -73,7 +74,6 @@ class NewPaymentForm(BaseModalForm): self.intervention = self.instance self.form_title = _("Payment") self.form_caption = _("Add a payment for intervention '{}'").format(self.intervention.title) - self.add_placeholder_for_field("amount", "0,00") def is_valid(self): """ @@ -156,6 +156,7 @@ class NewStateModalForm(BaseModalForm): widget=forms.NumberInput( attrs={ "class": "form-control", + "placeholder": "0,00" } ) ) @@ -164,7 +165,6 @@ class NewStateModalForm(BaseModalForm): super().__init__(*args, **kwargs) self.form_title = _("New state") self.form_caption = _("Insert data for the new state") - self.add_placeholder_for_field("surface", "0,00") def save(self, is_before_state: bool = False): with transaction.atomic(): @@ -357,6 +357,7 @@ class NewActionModalForm(BaseModalForm): widget=forms.NumberInput( attrs={ "class": "form-control", + "placeholder": "0,00", } ) ) @@ -378,7 +379,6 @@ class NewActionModalForm(BaseModalForm): super().__init__(*args, **kwargs) self.form_title = _("New action") self.form_caption = _("Insert data for the new action") - self.add_placeholder_for_field("amount", "0,00") def save(self): with transaction.atomic(): diff --git a/compensation/settings.py b/compensation/settings.py index 7953f34e..2ac54646 100644 --- a/compensation/settings.py +++ b/compensation/settings.py @@ -5,8 +5,8 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 18.12.20 """ -COMPENSATION_IDENTIFIER_LENGTH = 10 +COMPENSATION_IDENTIFIER_LENGTH = 6 COMPENSATION_IDENTIFIER_TEMPLATE = "KOM-{}" -ECO_ACCOUNT_IDENTIFIER_LENGTH = 10 +ECO_ACCOUNT_IDENTIFIER_LENGTH = 6 ECO_ACCOUNT_IDENTIFIER_TEMPLATE = "OEK-{}" \ No newline at end of file diff --git a/compensation/templates/compensation/detail/compensation/includes/comment.html b/compensation/templates/compensation/detail/compensation/includes/comment.html index 4f3243b5..aff3dec8 100644 --- a/compensation/templates/compensation/detail/compensation/includes/comment.html +++ b/compensation/templates/compensation/detail/compensation/includes/comment.html @@ -3,7 +3,7 @@ {% if obj.comment %}