Added the limitation so that essential accounts, like cash, and the accounts in use, cannot be deleted.
This commit is contained in:
@ -157,6 +157,9 @@ def delete_account(account: Account) -> redirect:
|
||||
:return: The redirection to the account list on success, or the account
|
||||
detail on error.
|
||||
"""
|
||||
if not account.can_delete:
|
||||
flash(s(lazy_gettext("The account cannot be deleted.")), "error")
|
||||
return redirect(inherit_next(__get_detail_uri(account)))
|
||||
account.delete()
|
||||
sort_accounts_in(account.base_code, account.id)
|
||||
db.session.commit()
|
||||
|
@ -236,6 +236,16 @@ class Account(db.Model):
|
||||
return True
|
||||
return False
|
||||
|
||||
@property
|
||||
def can_delete(self) -> bool:
|
||||
"""Returns whether the account can be deleted.
|
||||
|
||||
:return: True if the account can be deleted, or False otherwise.
|
||||
"""
|
||||
if self.code in {"1111-001", "3351-001", "3353-001"}:
|
||||
return False
|
||||
return len(self.line_items) == 0
|
||||
|
||||
def delete(self) -> None:
|
||||
"""Deletes this account.
|
||||
|
||||
|
@ -41,10 +41,17 @@ First written: 2023/1/31
|
||||
<span class="d-none d-md-inline">{{ A_("Order") }}</span>
|
||||
</a>
|
||||
{% if accounting_can_edit() %}
|
||||
<button class="btn btn-danger" type="button" data-bs-toggle="modal" data-bs-target="#accounting-delete-modal">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
<span class="d-none d-md-inline">{{ A_("Delete") }}</span>
|
||||
</button>
|
||||
{% if obj.can_delete %}
|
||||
<button class="btn btn-danger" type="button" data-bs-toggle="modal" data-bs-target="#accounting-delete-modal">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
<span class="d-none d-md-inline">{{ A_("Delete") }}</span>
|
||||
</button>
|
||||
{% else %}
|
||||
<button class="btn btn-secondary" type="button" disabled="disabled">
|
||||
<i class="fa-solid fa-trash"></i>
|
||||
<span class="d-none d-md-inline">{{ A_("Delete") }}</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@ -56,7 +63,7 @@ First written: 2023/1/31
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if accounting_can_edit() %}
|
||||
{% if accounting_can_edit() and obj.can_delete %}
|
||||
<form action="{{ url_for("accounting.account.delete", account=obj) }}" method="post">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{% if request.args.next %}
|
||||
|
Reference in New Issue
Block a user