diff --git a/accounting/views.py b/accounting/views.py index 5b92699..b84e68d 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -34,7 +34,8 @@ from django.views.generic import RedirectView from mia_core.digest_auth import login_required from mia_core.period import Period from mia_core.status import success_redirect, error_redirect -from mia_core.utils import Pagination, get_multi_lingual_search, UrlBuilder +from mia_core.utils import Pagination, get_multi_lingual_search, UrlBuilder, \ + strip_form from .models import Record, Transaction, Account, RecordSummary from .utils import ReportUrl, get_cash_accounts, get_ledger_accounts, \ find_imbalanced, find_order_holes, fill_transaction_from_form, \ @@ -848,6 +849,7 @@ def transaction_store(request, txn_type, transaction=None): if transaction is None: transaction = Transaction() form = request.POST.dict() + strip_form(form) sort_form_transaction_records(form) fill_transaction_from_form(transaction, form) errors = {} diff --git a/mia_core/utils.py b/mia_core/utils.py index 3551535..eaa32d5 100644 --- a/mia_core/utils.py +++ b/mia_core/utils.py @@ -43,6 +43,16 @@ def new_pk(cls): return id +def strip_form(form): + """Strips the values of a form. Empty strings are converted to None. + + Args: + form (dict[str]): The form. + """ + for key in form.keys(): + form[key] = form[key].strip() + + class Language: """A language.