search: asset lists search the type column they display

Every asset list shows a Type column (and printers a Model, machines and
network a Vendor), but the search filters only looked at the asset number,
name, serial and hostname. Searching a type returned zero rows: 'Part Washer'
on machines, 'Standard' on PCs, 'Thermal' on printers.

Extend the search on machines, computers, printers, network devices,
measuring tools and the unified asset list to cover the type name plus the
vendor/model where the list shows them. Joins are outer joins so an asset
missing a type or vendor still matches on its own fields; the core list uses
a correlated EXISTS instead, since its type-name filter already joins
AssetType.
This commit is contained in:
cproudlock
2026-07-31 09:02:51 -04:00
parent 71982fc0f1
commit b16f143467
8 changed files with 340 additions and 33 deletions

View File

@@ -354,13 +354,17 @@ def list_assets():
if request.args.get('active', 'true').lower() != 'false':
query = query.filter(Asset.isactive == True)
# Search filter
# Search filter. The asset type is a column in the list, so it has to be
# searchable. Matched via .has() (a correlated EXISTS) rather than a join,
# because the type-name filter below joins AssetType itself.
if search := request.args.get('search'):
pattern = f'%{search}%'
query = query.filter(
db.or_(
Asset.assetnumber.ilike(f'%{search}%'),
Asset.name.ilike(f'%{search}%'),
Asset.serialnumber.ilike(f'%{search}%')
Asset.assetnumber.ilike(pattern),
Asset.name.ilike(pattern),
Asset.serialnumber.ilike(pattern),
Asset.assettype.has(AssetType.assettype.ilike(pattern))
)
)