Initial commit: add compliance_checks table, per-check metadata on assets, and compliance audit trail
This commit is contained in:
72
app/models/paperwork.py
Normal file
72
app/models/paperwork.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from datetime import datetime
|
||||
from app.extensions import db
|
||||
|
||||
DOC_TYPES = [
|
||||
('handover', 'Equipment Handover Receipt'),
|
||||
('assignment', 'Asset Assignment Agreement'),
|
||||
('return', 'Equipment Return Form'),
|
||||
('offboarding', 'Off-Boarding Checklist'),
|
||||
('custom', 'Custom Document'),
|
||||
]
|
||||
|
||||
|
||||
class Paperwork(db.Model):
|
||||
"""Generated paperwork documents tied to a user and optionally an asset."""
|
||||
__tablename__ = 'paperwork'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
document_type = db.Column(db.String(30), nullable=False) # see DOC_TYPES
|
||||
title = db.Column(db.String(200), nullable=False)
|
||||
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
asset_id = db.Column(db.Integer, db.ForeignKey('assets.id'), nullable=True)
|
||||
assignment_id = db.Column(db.Integer, db.ForeignKey('assignments.id'), nullable=True)
|
||||
|
||||
# FK to DocumentTemplate — null for legacy ReportLab-generated docs
|
||||
template_id = db.Column(db.Integer, db.ForeignKey('document_templates.id'), nullable=True)
|
||||
|
||||
# JSON snapshot of merge variables used at generation time.
|
||||
# Kept forever so the document can be re-rendered (e.g. after PII masking).
|
||||
merge_vars = db.Column(db.Text, nullable=True)
|
||||
|
||||
# Legacy free-text / JSON snapshot (kept for backwards compat)
|
||||
template_data = db.Column(db.Text, nullable=True)
|
||||
|
||||
# Generated output files (relative to their respective folders)
|
||||
pdf_filename = db.Column(db.String(300), nullable=True)
|
||||
docx_filename = db.Column(db.String(300), nullable=True)
|
||||
|
||||
notes = db.Column(db.Text, nullable=True)
|
||||
|
||||
# Signature
|
||||
signed_at = db.Column(db.DateTime, nullable=True)
|
||||
signed_by_name = db.Column(db.String(200), nullable=True) # printed name
|
||||
signature_data = db.Column(db.Text, nullable=True) # base64 PNG
|
||||
|
||||
created_by_id = db.Column(db.Integer, db.ForeignKey('admin_users.id'), nullable=True)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
||||
created_by = db.relationship('AdminUser', foreign_keys=[created_by_id])
|
||||
template = db.relationship('DocumentTemplate', back_populates='paperwork_docs',
|
||||
foreign_keys=[template_id])
|
||||
|
||||
@property
|
||||
def doc_type_label(self):
|
||||
return dict(DOC_TYPES).get(self.document_type, self.document_type)
|
||||
|
||||
@property
|
||||
def is_signed(self):
|
||||
return self.signed_at is not None
|
||||
|
||||
def get_merge_vars(self):
|
||||
if self.merge_vars:
|
||||
try:
|
||||
import json
|
||||
return json.loads(self.merge_vars)
|
||||
except (ValueError, TypeError):
|
||||
return {}
|
||||
return {}
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Paperwork id={self.id} type={self.document_type}>'
|
||||
Reference in New Issue
Block a user