Fix form validation for disabled due date field
- Changed readonly to disabled for faellig_am field in auto-generated payments - Added clean method to preserve original due date for auto-generated payments - This prevents validation errors when editing auto-generated quarterly payments
This commit is contained in:
@@ -998,11 +998,22 @@ class DestinataerUnterstuetzungForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Make faellig_am read-only for automatically generated quarterly payments
|
||||
# Make faellig_am disabled for automatically generated quarterly payments
|
||||
self.is_auto_generated = False
|
||||
if self.instance and self.instance.pk and self.instance.beschreibung:
|
||||
if "Vierteljährliche Unterstützung" in self.instance.beschreibung and "(automatisch erstellt)" in self.instance.beschreibung:
|
||||
self.fields['faellig_am'].widget.attrs['readonly'] = True
|
||||
self.is_auto_generated = True
|
||||
self.fields['faellig_am'].disabled = True
|
||||
self.fields['faellig_am'].help_text = "Fälligkeitsdatum wird automatisch basierend auf Quartal berechnet"
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# For auto-generated payments, preserve the original due date
|
||||
if self.is_auto_generated and self.instance and self.instance.pk:
|
||||
cleaned_data['faellig_am'] = self.instance.faellig_am
|
||||
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class DestinataerNotizForm(forms.ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user