Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions django/cohiva/settings_for_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Modify settings to run automated tests

import logging
import os
import warnings
from urllib.parse import quote
Expand Down Expand Up @@ -30,9 +31,12 @@
## Make code aware that this is a test run
IS_RUNNING_TESTS = True

## Disable logging for tests
logging.disable()

if os.getenv("SKIP_SLOW", "false") == "true":
## Speed up tests in quick mode
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)

Check warning on line 39 in django/cohiva/settings_for_tests.py

View workflow job for this annotation

GitHub Actions / test

Missing coverage

Missing coverage on line 39
if os.getenv("KEEP_DB", "false") == "false":
## Skip migrations and use a test runner that applies selected migrations needed for tests
DATABASES["default"]["TEST"] = {"MIGRATE": False}
Expand Down
109 changes: 67 additions & 42 deletions django/credit_accounting/forms.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import datetime

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Div, Layout
import select2.fields
from django import forms
from django.core.exceptions import ValidationError
from django.db.models import Q
from unfold.widgets import (
UnfoldAdminDecimalFieldWidget,
UnfoldAdminFileFieldWidget,
UnfoldAdminSelect2Widget,
UnfoldAdminSelectWidget,
UnfoldAdminTextInputWidget,
)

## Don't use unfold widgets yet, because first the templated have to be adapted
# from unfold.widgets import (
# UnfoldAdminDecimalFieldWidget,
# UnfoldAdminFileFieldWidget,
# UnfoldAdminSelect2Widget,
# UnfoldAdminSelectWidget,
# UnfoldAdminTextInputWidget,
# )
# from crispy_forms.helper import FormHelper
# from crispy_forms.layout import Div, Layout
from geno.models import Address, Contract

from .accounts import get_transaction_time_filter_options
Expand All @@ -32,34 +34,40 @@
search = forms.CharField(
label="Suche",
required=False,
widget=UnfoldAdminTextInputWidget(attrs={"size": "40", "autofocus": True}),
# widget=UnfoldAdminTextInputWidget(attrs={"size": "40", "autofocus": True}),
widget=forms.TextInput(attrs={"size": "40", "autofocus": True}),
)
time = forms.ChoiceField(
choices=get_transaction_time_filter_options(),
label="Zeitraum",
required=False,
widget=UnfoldAdminSelectWidget(),
# widget=UnfoldAdminSelectWidget(),
)
sign_options = [
("all", "Alle Buchungen"),
("plus", "Gutschriften"),
("minus", "Lastschriften"),
]
sign = forms.ChoiceField(
choices=sign_options, label="Typ", required=False, widget=UnfoldAdminSelectWidget()
)
amount_min = forms.DecimalField(
label="Betrag min.",
required=False,
decimal_places=2,
widget=UnfoldAdminDecimalFieldWidget(),
)
amount_max = forms.DecimalField(
label="Betrag max.",
required=False,
decimal_places=2,
widget=UnfoldAdminDecimalFieldWidget(),
choices=sign_options,
label="Typ",
required=False, # widget=UnfoldAdminSelectWidget()
)
amount_min = forms.FloatField(label="Betrag min.", required=False)
amount_max = forms.FloatField(label="Betrag max.", required=False)
## TODO: DecimalField does not work yet because it is not JSON serializable in the session
# amount_min = forms.DecimalField(
# label="Betrag min.",
# required=False,
# decimal_places=2,
# # widget=UnfoldAdminDecimalFieldWidget(),
# )
# amount_max = forms.DecimalField(
# label="Betrag max.",
# required=False,
# decimal_places=2,
# # widget=UnfoldAdminDecimalFieldWidget(),
# )

def __init__(self, *args, **kwargs):
accounts = kwargs.pop("accounts", [])
Expand All @@ -68,28 +76,30 @@
account_options = [(account.id, str(account)) for account in accounts]
if admin:
account_options.append(("_all_", "== ALLE =="))
self.fields["account"] = forms.ChoiceField(
choices=account_options, label="Konto", widget=UnfoldAdminSelect2Widget()
)
self.fields["account"] = select2.fields.ChoiceField(choices=account_options, label="Konto")
self.fields["account"].widget.choices = iter(account_options)
# self.fields["account"] = forms.ChoiceField(
# choices=account_options, label="Konto", widget=UnfoldAdminSelect2Widget()
# )


class TransactionUploadForm(forms.Form):
file = forms.FileField(
label="Zahlungsdatei",
required=False,
widget=UnfoldAdminFileFieldWidget(),
help_text="camt.053 oder camt.054 (XML) oder ZIP-Datei mit mehreren XML-Dateien",
# widget=UnfoldAdminFileFieldWidget(),
# help_text="camt.053 oder camt.054 (XML) oder ZIP-Datei mit mehreren XML-Dateien",
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Add Crispy Forms helper for Unfold styling
self.helper = FormHelper()
self.helper.form_tag = False # Form tag handled in template
self.helper.form_class = ""
self.helper.layout = Layout(
Div("file", css_class="mb-4"),
)
# self.helper = FormHelper()
# self.helper.form_tag = False # Form tag handled in template
# self.helper.form_class = ""
# self.helper.layout = Layout(
# Div("file", css_class="mb-4"),
# )


class AccountEditForm(forms.ModelForm):
Expand All @@ -104,15 +114,19 @@
Contract.objects.filter(Q(date_end=None) | Q(date_end__gt=datetime.date.today())),
key=str,
):
owner_options.append(("c_%s" % c.id, str(c)))

