Compare commits

..

No commits in common. "2889b10e0da6ba8980af3dfc67bf0d9ac17f860d" and "8885f8177011f812139e6556fa9b177dceaad86b" have entirely different histories.

17 changed files with 105 additions and 334 deletions

View File

@ -41,9 +41,7 @@ class PaymentAdmin(admin.ModelAdmin):
list_display = [
"id",
"amount",
"due_on",
"created_by",
"created_on",
"due_on"
]

View File

@ -5,62 +5,10 @@ Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 04.12.20
"""
from django import forms
from django.db import transaction
from django.utils.translation import gettext_lazy as _
from compensation.models import Payment
from konova.forms import BaseForm, BaseModalForm
from konova.forms import BaseForm
class NewCompensationForm(BaseForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class NewPaymentForm(BaseModalForm):
amount = forms.DecimalField(
min_value=0.00,
decimal_places=2,
label=_("Amount"),
label_suffix=_(""),
help_text=_("Amount in Euro"),
localize=True,
)
due = forms.DateField(
label=_("Due on"),
label_suffix=_(""),
help_text=_("Due on which date"),
widget=forms.DateInput(
attrs={
"type": "date",
"data-provide": "datepicker",
},
format="%d.%m.%Y"
)
)
transfer_note = forms.CharField(
max_length=1000,
required=False,
label_suffix=_(""),
label=_("Transfer note"),
help_text=_("Note for money transfer")
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.intervention = self.instance
self.form_title = _("Payment")
self.form_caption = _("Add a payment for intervention '{}'").format(self.intervention.title)
def save(self):
with transaction.atomic():
pay = Payment.objects.create(
created_by=self.user,
amount=self.cleaned_data.get("amount", -1),
due_on=self.cleaned_data.get("due", None),
comment=self.cleaned_data.get("transfer_note", None),
intervention=self.intervention,
)
return pay
super().__init__(*args, **kwargs)

View File

@ -19,10 +19,10 @@ urlpatterns = [
path('<id>/remove', remove_view, name='remove'),
# Payment
path('pay/<intervention_id>/new', new_payment_view, name='pay-new'),
path('pay/new', new_view, name='pay-new'),
path('pay/<id>', open_view, name='pay-open'),
path('pay/<id>/edit', edit_view, name='pay-edit'),
path('pay/<id>/remove', payment_remove_view, name='pay-remove'),
path('pay/<id>/remove', remove_view, name='pay-remove'),
# Eco-account
path("acc/", account_index_view, name="acc-index"),

View File

@ -1,15 +1,11 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest
from django.shortcuts import render, get_object_or_404
from django.utils.translation import gettext_lazy as _
from django.shortcuts import render
from compensation.forms import NewPaymentForm
from compensation.models import Compensation, EcoAccount, Payment
from compensation.models import Compensation, EcoAccount
from compensation.tables import CompensationTable, EcoAccountTable
from intervention.models import Intervention
from konova.contexts import BaseContext
from konova.decorators import *
from konova.forms import RemoveModalForm
@login_required
@ -112,79 +108,3 @@ def account_open_view(request: HttpRequest, id: str):
def account_remove_view(request: HttpRequest, id: str):
# ToDo
pass
@login_required
def new_payment_view(request: HttpRequest, intervention_id: str):
""" Renders a modal view for adding new payments
Args:
request (HttpRequest): The incoming request
intervention_id (str): The intervention's id for which a new payment shall be added
Returns:
"""
template = "modal/modal_form.html"
intervention = get_object_or_404(Intervention, id=intervention_id)
form = NewPaymentForm(request.POST or None, instance=intervention, user=request.user)
if request.method == "POST":
if form.is_valid():
payment = form.save()
messages.success(
request,
_("Payment added")
)
return redirect(request.META.get("HTTP_REFERER", "home"))
else:
messages.info(
request,
_("There was an error on this form.")
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":
context = {
"form": form,
}
context = BaseContext(request, context).context
return render(request, template, context)
else:
raise NotImplementedError
@login_required
def payment_remove_view(request: HttpRequest, id: str):
""" Renders a modal view for adding new payments
Args:
request (HttpRequest): The incoming request
id (str): The payment's id
Returns:
"""
template = "modal/modal_form.html"
payment = get_object_or_404(Payment, id=id)
form = RemoveModalForm(request.POST or None, instance=payment, user=request.user)
if request.method == "POST":
if form.is_valid():
form.save()
messages.success(
request,
_("Payment removed")
)
return redirect(request.META.get("HTTP_REFERER", "home"))
else:
messages.info(
request,
_("There was an error on this form.")
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":
context = {
"form": form,
}
context = BaseContext(request, context).context
return render(request, template, context)
else:
raise NotImplementedError

View File

@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load i18n l10n static fontawesome_5 humanize %}
{% load i18n static fontawesome_5 %}
{% block head %}
@ -129,7 +129,7 @@
<tr>
<th scope="row">{% trans 'Last modified' %}</th>
<td class="align-middle">
{{intervention.created_on|default_if_none:""|naturalday}}
{{intervention.created_on|default_if_none:""}}
<br>
{% trans 'by' %}
{{intervention.created_by|default_if_none:""}}
@ -171,7 +171,7 @@
</div>
</div>
</div>
<div class="card-body scroll-300">
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
@ -211,30 +211,26 @@
</div>
<div class="col-sm-6">
<div class="d-flex justify-content-end">
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:pay-new' intervention.id %}" title="{% trans 'Add new payment' %}">
{% fa5_icon 'plus' %}
{% fa5_icon 'money-bill-wave' %}
</button>
<a href="{% url 'compensation:pay-new' %}" title="{% trans 'Add new payment' %}">
<button class="btn btn-outline-default">
{% fa5_icon 'plus' %}
{% fa5_icon 'money-bill-wave' %}
</button>
</a>
</div>
</div>
</div>
</div>
<div class="card-body scroll-300">
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">
{% trans 'Amount' %}
</th>
<th scope="col">
{% trans 'Due on' %}
</th>
<th scope="col">
{% trans 'Transfer comment' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
</tr>
</thead>
<tbody>
@ -242,16 +238,10 @@
<tr>
<td class="align-middle">
<a href="{% url 'compensation:pay-open' pay.id %}">
{{ pay.amount|floatformat:2 }}
{{ pay.amount }}
</a>
</td>
<td class="align-middle">{{ pay.due_on }}</td>
<td class="align-middle">{{ pay.comment }}</td>
<td>
<button data-form-url="{% url 'compensation:pay-remove' pay.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove payment' %}">
{% fa5_icon 'trash' %}
</button>
</td>
</tr>
{% endfor %}
</tbody>
@ -274,7 +264,7 @@
<div class="col-sm-6">
<div class="d-flex justify-content-end">
<a href="{% url 'doc-new' %}" title="{% trans 'Add new document' %}">
<button class="btn btn-outline-default ">
<button class="btn btn-outline-default">
{% fa5_icon 'plus' %}
{% fa5_icon 'file' %}
</button>
@ -283,7 +273,7 @@
</div>
</div>
</div>
<div class="card-body scroll-300">
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
@ -308,7 +298,7 @@
</td>
<td class="align-middle">{{ doc.comment }}</td>
<td>
<button data-form-url="{% url 'doc-remove' doc.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove document' %}">
<button data-form-url="{% url 'doc-remove' doc.id %}" class="btn btn-default del-btn" title="{% trans 'Remove document' %}">
{% fa5_icon 'trash' %}
</button>
</td>
@ -321,7 +311,7 @@
</div>
</div>
{% with 'btn-modal' as btn_class %}
{% with 'del-btn' as btn_class %}
{% include 'modal/modal_form_script.html' %}
{% endwith %}

View File

@ -4,7 +4,7 @@ from django.utils.translation import gettext_lazy as _
from django.http import HttpRequest
from django.shortcuts import render, get_object_or_404
from intervention.forms import NewInterventionForm, EditInterventionForm
from intervention.forms import NewInterventionForm, EditInterventionForm, OpenInterventionForm
from intervention.models import Intervention
from intervention.tables import InterventionTable
from konova.contexts import BaseContext

View File

@ -8,11 +8,12 @@ Created on: 16.11.20
from abc import abstractmethod
from bootstrap_modal_forms.forms import BSModalForm
from bootstrap_modal_forms.forms import BSModalModelForm, BSModalForm
from django import forms
from django.contrib.auth.models import User
from django.contrib.gis.forms import GeometryField, OSMWidget
from django.contrib.gis.geos import Polygon
from django.urls import reverse
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
@ -29,7 +30,6 @@ class BaseForm(forms.Form):
def __init__(self, *args, **kwargs):
self.instance = kwargs.pop("instance", None)
self.user = kwargs.pop("user", None)
super().__init__(*args, **kwargs)
@abstractmethod
@ -99,13 +99,6 @@ class RemoveForm(BaseForm):
return self.object_to_remove
class BaseModalForm(BaseForm, BSModalForm):
""" A specialzed form class for modal form handling
"""
is_modal_form = True
class SimpleGeomForm(BaseForm):
""" A geometry form for rendering geometry read-only using a widget
@ -138,35 +131,7 @@ class SimpleGeomForm(BaseForm):
self.area = geom.area
class RemoveModalForm(BaseModalForm):
""" Generic removing modal form
Can be used for anything, where removing shall be confirmed by the user a second time.
"""
confirm = forms.BooleanField(
label=_("Confirm"),
label_suffix=_(""),
widget=forms.CheckboxInput(),
required=True,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_title = _("Remove")
self.form_caption = _("Are you sure?")
def save(self):
if hasattr(self.instance, "deleted_on"):
self.instance.deleted_on = timezone.now()
self.instance.deleted_by = self.user
self.instance.save()
else:
# If the class does not provide restorable delete functionality, we must delete the entry finally
self.instance.delete()
class RemoveDocumentForm(BaseModalForm):
class RemoveDocumentForm(BaseForm, BSModalForm):
confirm = forms.BooleanField(
label=_("Confirm"),
label_suffix=_(""),

View File

@ -168,7 +168,7 @@ a {
}
input:focus, textarea:focus, select:focus{
border-color: var(--rlp-red) !important;
border: 1px solid var(--rlp-red) !important;
box-shadow: 0 0 3px var(--rlp-red) !important;
-moz-box-shadow: 0 0 3px var(--rlp-red) !important;
-webkit-box-shadow: 0 0 3px var(--rlp-red) !important;
@ -194,13 +194,4 @@ input:focus, textarea:focus, select:focus{
.page-item.active > .page-link{
background-color: var(--rlp-red);
border-color: var(--rlp-red);
}
.label-required{
color: var(--rlp-red);
}
.scroll-300{
max-height: 300px;
overflow: auto;
}

View File

@ -53,7 +53,6 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'django.contrib.humanize',
'simple_sso.sso_server',
'django_tables2',
'bootstrap_modal_forms',
@ -144,12 +143,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'de'
USE_THOUSAND_SEPARATOR = True
LANGUAGE_CODE = 'en-us'
DEFAULT_DATE_TIME_FORMAT = '%d.%m.%Y %H:%M:%S'
DATE_FORMAT = '%d.%m.%Y'
TIME_ZONE = 'Europe/Berlin'

View File

@ -3,6 +3,6 @@
{% block body %}
<div class="column">
{% include 'table/generic_table_form.html' %}
{% include 'generic_table_form.html' %}
</div>
{% endblock %}

Binary file not shown.

View File

@ -3,16 +3,15 @@
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#: compensation/forms.py:26 compensation/forms.py:32 compensation/forms.py:45
#: intervention/filters.py:25 intervention/filters.py:31
#: intervention/filters.py:38 intervention/filters.py:39 konova/forms.py:73
#: konova/forms.py:149 konova/forms.py:172 user/forms.py:38
#: konova/forms.py:137 user/forms.py:38
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-07-26 10:44+0200\n"
"POT-Creation-Date: 2021-07-23 18:26+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -22,39 +21,6 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: compensation/forms.py:25
#: intervention/templates/intervention/detail-view.html:227
msgid "Amount"
msgstr "Betrag"
#: compensation/forms.py:27
msgid "Amount in Euro"
msgstr "Betrag in Euro"
#: compensation/forms.py:31
msgid "Due on"
msgstr "Fällig am"
#: compensation/forms.py:33
msgid "Due on which date"
msgstr "Zahlung wird an diesem Datum erwartet"
#: compensation/forms.py:46
msgid "Transfer note"
msgstr "Verwendungszweck"
#: compensation/forms.py:47
msgid "Note for money transfer"
msgstr "Verwendungszweck für Überweisung"
#: compensation/forms.py:55
msgid "Payment"
msgstr "Zahlung"
#: compensation/forms.py:56
msgid "Add a payment for intervention '{}'"
msgstr "Neue Ersatzzahlung zu Eingriff '{}' hinzufügen"
#: compensation/tables.py:18 compensation/tables.py:71 intervention/forms.py:26
#: intervention/tables.py:23
#: intervention/templates/intervention/detail-view.html:179
@ -65,7 +31,7 @@ msgstr "Kennung"
#: intervention/tables.py:28
#: intervention/templates/intervention/detail-view.html:62
#: intervention/templates/intervention/detail-view.html:182
#: intervention/templates/intervention/detail-view.html:287
#: intervention/templates/intervention/detail-view.html:281
msgid "Title"
msgstr "Bezeichnung"
@ -106,18 +72,6 @@ msgstr "Lösche {}"
msgid "Eco Accounts"
msgstr "Ökokonten"
#: compensation/views.py:136
msgid "Payment added"
msgstr "Zahlung hinzugefügt"
#: compensation/views.py:142 compensation/views.py:180 konova/views.py:137
msgid "There was an error on this form."
msgstr "Es gab einen Fehler im Formular."
#: compensation/views.py:174
msgid "Payment removed"
msgstr "Zahlung gelöscht"
#: intervention/filters.py:24
msgid "Show all"
msgstr "Alle anzeigen"
@ -337,32 +291,31 @@ msgstr "Ersatzzahlungen"
msgid "Add new payment"
msgstr "Neue Zahlung hinzufügen"
#: intervention/templates/intervention/detail-view.html:230
#: intervention/templates/intervention/detail-view.html:229
msgid "Amount"
msgstr "Betrag"
#: intervention/templates/intervention/detail-view.html:232
msgid "Transfer comment"
msgstr "Verwendungszweck"
#: intervention/templates/intervention/detail-view.html:233
#: intervention/templates/intervention/detail-view.html:293
msgid "Action"
msgstr "Aktionen"
#: intervention/templates/intervention/detail-view.html:247
msgid "Remove payment"
msgstr "Zahlung entfernen"
#: intervention/templates/intervention/detail-view.html:267
#: intervention/templates/intervention/detail-view.html:261
msgid "Documents"
msgstr "Dokumente"
#: intervention/templates/intervention/detail-view.html:272
#: intervention/templates/intervention/detail-view.html:266
msgid "Add new document"
msgstr "Neues Dokument hinzufügen"
#: intervention/templates/intervention/detail-view.html:290
#: intervention/templates/intervention/detail-view.html:284
msgid "Comment"
msgstr "Kommentar"
#: intervention/templates/intervention/detail-view.html:307 konova/forms.py:180
#: intervention/templates/intervention/detail-view.html:287
msgid "Action"
msgstr "Aktionen"
#: intervention/templates/intervention/detail-view.html:301 konova/forms.py:145
msgid "Remove document"
msgstr "Dokument löschen"
@ -404,23 +357,19 @@ msgstr "Hierfür müssen Sie einer anderen Nutzergruppe angehören!"
msgid "Not editable"
msgstr "Nicht editierbar"
#: konova/forms.py:72 konova/forms.py:148 konova/forms.py:171
#: konova/forms.py:72 konova/forms.py:136
msgid "Confirm"
msgstr "Bestätige"
#: konova/forms.py:84 konova/forms.py:156
#: konova/forms.py:84
msgid "Remove"
msgstr "Löschen"
msgstr "Entferne"
#: konova/forms.py:86
msgid "You are about to remove {} {}"
msgstr "Sie sind dabei {} {} zu löschen"
#: konova/forms.py:157
msgid "Are you sure?"
msgstr ""
#: konova/forms.py:181
#: konova/forms.py:146
msgid "This will remove '{}'. Are you sure?"
msgstr "Hiermit wird '{}' gelöscht. Sind Sie sicher?"
@ -476,10 +425,14 @@ msgstr "Ökokonto"
msgid "Withdraw"
msgstr "Abbuchen"
#: konova/views.py:131
#: konova/views.py:133
msgid "Document '{}' deleted"
msgstr "Dokument '{}' gelöscht"
#: konova/views.py:139
msgid "There was an error on this form."
msgstr "Es gab einen Fehler im Formular."
#: news/templates/news/dashboard-news.html:12 news/templates/news/index.html:19
msgid "Published on"
msgstr "Veröffentlicht am"
@ -508,7 +461,19 @@ msgstr ""
msgid "Contact"
msgstr "Kontakt"
#: templates/modal/modal_form.html:24
#: templates/generic_table_form.html:37
msgid "Fields with * are required."
msgstr "* sind Pflichtfelder."
#: templates/generic_table_form.html:41
msgid "Cancel"
msgstr "Abbrechen"
#: templates/generic_table_form.html:45
msgid "Save"
msgstr "Speichern"
#: templates/modal/modal_form.html:30
msgid "Continue"
msgstr "Weiter"
@ -584,18 +549,6 @@ msgstr ""
msgid "Apply filter"
msgstr "Filter anwenden"
#: templates/table/generic_table_form.html:23
msgid "Cancel"
msgstr "Abbrechen"
#: templates/table/generic_table_form.html:27
msgid "Save"
msgstr "Speichern"
#: templates/table/generic_table_form_body.html:20
msgid "Fields with * are required."
msgstr "* sind Pflichtfelder."
#: user/forms.py:23
msgid "Notifications"
msgstr "Benachrichtigungen"
@ -1863,6 +1816,9 @@ msgstr ""
#~ msgid "Last login on"
#~ msgstr "Zuletzt eingeloggt am"
#~ msgid "Add new intervention"
#~ msgstr "Neuen Eingriff hinzufügen"
#~ msgid "Delete intervention"
#~ msgstr "Eingriff löschen"
@ -1948,6 +1904,9 @@ msgstr ""
#~ "Eingriffe müssen zu einem Vorgang gehören. Bitte geben SIe die fehlenden "
#~ "Daten für den Vorgang ein."
#~ msgid "Intervention {} removed"
#~ msgstr "Eingriff {} gelöscht"
#~ msgid "You are working as"
#~ msgstr "Sie arbeiten gerade als "

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
{% load static i18n l10n fontawesome_5 bootstrap4 %}
{% load static i18n fontawesome_5 bootstrap4 %}
<html lang="{{ language }}">
<head>
<meta charset="UTF-8">

View File

@ -16,7 +16,25 @@
{% endif %}
<form method="post" action="{{ form.action_url }}">
{% csrf_token %}
{% include 'table/generic_table_form_body.html' %}
<table class="table">
<tbody>
{% for field in form %}
<tr title="{{ field.help_text }}" class="{% if field.errors %}error{% endif %}">
<th scope="row" class="col-sm-3">
<div>{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></div>
<small>{{ field.help_text }}</small>
</th>
<td class="col-sm-9">
{{ field }}
{% for error in field.errors %}
<strong>{{ error }}</strong>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<small>{% trans 'Fields with * are required.' %}</small>
<div class="row">
<div class="col-md">
<a href="{{ form.cancel_redirect }}">

View File

@ -1,4 +1,4 @@
{% load i18n l10n %}
{% load i18n %}
{% comment %}
A generic modal form template which is based on django-bootstrap-modal-forms package
https://pypi.org/project/django-bootstrap-modal-forms/
@ -15,10 +15,16 @@
</div>
<div class="modal-body">
<article>
{{ form.form_caption }}
</article>
{% include 'table/generic_table_form_body.html' %}
<article class="mb-5">{{form.form_caption}}</article>
{% for field in form %}
<div class="form-group{% if field.errors %} invalid{% endif %}">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
{% for error in field.errors %}
<p class="help-block">{{ error }}</p>
{% endfor %}
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default">{% trans 'Continue' %}</button>

View File

@ -1,20 +0,0 @@
{% load i18n %}
<table class="table">
<tbody>
{% for field in form %}
<tr title="{{ field.help_text }}" class="{% if field.errors %}error{% endif %}">
<th scope="row" class="col-sm-3">
<div>{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></div>
<small>{{ field.help_text }}</small>
</th>
<td class="col-sm-9">
{{ field }}
{% for error in field.errors %}
<strong>{{ error }}</strong>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<small>{% trans 'Fields with * are required.' %}</small>

View File

@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% block body %}
{% include 'table/generic_table_form.html' %}
{% include 'generic_table_form.html' %}
{% endblock %}