Dashboard cards: rebuild deployable dists
This commit is contained in:
@@ -558,3 +558,35 @@ def dashboard_summary():
|
||||
'bytype': [{'type': t, 'count': c} for t, c in by_type],
|
||||
'bystatus': [{'status': s, 'count': c} for s, c in by_status]
|
||||
})
|
||||
|
||||
|
||||
@machines_bp.route('/dashboard/outofservice', methods=['GET'])
|
||||
@jwt_required()
|
||||
@require_permission('machines.view')
|
||||
def dashboard_outofservice():
|
||||
"""Machines whose status says they are not running.
|
||||
|
||||
Anything that is not In Use: In Repair, Lost, Returned, and so on. Someone
|
||||
is supposed to be chasing each of these, and today they are visible only to
|
||||
whoever thinks to filter the machines list by status.
|
||||
|
||||
Inventory is excluded - a spare on a shelf is not a problem, it is stock.
|
||||
"""
|
||||
from shopdb.api import AssetStatus
|
||||
|
||||
ignored = ('In Use', 'Inventory')
|
||||
|
||||
rows = (db.session.query(Machine, Asset, AssetStatus)
|
||||
.join(Asset, Asset.assetid == Machine.assetid)
|
||||
.join(AssetStatus, AssetStatus.statusid == Asset.statusid)
|
||||
.filter(Asset.isactive.is_(True),
|
||||
AssetStatus.status.notin_(ignored))
|
||||
.order_by(Asset.assetnumber)
|
||||
.limit(50).all())
|
||||
|
||||
return success_response([{
|
||||
'assetid': asset.assetid,
|
||||
'assetnumber': asset.assetnumber or str(asset.assetid),
|
||||
'name': asset.name,
|
||||
'status': status.status,
|
||||
} for _machine, asset, status in rows])
|
||||
|
||||
Reference in New Issue
Block a user