Skip to content

Commit

Permalink
feat(return): warn on staff current checkouts (#154)
Browse files Browse the repository at this point in the history
closes #65
  • Loading branch information
drahamim authored May 17, 2024
1 parent 79ee4c4 commit 0ec4918
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/invenflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,6 @@ def get_version():
capture_output=True).stdout.decode('utf-8').strip())
return dict(app_version=version("invenflask"))


@app.route('/')
def index():
assets = db.session.query(Asset).all()
asset_total = db.session.query(Asset).count()
asset_types = db.session.query(
Asset.asset_type, db.func.count()).group_by(Asset.asset_type).all()
asset_status = db.session.query(
Asset.asset_type,
db.func.count().label('TotalCount'),
db.func.sum(db.case((Asset.asset_status == 'checkedout', 1), else_=0)).label(
'AvailCount')
).group_by(Asset.asset_type).all()
checkouts = db.session.query(Checkout).all()
return render_template(
'index.html', assets=assets, asset_total=asset_total,
asset_type=asset_types, asset_status=asset_status, checkouts=checkouts)

# ASSET ROUTES


Expand Down Expand Up @@ -311,8 +293,16 @@ def return_asset():
db.session.query(Checkout).filter(
Checkout.assetid == checkout_info.assetid).delete()
print('commit')
current_checkouts = db.session.query(Checkout).filter(
Checkout.staffid == staffer.id).all()
db.session.commit()
return redirect(url_for('history'))
if not current_checkouts:
flash('Asset was successfully returned!', "success")
return redirect(url_for('return_asset'))
else:
flash('Asset was successfully returned!', "success")
flash('Staffer still has assets checked out', "warning")
return redirect(url_for('return_asset'))
except Exception as e:
app.logger.error(e)
flash("Return failed", 'warning')
Expand Down

0 comments on commit 0ec4918

Please sign in to comment.