Payment date and comment #3
* adds payment-comment relation in NewPaymentForm * drops transfer note form field (may not be used anyway) and replace it with comment * adds/updates translations
This commit is contained in:
@@ -60,12 +60,18 @@ class NewPaymentForm(BaseModalForm):
|
||||
format="%d.%m.%Y"
|
||||
)
|
||||
)
|
||||
transfer_note = forms.CharField(
|
||||
comment = forms.CharField(
|
||||
max_length=200,
|
||||
required=False,
|
||||
label=_("Comment"),
|
||||
label_suffix=_(""),
|
||||
label=_("Transfer note"),
|
||||
help_text=_("Note for money transfer")
|
||||
help_text=_("Additional comment, maximum {} letters").format(200),
|
||||
widget=forms.Textarea(
|
||||
attrs={
|
||||
"rows": 5,
|
||||
"class": "w-100"
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -75,6 +81,29 @@ class NewPaymentForm(BaseModalForm):
|
||||
self.form_caption = _("Add a payment for intervention '{}'").format(self.intervention.title)
|
||||
self.add_placeholder_for_field("amount", "0,00")
|
||||
|
||||
def is_valid(self):
|
||||
"""
|
||||
Checks on form validity.
|
||||
|
||||
For this form we need to make sure that a date or a comment is set.
|
||||
If both are missing, the user needs to enter at least an explanation why
|
||||
there is no date to be entered.
|
||||
|
||||
Returns:
|
||||
is_valid (bool): True if valid, False otherwise
|
||||
"""
|
||||
super_valid = super().is_valid()
|
||||
date = self.cleaned_data["due"]
|
||||
comment = self.cleaned_data["comment"] or None
|
||||
if not date and not comment:
|
||||
# At least one needs to be set!
|
||||
self.add_error(
|
||||
"comment",
|
||||
_("If there is no date you can enter, please explain why.")
|
||||
)
|
||||
return False
|
||||
return super_valid
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
@@ -90,7 +119,7 @@ class NewPaymentForm(BaseModalForm):
|
||||
created=created_action,
|
||||
amount=self.cleaned_data.get("amount", -1),
|
||||
due_on=self.cleaned_data.get("due", None),
|
||||
comment=self.cleaned_data.get("transfer_note", None),
|
||||
comment=self.cleaned_data.get("comment", None),
|
||||
intervention=self.intervention,
|
||||
)
|
||||
self.intervention.log.add(edited_action)
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<td class="align-middle">
|
||||
{% trans deadline.type_humanized %}
|
||||
</td>
|
||||
<td class="align-middle">{{ deadline.date }}</td>
|
||||
<td class="align-middle">{{ deadline.date|default_if_none:"---" }}</td>
|
||||
<td class="align-middle">{{ deadline.comment }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<td class="align-middle">
|
||||
{% trans deadline.type_humanized %}
|
||||
</td>
|
||||
<td class="align-middle">{{ deadline.date }}</td>
|
||||
<td class="align-middle">{{ deadline.date|default_if_none:"---" }}</td>
|
||||
<td class="align-middle">{{ deadline.comment }}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
|
||||
Reference in New Issue
Block a user