From 496763473e8d5ec1d5183248a300d256964b39ae Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 4 Mar 2022 18:30:14 +0100 Subject: [PATCH] always show the button to delete a lot and show an error message if you try to delete a lot with devices --- ereuse_devicehub/inventory/views.py | 7 +++++++ ereuse_devicehub/templates/inventory/device_list.html | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index c0ac0117..42e0f67f 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -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) diff --git a/ereuse_devicehub/templates/inventory/device_list.html b/ereuse_devicehub/templates/inventory/device_list.html index 80384cb1..bb01f389 100644 --- a/ereuse_devicehub/templates/inventory/device_list.html +++ b/ereuse_devicehub/templates/inventory/device_list.html @@ -37,7 +37,7 @@

{{ lot.name }}

- {% if lot and lot.is_temporary and not lot.devices %} + {% if lot and lot.is_temporary %} Remove Lot