"""USB Checkout model.""" from shopdb.extensions import db from datetime import datetime class USBCheckout(db.Model): """ USB device checkout tracking. References machines table (USB devices have machinetypeid=44). """ __tablename__ = 'usbcheckouts' checkoutid = db.Column(db.Integer, primary_key=True) machineid = db.Column(db.Integer, db.ForeignKey('machines.machineid'), nullable=False, index=True) sso = db.Column(db.String(20), nullable=False, index=True) checkout_name = db.Column(db.String(100)) checkout_reason = db.Column(db.Text) checkout_time = db.Column(db.DateTime, default=datetime.utcnow, index=True) checkin_time = db.Column(db.DateTime, index=True) was_wiped = db.Column(db.Boolean, default=False) checkin_notes = db.Column(db.Text) def to_dict(self): """Convert to dictionary.""" return { 'checkoutid': self.checkoutid, 'machineid': self.machineid, 'sso': self.sso, 'checkout_name': self.checkout_name, 'checkout_reason': self.checkout_reason, 'checkout_time': self.checkout_time.isoformat() if self.checkout_time else None, 'checkin_time': self.checkin_time.isoformat() if self.checkin_time else None, 'was_wiped': self.was_wiped, 'checkin_notes': self.checkin_notes, 'is_checked_out': self.checkin_time is None }