Printer card chips
This commit is contained in:
@@ -1407,6 +1407,24 @@ def _shortsupplyname(name):
|
||||
return text or 'supply'
|
||||
|
||||
|
||||
def _reordertip(supply):
|
||||
"""What to order, for the chip's tooltip.
|
||||
|
||||
A percentage says a cartridge is nearly out; the part number says what to
|
||||
buy, which is the next thing someone needs and today means opening the
|
||||
printer's page to find it. Every capacity tier is listed, because the
|
||||
report has always shown all reorder options.
|
||||
"""
|
||||
parts = supply.get('partnumbers') or []
|
||||
if not parts:
|
||||
return 'No part number on file for this model'
|
||||
return ', '.join(
|
||||
'{}{}'.format(part['partnumber'],
|
||||
' ({})'.format(part['capacitytier'])
|
||||
if part.get('capacitytier') else '')
|
||||
for part in parts)
|
||||
|
||||
|
||||
@printers_asset_bp.route('/dashboard/supplies', methods=['GET'])
|
||||
@jwt_required()
|
||||
@require_permission('printers.view')
|
||||
@@ -1429,22 +1447,21 @@ def dashboard_supplies():
|
||||
lows = [s for s in printer['supplies'] if s['status'] == 'low']
|
||||
if not criticals and not lows:
|
||||
continue
|
||||
# Every depleted supply, criticals first. Listing only the worst class
|
||||
# would hide a low cartridge behind a critical one on the same printer,
|
||||
# and whoever walks out there wants to carry both.
|
||||
worst = criticals + lows
|
||||
# Criticals first. Every depleted supply is listed, not just the worst
|
||||
# class - whoever walks out there wants to carry both cartridges.
|
||||
rows.append({
|
||||
'printerid': printer['printerid'],
|
||||
'printername': printer['printername'] or printer['assetnumber'],
|
||||
'location': printer['location'],
|
||||
'status': 'critical' if criticals else 'low',
|
||||
# 'remaining' is the percent left. There is no 'percent' key -
|
||||
# reading one rendered every cartridge as "None%" on the board.
|
||||
'supplies': ', '.join(
|
||||
'{} {}%'.format(_shortsupplyname(s.get('name')),
|
||||
s.get('remaining'))
|
||||
for s in worst),
|
||||
'location': printer['location'] or 'No location set',
|
||||
'iscritical': bool(criticals),
|
||||
# One chip per depleted supply: what is low, and on hover what to
|
||||
# order to fix it.
|
||||
'supplies': [{
|
||||
'text': '{} {}%'.format(_shortsupplyname(supply.get('name')),
|
||||
supply.get('remaining')),
|
||||
'title': _reordertip(supply),
|
||||
'level': supply.get('status'),
|
||||
} for supply in criticals + lows],
|
||||
})
|
||||
|
||||
rows.sort(key=lambda r: (not r['iscritical'], r['printername']))
|
||||
|
||||
Reference in New Issue
Block a user