warranty machine column with map hover; opaque settings dialogs
This commit is contained in:
@@ -33,12 +33,57 @@ def _parse_date(value):
|
||||
return None
|
||||
|
||||
|
||||
def _related_machine(asset):
|
||||
"""The machine a covered asset is associated with, or None.
|
||||
|
||||
A shopfloor PC is bought, warranted and replaced as a PC, but it is FOUND
|
||||
by the machine it drives - nobody walks the floor looking for an asset
|
||||
number. So a warranty row for a PC carries the machine's number, and its
|
||||
map position so the row can point at where to go.
|
||||
|
||||
Walks the asset relationship graph in BOTH directions: the canonical edge is
|
||||
PC --controls--> machine, but a dual-bay pair carries controls on both bays
|
||||
and hand-made links are not guaranteed to be oriented. Returns the first
|
||||
active related asset whose type is 'machine'.
|
||||
"""
|
||||
from shopdb.api import Asset as CoreAsset
|
||||
|
||||
related = []
|
||||
for rel in (getattr(asset, 'outgoing_relationships', None) or []):
|
||||
if rel.isactive and rel.targetasset:
|
||||
related.append(rel.targetasset)
|
||||
for rel in (getattr(asset, 'incoming_relationships', None) or []):
|
||||
if rel.isactive and rel.sourceasset:
|
||||
related.append(rel.sourceasset)
|
||||
|
||||
for candidate in related:
|
||||
typename = candidate.assettype.assettype if candidate.assettype else None
|
||||
if typename != 'machine':
|
||||
continue
|
||||
return {
|
||||
'assetid': candidate.assetid,
|
||||
'machinenumber': candidate.assetnumber,
|
||||
'name': candidate.name,
|
||||
# Map position for the hover preview. Either may be None: a machine
|
||||
# that has never been placed on the floor map still has a number
|
||||
# worth showing, so the caller decides what to do with a missing
|
||||
# position rather than the row being dropped.
|
||||
'mapx': candidate.mapx,
|
||||
'mapy': candidate.mapy,
|
||||
'locationid': candidate.locationid,
|
||||
'locationname': (candidate.location.locationname
|
||||
if candidate.location else None),
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
def _asset_summary(asset):
|
||||
return {
|
||||
'assetid': asset.assetid,
|
||||
'assetnumber': asset.assetnumber,
|
||||
'name': asset.name,
|
||||
'assettypename': asset.assettype.assettype if asset.assettype else None,
|
||||
'machine': _related_machine(asset),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user