From 9d432995929711aaacda902e3c41b61c6eef9156 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 7 Mar 2022 10:20:18 +0100 Subject: [PATCH] now is possible delete a temporary lot when this lot have one or more devices --- ereuse_devicehub/inventory/forms.py | 2 +- ereuse_devicehub/inventory/views.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 841dcb15..b65079fa 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -113,7 +113,7 @@ class LotForm(FlaskForm): return self.id def remove(self): - if self.instance and not self.instance.devices: + if self.instance and not self.instance.trade: self.instance.delete() db.session.commit() return self.instance diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 42e0f67f..089a1920 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -211,9 +211,8 @@ 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") + if form.instance.trade: + msg = "Sorry, the lot cannot be deleted because have a trade action " messages.error(msg) next_url = url_for('inventory.devices.lotdevicelist', lot_id=id) return flask.redirect(next_url)