- Fix equipment badge barcode not rendering (loading race condition) - Fix printer QR code not rendering on initial load (same race condition) - Add model image to equipment badge via imageurl from Model table - Fix white-on-white machine number text on badge, tighten barcode spacing - Add PaginationBar component used across all list pages - Split monolithic router into per-plugin route modules - Fix 25 GET API endpoints returning 401 (jwt_required -> optional=True) - Align list page columns across Equipment, PCs, and Network pages - Add print views: EquipmentBadge, PrinterQRSingle, PrinterQRBatch, USBLabelBatch - Add PC Relationships report, migration docs, and CLAUDE.md project guide - Various plugin model, API, and frontend refinements Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
137 lines
3.5 KiB
Python
137 lines
3.5 KiB
Python
"""Machine and Asset relationship models."""
|
|
|
|
from shopdb.extensions import db
|
|
from .base import BaseModel
|
|
|
|
|
|
class RelationshipType(BaseModel):
|
|
"""Types of relationships between machines/assets."""
|
|
__tablename__ = 'relationshiptypes'
|
|
|
|
relationshiptypeid = db.Column(db.Integer, primary_key=True)
|
|
relationshiptype = db.Column(db.String(50), unique=True, nullable=False)
|
|
description = db.Column(db.Text)
|
|
|
|
# Example types:
|
|
# - "Controls" (PC controls Equipment)
|
|
# - "Dualpath" (Redundant path partner)
|
|
# - "Backup" (Backup machine)
|
|
|
|
def __repr__(self):
|
|
return f"<RelationshipType {self.relationshiptype}>"
|
|
|
|
|
|
class AssetRelationship(BaseModel):
|
|
"""
|
|
Relationships between assets.
|
|
|
|
Examples:
|
|
- Computer controls Equipment
|
|
- Two machines are dualpath partners
|
|
- Network device connects to equipment
|
|
"""
|
|
__tablename__ = 'assetrelationships'
|
|
|
|
relationshipid = db.Column(db.Integer, primary_key=True)
|
|
|
|
sourceassetid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('assets.assetid'),
|
|
nullable=False
|
|
)
|
|
targetassetid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('assets.assetid'),
|
|
nullable=False
|
|
)
|
|
relationshiptypeid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('relationshiptypes.relationshiptypeid'),
|
|
nullable=False
|
|
)
|
|
|
|
notes = db.Column(db.Text)
|
|
|
|
# Relationships
|
|
sourceasset = db.relationship(
|
|
'Asset',
|
|
foreign_keys=[sourceassetid],
|
|
backref='outgoing_relationships'
|
|
)
|
|
targetasset = db.relationship(
|
|
'Asset',
|
|
foreign_keys=[targetassetid],
|
|
backref='incoming_relationships'
|
|
)
|
|
relationshiptype = db.relationship('RelationshipType', backref='asset_relationships')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint(
|
|
'sourceassetid',
|
|
'targetassetid',
|
|
'relationshiptypeid',
|
|
name='uq_asset_relationship'
|
|
),
|
|
db.Index('idx_asset_rel_source', 'sourceassetid'),
|
|
db.Index('idx_asset_rel_target', 'targetassetid'),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<AssetRelationship {self.sourceassetid} -> {self.targetassetid}>"
|
|
|
|
|
|
class MachineRelationship(BaseModel):
|
|
"""
|
|
Relationships between machines.
|
|
|
|
Examples:
|
|
- PC controls CNC machine
|
|
- Two CNCs are dualpath partners
|
|
"""
|
|
__tablename__ = 'machinerelationships'
|
|
|
|
relationshipid = db.Column(db.Integer, primary_key=True)
|
|
|
|
parentmachineid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('machines.machineid'),
|
|
nullable=False
|
|
)
|
|
childmachineid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('machines.machineid'),
|
|
nullable=False
|
|
)
|
|
relationshiptypeid = db.Column(
|
|
db.Integer,
|
|
db.ForeignKey('relationshiptypes.relationshiptypeid'),
|
|
nullable=False
|
|
)
|
|
|
|
notes = db.Column(db.Text)
|
|
|
|
# Relationships
|
|
parent_machine = db.relationship(
|
|
'Machine',
|
|
foreign_keys=[parentmachineid],
|
|
backref='child_relationships'
|
|
)
|
|
child_machine = db.relationship(
|
|
'Machine',
|
|
foreign_keys=[childmachineid],
|
|
backref='parent_relationships'
|
|
)
|
|
relationship_type = db.relationship('RelationshipType', backref='relationships')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint(
|
|
'parentmachineid',
|
|
'childmachineid',
|
|
'relationshiptypeid',
|
|
name='uq_machine_relationship'
|
|
),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<MachineRelationship {self.parentmachineid} -> {self.childmachineid}>"
|