Implement deleting transactions
This commit is contained in:
parent
383d43fa4a
commit
63f37fc2a1
@ -75,6 +75,12 @@ def journal_edit_transaction():
|
||||
if request.method == 'GET':
|
||||
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
|
||||
transaction.dt = datetime.strptime(request.form['dt'], '%Y-%m-%d')
|
||||
transaction.description = request.form['description']
|
||||
|
@ -16,10 +16,10 @@
|
||||
#}
|
||||
|
||||
{% 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 %}
|
||||
<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">
|
||||
<table class="table">
|
||||
@ -119,8 +119,11 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="d-flex justify-content-end">
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<div class="d-flex">
|
||||
{% 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>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user