Implement deleting transactions

This commit is contained in:
RunasSudo 2023-01-29 19:12:28 +11:00
parent 383d43fa4a
commit 63f37fc2a1
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 13 additions and 4 deletions

View File

@ -75,6 +75,12 @@ def journal_edit_transaction():
if request.method == 'GET': if request.method == 'GET':
return render_template('journal/journal_edit_transaction.html', transaction=transaction) return render_template('journal/journal_edit_transaction.html', transaction=transaction)
if request.form.get('action', None) == 'delete':
# Delete transaction
db.session.delete(transaction)
db.session.commit()
return redirect(url_for('journal'))
# Edit transaction # Edit transaction
transaction.dt = datetime.strptime(request.form['dt'], '%Y-%m-%d') transaction.dt = datetime.strptime(request.form['dt'], '%Y-%m-%d')
transaction.description = request.form['description'] transaction.description = request.form['description']

View File

@ -16,10 +16,10 @@
#} #}
{% extends 'base.html' %} {% extends 'base.html' %}
{% block title %}{{ 'Edit' if transaction else 'New' }} transaction{% endblock %} {% block title %}{{ 'Edit' if transaction and transaction.id else 'New' }} transaction{% endblock %}
{% block content %} {% block content %}
<h1 class="h2 my-4">{{ 'Edit' if transaction else 'New' }} transaction</h1> <h1 class="h2 my-4">{{ 'Edit' if transaction and transaction.id else 'New' }} transaction</h1>
<form method="POST"> <form method="POST">
<table class="table"> <table class="table">
@ -119,8 +119,11 @@
</tbody> </tbody>
</table> </table>
<div class="d-flex justify-content-end"> <div class="d-flex">
<button type="submit" class="btn btn-primary">Save</button> {% if transaction and transaction.id %}
<button type="submit" name="action" value="delete" class="btn btn-outline-danger" onclick="confirm('Are you sure you want to delete this transaction? This operation is irreversible.')">Delete</button>
{% endif %}
<button type="submit" class="btn btn-primary ms-auto">Save</button>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}