Implement basic chart of accounts editing
This commit is contained in:
parent
f78f17c0cb
commit
7df955e5b6
@ -185,3 +185,12 @@ class TrialBalancer:
|
|||||||
# FIXME: Handle commodities
|
# FIXME: Handle commodities
|
||||||
self.accounts[destination_account].quantity += self.accounts[source_account].quantity
|
self.accounts[destination_account].quantity += self.accounts[source_account].quantity
|
||||||
del self.accounts[source_account]
|
del self.accounts[source_account]
|
||||||
|
|
||||||
|
class AccountConfiguration(db.Model):
|
||||||
|
__tablename__ = 'account_configurations'
|
||||||
|
|
||||||
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
|
account = db.Column(db.String)
|
||||||
|
kind = db.Column(db.String)
|
||||||
|
data = db.Column(db.JSON)
|
||||||
|
67
drcr/templates/chart_of_accounts.html
Normal file
67
drcr/templates/chart_of_accounts.html
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{# DrCr: Web-based double-entry bookkeeping framework
|
||||||
|
Copyright (C) 2022–2023 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 <https://www.gnu.org/licenses/>.
|
||||||
|
#}
|
||||||
|
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block title %}Chart of accounts{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1 class="h2 my-4">Chart of accounts</h1>
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<div class="d-flex mb-2">
|
||||||
|
<div class="me-2">
|
||||||
|
<select class="form-select" name="kind">
|
||||||
|
<option value="drcr.asset">Asset</option>
|
||||||
|
<option value="drcr.liability">Liability</option>
|
||||||
|
<option value="drcr.income">Income</option>
|
||||||
|
<option value="drcr.expense">Expense</option>
|
||||||
|
<option value="drcr.equity">Equity</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button type="submit" class="btn btn-primary" formaction="/chart-of-accounts/add-kind">Add kind</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Account</th>
|
||||||
|
<th>Associated types</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for account in accounts %}
|
||||||
|
<tr>
|
||||||
|
<td><input type="checkbox" name="sel-account" value="{{ account }}"></td>
|
||||||
|
<td>{{ account }}</td>
|
||||||
|
<td>
|
||||||
|
{% if account in account_configurations %}
|
||||||
|
<ul class="mb-0">
|
||||||
|
{% for account_configuration in account_configurations[account] %}
|
||||||
|
<li>{{ account_configuration.kind }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -24,6 +24,7 @@
|
|||||||
<li><a href="/journal">Journal</a></li>
|
<li><a href="/journal">Journal</a></li>
|
||||||
<li><a href="/statement-lines">Statement lines</a></li>
|
<li><a href="/statement-lines">Statement lines</a></li>
|
||||||
<li><a href="/balance-assertions">Balance assertions</a></li>
|
<li><a href="/balance-assertions">Balance assertions</a></li>
|
||||||
|
<li><a href="/chart-of-accounts">Chart of accounts</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h1 class="h2 my-4">General reports</h1>
|
<h1 class="h2 my-4">General reports</h1>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# DrCr: Web-based double-entry bookkeeping framework
|
# DrCr: Web-based double-entry bookkeeping framework
|
||||||
# Copyright (C) 2022 Lee Yingtong Li (RunasSudo)
|
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo)
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
@ -14,15 +14,39 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from flask import render_template, request
|
from flask import redirect, render_template, request
|
||||||
|
|
||||||
from .models import Amount, Balance, TrialBalancer
|
from .database import db
|
||||||
|
from .models import AccountConfiguration, Amount, Balance, Posting, TrialBalancer
|
||||||
from .webapp import all_transactions, app
|
from .webapp import all_transactions, app
|
||||||
|
|
||||||
|
from itertools import groupby
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template('index.html')
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@app.route('/chart-of-accounts')
|
||||||
|
def chart_of_accounts():
|
||||||
|
accounts = sorted(db.session.execute(db.select(Posting.account)).unique().scalars().all())
|
||||||
|
|
||||||
|
# Get existing AccountConfiguration's
|
||||||
|
account_configurations = db.session.execute(db.select(AccountConfiguration).order_by(AccountConfiguration.account)).scalars()
|
||||||
|
account_configurations = {v: list(g) for v, g in groupby(account_configurations, lambda c: c.account)}
|
||||||
|
|
||||||
|
# TODO: Handle orphans
|
||||||
|
return render_template('chart_of_accounts.html', accounts=accounts, account_configurations=account_configurations)
|
||||||
|
|
||||||
|
@app.route('/chart-of-accounts/add-kind', methods=['POST'])
|
||||||
|
def account_add_kind():
|
||||||
|
for account in request.form.getlist('sel-account'):
|
||||||
|
account_configuration = AccountConfiguration(account=account, kind=request.form['kind'])
|
||||||
|
db.session.add(account_configuration)
|
||||||
|
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return redirect('/chart-of-accounts')
|
||||||
|
|
||||||
@app.route('/general-ledger')
|
@app.route('/general-ledger')
|
||||||
def general_ledger():
|
def general_ledger():
|
||||||
return render_template(
|
return render_template(
|
||||||
|
Loading…
Reference in New Issue
Block a user