Added the should_validate template variable to the transaction forms to prevent initial errors with newly-created empty forms in the accounting application.

This commit is contained in:
依瑪貓
2020-08-06 15:48:26 +08:00
parent 9a9f715349
commit ede94eb68e
6 changed files with 31 additions and 28 deletions

View File

@ -847,9 +847,11 @@ def txn_edit(request, txn_type, txn=None):
HttpResponse: The response.
"""
form = make_txn_form_from_status(request, txn_type, txn)
should_validate = True
if form is None:
if txn is None:
txn = Transaction(date=timezone.localdate())
should_validate = False
if len(txn.debit_records) == 0:
txn.records.append(Record(ord=1, is_credit=False))
if len(txn.credit_records) == 0:
@ -870,6 +872,7 @@ def txn_edit(request, txn_type, txn=None):
return render(request, F"accounting/transactions/{txn_type}/form.html", {
"item": form,
"summary_categories": get_summary_categories,
"should_validate": should_validate,
"new_record_template": new_record_template,
})