remove lot

This commit is contained in:
Cayo Puigdefabregas 2022-01-03 12:28:42 +01:00
parent d17114a0b0
commit d994cd2f10
3 changed files with 28 additions and 1 deletions

View File

@ -64,3 +64,8 @@ class LotForm(FlaskForm):
db.session.add(self.lot)
db.session.commit()
def remove(self):
if self.lot and not self.lot.devices:
self.lot.delete()
db.session.commit()

View File

@ -80,9 +80,23 @@ class LotView(View):
return flask.render_template(self.template_name, form=form, title=self.title)
class LotDeleteView(View):
methods = ['GET']
decorators = [login_required]
template_name = 'inventory/device_list.html'
def dispatch_request(self, id):
form = LotForm(id=id)
form.remove()
next_url = url_for('inventory.devices.devicelist')
return flask.redirect(next_url)
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))
devices.add_url_rule('/lot/devices/del/', view_func=LotDeviceDeleteView.as_view('lot_devices_del'))
devices.add_url_rule('/lot/add', view_func=LotView.as_view('lot_add'))
devices.add_url_rule('/lot/add/', view_func=LotView.as_view('lot_add'))
devices.add_url_rule('/lot/<string:id>/del/', view_func=LotDeleteView.as_view('lot_del'))
devices.add_url_rule('/lot/<string:id>/', view_func=LotView.as_view('lot_edit'))

View File

@ -33,11 +33,19 @@
<!-- Bordered Tabs -->
<div class="btn-group dropdown ml-1">
{% if lot and lot.is_temporary and not lot.devices %}
<a href="{{ url_for('inventory.devices.lot_del', id=lot.id)}}" type="button" class="btn btn-primary">
<i class="bi bi-trash"></i>
Remove Lot
<span class="caret"></span>
</a>
{% else %}
<button id="btnLots" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-folder2"></i>
Lots
<span class="caret"></span>
</button>
{% endif %}
<ul class="dropdown-menu" aria-labelledby="btnLots"">
<li>
<a href="javascript:void()" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#addingLotModal">