now is possible delete a temporary lot when this lot have one or more devices

This commit is contained in:
Cayo Puigdefabregas 2022-03-07 10:20:18 +01:00
parent 4fbed3c5ef
commit 9d43299592
2 changed files with 3 additions and 4 deletions

View File

@ -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

View File

@ -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)