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