Moved the dummy record creation of the new transaction forms from the view to the templates, reducing the complexity of the control logic in the view in the accounting application.

This commit is contained in:
依瑪貓 2020-08-12 21:14:51 +08:00
parent 0996fa59f8
commit 94243b676a
4 changed files with 16 additions and 2 deletions

View File

@ -76,6 +76,10 @@ First written: 2020/7/23
{% with record_type="debit" no=forloop.counter order=forloop.counter %}
{% include "accounting/include/record_form-non-transfer.html" %}
{% endwith %}
{% empty %}
{% with record_type="debit" no=1 order=1 %}
{% include "accounting/include/record_form-non-transfer.html" %}
{% endwith %}
{% endfor %}
</ul>
<ul class="list-group">

View File

@ -75,6 +75,10 @@ First written: 2020/7/23
{% with record_type="credit" no=forloop.counter order=forloop.counter %}
{% include "accounting/include/record_form-non-transfer.html" %}
{% endwith %}
{% empty %}
{% with record_type="credit" no=1 order=1 %}
{% include "accounting/include/record_form-non-transfer.html" %}
{% endwith %}
{% endfor %}
</ul>
<ul class="list-group">

View File

@ -77,6 +77,10 @@ First written: 2020/7/23
{% with record_type="debit" no=forloop.counter order=forloop.counter %}
{% include "accounting/include/record_form-transfer.html" %}
{% endwith %}
{% empty %}
{% with record_type="debit" no=1 order=1 %}
{% include "accounting/include/record_form-transfer.html" %}
{% endwith %}
{% endfor %}
</ul>
<ul class="list-group">
@ -103,6 +107,10 @@ First written: 2020/7/23
{% with record_type="credit" no=forloop.counter order=forloop.counter %}
{% include "accounting/include/record_form-transfer.html" %}
{% endwith %}
{% empty %}
{% with record_type="credit" no=1 order=1 %}
{% include "accounting/include/record_form-transfer.html" %}
{% endwith %}
{% endfor %}
</ul>
<ul class="list-group">

View File

@ -827,8 +827,6 @@ def txn_form(request, txn_type, txn=None):
form = utils.make_txn_form_from_model(txn_type, txn)
else:
form = TransactionForm()
form.debit_records.append(RecordForm())
form.credit_records.append(RecordForm())
form.transaction = txn
form.txn_type = txn_type
new_record_context = {"record": RecordForm(),