diff --git a/drcr/statements/views.py b/drcr/statements/views.py
index 301bd4c..5688d86 100644
--- a/drcr/statements/views.py
+++ b/drcr/statements/views.py
@@ -28,7 +28,7 @@ def statement_lines():
else:
statement_lines = StatementLine.query.all()
- return render_template('statement_lines.html', statement_lines=sorted(statement_lines, key=lambda l: l.dt))
+ return render_template('statements/statement_lines.html', statement_lines=sorted(statement_lines, key=lambda l: l.dt))
@app.route('/statement-lines/charge', methods=['POST'])
def statement_line_charge():
@@ -68,14 +68,14 @@ def statement_line_edit_transaction():
if request.method == 'GET':
if len(statement_line.postings) == 0:
- return render_template('statement_line_edit_transaction.html', statement_line=statement_line, transaction=None)
+ return render_template('statements/statement_line_edit_transaction.html', statement_line=statement_line, transaction=None)
if len(statement_line.postings) > 1:
# NYI
raise Exception('Cannot display a StatementLine with >2 postings')
# Get existing transaction
- return render_template('statement_line_edit_transaction.html', statement_line=statement_line, transaction=statement_line.postings[0].transaction)
+ return render_template('statements/statement_line_edit_transaction.html', statement_line=statement_line, transaction=statement_line.postings[0].transaction)
# Delete existing postings
if len(statement_line.postings) > 0:
diff --git a/drcr/templates/statement_line_edit_transaction.html b/drcr/templates/statements/statement_line_edit_transaction.html
similarity index 100%
rename from drcr/templates/statement_line_edit_transaction.html
rename to drcr/templates/statements/statement_line_edit_transaction.html
diff --git a/drcr/templates/statement_lines.html b/drcr/templates/statements/statement_lines.html
similarity index 100%
rename from drcr/templates/statement_lines.html
rename to drcr/templates/statements/statement_lines.html
diff --git a/drcr/views.py b/drcr/views.py
new file mode 100644
index 0000000..60b1072
--- /dev/null
+++ b/drcr/views.py
@@ -0,0 +1,38 @@
+# DrCr: Web-based double-entry bookkeeping framework
+# Copyright (C) 2022 Lee Yingtong Li (RunasSudo)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+from flask import render_template
+
+from .models import Amount, TrialBalancer
+from .webapp import all_transactions, app
+
+@app.route('/')
+def index():
+ return 'General journal
Statement lines
General ledger
Trial balance'
+
+@app.route('/general-ledger')
+def general_ledger():
+ return render_template('general_ledger.html', transactions=sorted(all_transactions(), key=lambda t: t.dt))
+
+@app.route('/trial-balance')
+def trial_balance():
+ balancer = TrialBalancer()
+ balancer.apply_transactions(all_transactions())
+
+ total_dr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity > 0), '$')
+ total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), '$')
+
+ return render_template('trial_balance.html', accounts=dict(sorted(balancer.accounts.items())), total_dr=total_dr, total_cr=total_cr)
diff --git a/drcr/webapp.py b/drcr/webapp.py
index 637e34d..70d22ae 100644
--- a/drcr/webapp.py
+++ b/drcr/webapp.py
@@ -14,19 +14,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-from flask import Flask, render_template
+from flask import Flask
from .database import db_session, init_db
from .general_journal.models import GeneralJournalTransaction
-from .models import Amount, TrialBalancer
from .statements.models import StatementLine, StatementLineTransaction
app = Flask(__name__)
-@app.route('/')
-def index():
- return 'General journal
Statement lines
General ledger
Trial balance'
-
def all_transactions():
return (
GeneralJournalTransaction.query.all() +
@@ -34,20 +29,7 @@ def all_transactions():
[line.into_transaction() for line in StatementLine.query.all() if len(line.postings) == 0] # TODO: Filter in SQL
)
-@app.route('/general-ledger')
-def general_ledger():
- return render_template('general_ledger.html', transactions=sorted(all_transactions(), key=lambda t: t.dt))
-
-@app.route('/trial-balance')
-def trial_balance():
- balancer = TrialBalancer()
- balancer.apply_transactions(all_transactions())
-
- total_dr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity > 0), '$')
- total_cr = Amount(sum(v.quantity for v in balancer.accounts.values() if v.quantity < 0), '$')
-
- return render_template('trial_balance.html', accounts=dict(sorted(balancer.accounts.items())), total_dr=total_dr, total_cr=total_cr)
-
+from . import views
from .general_journal import views
from .reports import views
from .statements import views