A supply nobody could read is unknown, not empty

This commit is contained in:
2026-08-21 11:44:10 -04:00
parent 65312c0502
commit bbda5cbfe9
6 changed files with 277 additions and 12 deletions

View File

@@ -2109,7 +2109,9 @@ def _annotate_supply(supply, vendor_name, modelnumberid):
Waste cartridge direction depends on vendor, so classification lives in
the supply_parts helper. Part numbers come from the modelsupplies table.
"""
level = supply.get('level', 0)
# .get('level') with no default: a supply with no reading carries None, and
# a 0 default would put back the very substitution this reports around.
level = supply.get('level')
name = supply.get('name', 'Unknown')
supplytype = derivesupplytype(name)
color = derivecolor(name, supply.get('color'))
@@ -2117,6 +2119,7 @@ def _annotate_supply(supply, vendor_name, modelnumberid):
return {
'name': name,
'level': level,
'lastseen': supply.get('lastseen'),
'color': color,
'supplytype': supplytype,
'status': cls['status'],
@@ -2160,6 +2163,7 @@ def _get_low_supplies_data():
results = []
total_checked = 0
unknown_printers = 0
for printer, asset, comm, vendor, model in unique_printers:
supplies = service.getsuppliesbyip_cached(comm.ipaddress)
@@ -2178,13 +2182,24 @@ def _get_low_supplies_data():
# shown it. The whole report exists to answer "what needs replacing".
annotated = []
has_low = False
has_unknown = False
for s in supplies:
item = _annotate_supply(s, vendor_name, modelnumberid)
if item['status'] == 'ok':
continue
# A supply nobody could read is not a supply that needs replacing,
# so it does not join the list of things to act on. It is counted
# instead: a printer that has gone quiet should be visible as that,
# not disappear from the report and not masquerade as empty.
if item['status'] == 'unknown':
has_unknown = True
continue
has_low = True
annotated.append(item)
if has_unknown:
unknown_printers += 1
if has_low:
# location name for the report row
# Via the relationship, the way the printers list does it. The
@@ -2222,7 +2237,12 @@ def _get_low_supplies_data():
'summary': {
'total_checked': total_checked,
'low': low_count,
'critical': critical_count
'critical': critical_count,
# Printers with at least one unreadable supply. They are NOT in
# 'printers' above - nothing about them needs ordering - but a
# count that only ever went up when a cartridge ran low would hide
# a fleet quietly going dark.
'unknown': unknown_printers
}
}