Never file a part marker under its own PC

This commit is contained in:
2026-08-10 17:01:41 -04:00
parent 2924a53346
commit 2e0f021354
2 changed files with 54 additions and 2 deletions

View File

@@ -798,19 +798,26 @@ class ComputersPlugin(BasePlugin):
rel.isactive = False
operation = self._link_marker_to_operation(
markerasset, machinenumber, warnings)
markerasset, machinenumber, pcasset, warnings)
return [{'assetid': markerasset.assetid,
'assetnumber': markerasset.assetnumber,
'operationassetid': operation}]
def _link_marker_to_operation(self, markerasset, machinenumber, warnings):
def _link_marker_to_operation(self, markerasset, machinenumber, pcasset,
warnings):
"""Make a marker `partof` the operation whose number its PC reports.
Unlike the PC-to-machine link this does NOT contest: an operation can
hold any number of markers, which is the whole point. Moving a marker to
another operation archives the old membership rather than deleting it,
so where a marker used to live stays answerable.
Refuses to file a marker under the reporting PC. A PC first seen before
the machine-number fix was created with the machine number as its OWN
asset number, and that is deliberately never overwritten, so looking up
the number can return the PC itself. Filing the marker partof its own PC
would read, on the machine page, as the PC being the operation.
"""
from shopdb.api import AssetRelationship, RelationshipType, Asset
@@ -834,6 +841,13 @@ class ComputersPlugin(BasePlugin):
return None
if operation.assetid == markerasset.assetid:
return None
if pcasset is not None and operation.assetid == pcasset.assetid:
warnings.append(
'machine number {!r} is this PC\'s own asset number; marker '
'not filed under an operation. Rename the PC asset to its '
'hostname, or create the operation asset.'.format(
machinenumber))
return None
links = AssetRelationship.query.filter(
AssetRelationship.sourceassetid == markerasset.assetid,