Check warning on line 117 in django/credit_accounting/forms.py

View workflow job for this annotation

GitHub Actions / test

Missing coverage

Missing coverage on line 117
for a in Address.objects.filter(active=True).exclude(user=None):
owner_options.append(("a_%s" % a.id, str(a)))
self.fields["owner"] = forms.ChoiceField(
choices=owner_options, label="Verknüpft mit", widget=UnfoldAdminSelect2Widget()
self.fields["owner"] = select2.fields.ChoiceField(
choices=owner_options, label="Verknüpft mit"
)
self.fields["owner"].widget.choices = iter(owner_options)
# self.fields["owner"] = forms.ChoiceField(
# choices=owner_options, label="Verknüpft mit", widget=UnfoldAdminSelect2Widget()
# )

def clean(self):
cleaned_data = super().clean()

Check warning on line 129 in django/credit_accounting/forms.py

View workflow job for this annotation

GitHub Actions / test

Missing coverage

Missing coverage on line 129
if not self.is_update:
if (
Account.objects.filter(pin=cleaned_data.get("pin"))
Expand All @@ -133,17 +147,24 @@
search = forms.CharField(
label="Suche",
required=False,
widget=UnfoldAdminTextInputWidget(attrs={"size": "40", "autofocus": True}),
# widget=UnfoldAdminTextInputWidget(attrs={"size": "40", "autofocus": True}),
widget=forms.TextInput(attrs={"size": "40", "autofocus": True}),
)


class RevenueReportForm(forms.Form):
start_date = forms.DateField(
label="Start Datum", widget=UnfoldAdminTextInputWidget(attrs={"class": "datepicker"})
label="Start Datum",
widget=forms.TextInput(
attrs={"class": "datepicker"},
),
# widget=UnfoldAdminTextInputWidget(attrs={"class": "datepicker"}
)
start_time = forms.TimeField(label="Start Zeit")
end_date = forms.DateField(
label="End Datum", widget=UnfoldAdminTextInputWidget(attrs={"class": "datepicker"})
label="End Datum",
widget=forms.TextInput(attrs={"class": "datepicker"}),
# widget=UnfoldAdminTextInputWidget(attrs={"class": "datepicker"})
)
end_time = forms.TimeField(label="Start Zeit")

Expand All @@ -152,6 +173,10 @@
period_options = [("all_years", "Alle Jahre"), ("manual", "Manuelle Eingabe")]
for year in range(start_year, datetime.datetime.now().year + 1):
period_options.insert(0, (f"year_{year}", f"Jahr {year}"))
self.fields["period"] = forms.ChoiceField(
choices=period_options, label="Zeitraum", widget=UnfoldAdminSelect2Widget()
# self.fields["period"] = forms.ChoiceField(
# choices=period_options, label="Zeitraum", widget=UnfoldAdminSelect2Widget()
# )
self.fields["period"] = select2.fields.ChoiceField(
choices=period_options, label="Zeitraum"
)
self.fields["period"].widget.choices = iter(period_options)
2 changes: 0 additions & 2 deletions django/credit_accounting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@
return form

def post(self, request, *args, **kwargs):
form = self.get_form()
print(request.POST.get("date", "KEIN DATUM"))
print(form.errors)
if form.is_valid():
self.object = form.save()
self.object.name = "Manuelle Buchung"

Check warning on line 120 in django/credit_accounting/views.py

View workflow job for this annotation

GitHub Actions / test

Missing coverage

Missing coverage on lines 117-120
self.object.user = self.user
self.object.save()
logger.info(
Expand Down
19 changes: 19 additions & 0 deletions django/geno/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,25 @@ def __init__(self, *args, **kwargs):
)


class TransactionUploadForm(forms.Form):
file = forms.FileField(
label="Zahlungsdatei",
required=False,
widget=UnfoldAdminFileFieldWidget(),
help_text="camt.053 oder camt.054 (XML) oder ZIP-Datei mit mehreren XML-Dateien",
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Add Crispy Forms helper for Unfold styling
self.helper = FormHelper()
self.helper.form_tag = False # Form tag handled in template
self.helper.form_class = ""
self.helper.layout = Layout(
Div("file", css_class="mb-4"),
)


class TransactionUploadFileForm(forms.Form):
file = forms.FileField(required=False)

Expand Down
2 changes: 1 addition & 1 deletion django/geno/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from requests_oauthlib import OAuth2Session
from stdnum.ch import esr

from credit_accounting.forms import TransactionUploadForm
from finance.accounting import Account, AccountingManager, AccountKey

if hasattr(settings, "SHARE_PLOT") and settings.SHARE_PLOT:
Expand Down Expand Up @@ -86,6 +85,7 @@
ShareStatementForm,
TransactionForm,
TransactionFormInvoice,
TransactionUploadForm,
TransactionUploadProcessForm,
WebstampForm,
process_registration_forms,
Expand Down
Loading