always show the button to delete a lot and show an error message if you try to delete a lot with devices

This commit is contained in:
Cayo Puigdefabregas 2022-03-04 18:30:14 +01:00
parent 6b3ccee58f
commit 496763473e
2 changed files with 8 additions and 1 deletions

View file

@ -211,6 +211,13 @@ class LotDeleteView(View):
def dispatch_request(self, id):
form = LotForm(id=id)
if form.instance.devices:
msg = ("Sorry, the lot cannot be deleted because it still "
"has associated devices. Only empty lots can be deleted")
messages.error(msg)
next_url = url_for('inventory.devices.lotdevicelist', lot_id=id)
return flask.redirect(next_url)
form.remove()
next_url = url_for('inventory.devices.devicelist')
return flask.redirect(next_url)

View file

@ -37,7 +37,7 @@
<h3><a href="{{ url_for('inventory.devices.lot_edit', id=lot.id) }}">{{ lot.name }}</a></h3>
</div>
<div class="col">
{% if lot and lot.is_temporary and not lot.devices %}
{% if lot and lot.is_temporary %}
<a href="javascript:void()" data-bs-toggle="modal" data-bs-target="#btnRemoveLots">
<i class="bi bi-trash"></i>
Remove Lot