IT Assets: add Maintenance page with modal form
New database table: maintenance_records - Fields: asset, start_date, end_date, status (open/in_progress/closed), initial_diagnosis, action_taken, action_result New routes (/maintenance/): - List with status + asset filters and pagination - POST /new — create record (editor+); auto-sets asset status to 'maintenance' - GET /<id>/edit — opens list page with modal pre-filled - POST /<id>/update — save edits; auto-clears 'maintenance' status on close - POST /<id>/delete — remove record UI: - Bootstrap modal form shared for add and edit - Clicking any table row opens the modal pre-filled with that row's data - Asset field locked in edit mode (cannot change asset) - Delete button per row (with confirmation) - Sidebar: 'Maintenance' link added under Hardware section
This commit is contained in:
@@ -5,5 +5,6 @@ from app.models.assignment import Assignment
|
||||
from app.models.paperwork import Paperwork
|
||||
from app.models.audit_log import AuditLog
|
||||
from app.models.compliance_check import ComplianceCheck
|
||||
from app.models.maintenance import MaintenanceRecord
|
||||
|
||||
__all__ = ['AdminUser', 'User', 'Asset', 'Assignment', 'Paperwork', 'AuditLog', 'ComplianceCheck']
|
||||
__all__ = ['AdminUser', 'User', 'Asset', 'Assignment', 'Paperwork', 'AuditLog', 'ComplianceCheck', 'MaintenanceRecord']
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime
|
||||
from app.extensions import db
|
||||
|
||||
MAINTENANCE_STATUSES = [
|
||||
('open', 'Open / Diagnosed'),
|
||||
('in_progress', 'In Progress'),
|
||||
('closed', 'Closed'),
|
||||
]
|
||||
|
||||
|
||||
class MaintenanceRecord(db.Model):
|
||||
"""A maintenance or service event performed on a single asset."""
|
||||
__tablename__ = 'maintenance_records'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
asset_id = db.Column(db.Integer, db.ForeignKey('assets.id'), nullable=False)
|
||||
|
||||
start_date = db.Column(db.Date, nullable=False)
|
||||
end_date = db.Column(db.Date, nullable=True)
|
||||
|
||||
status = db.Column(db.String(20), nullable=False, default='open')
|
||||
|
||||
initial_diagnosis = db.Column(db.Text, nullable=True)
|
||||
action_taken = db.Column(db.Text, nullable=True)
|
||||
action_result = db.Column(db.Text, nullable=True)
|
||||
|
||||
created_by_id = db.Column(db.Integer, db.ForeignKey('admin_users.id'), nullable=True)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
asset = db.relationship('Asset', backref=db.backref('maintenance_records', lazy='dynamic'))
|
||||
created_by = db.relationship('AdminUser', foreign_keys=[created_by_id])
|
||||
|
||||
@property
|
||||
def is_open(self):
|
||||
return self.status != 'closed'
|
||||
|
||||
def __repr__(self):
|
||||
return f'<MaintenanceRecord asset={self.asset_id} status={self.status}>'
|
||||
Reference in New Issue
Block a user