Files

152 lines
6.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from sqlalchemy.orm import Session
from .database import SessionLocal, engine
from . import models, auth
from datetime import datetime
# Import data directly as if it were coming from data.jsx
USERS = [
{"id": "rod", "name": "Rod", "role": "Owner", "hue": 220, "initials": "R"},
{"id": "lani", "name": "Lani", "role": "Admin", "hue": 340, "initials": "L"},
{"id": "kirra", "name": "Kirra", "role": "Technician", "hue": 160, "initials": "K"},
{"id": "ayron", "name": "Ayron", "role": "Technician", "hue": 40, "initials": "A"},
]
SEED_TASKS = [
{ "id": 't1', "title": 'Call back Mrs. Patel re: Hilux service quote',
"description": 'She left a voicemail Tuesday — wants confirmation on the timing belt price before she books in.',
"assignee": 'lani', "addedBy": 'rod', "priority": 'high', "source": 'imessage',
"addedAt": '2026-05-08T08:42:00', "status": 'open',
"tags": ['quote'] },
{ "id": 't2', "title": 'Email #3814 → Workorder #2207',
"description": 'Auto-converted from inbox. Tell customer ETA of Friday.',
"assignee": 'lani', "addedBy": 'system', "priority": 'med', "source": 'email',
"addedAt": '2026-05-08T07:15:00', "status": 'open',
"tags": ['WO #2207'] },
{ "id": 't3', "title": 'Reorder coolant — 5L × 4',
"description": 'Stock card ran red on the morning sweep.',
"assignee": 'lani', "addedBy": 'kirra', "priority": 'low', "source": 'manual',
"addedAt": '2026-05-07T16:02:00', "status": 'open', "tags": [] },
{ "id": 't4', "title": 'Form response from "K. Wynne" auto-switched to Billing',
"description": 'Originally captured as Service Booking — heads up.',
"assignee": 'lani', "addedBy": 'system', "priority": 'med', "source": 'automation',
"addedAt": '2026-05-08T09:50:00', "status": 'billing',
"tags": ['form'] },
{ "id": 't5', "title": 'Diagnose intermittent misfire — Camry, WO #2199',
"description": 'Cust says it stutters between 6080km/h once warm.',
"assignee": 'kirra', "addedBy": 'rod', "priority": 'high', "source": 'manual',
"addedAt": '2026-05-08T07:50:00', "status": 'open',
"tags": ['WO #2199'] },
{ "id": 't6', "title": 'Sign off on Ayron\'s brake job — Forester',
"description": 'Final torque check + road test before pickup at 3pm.',
"assignee": 'kirra', "addedBy": 'ayron', "priority": 'med', "source": 'manual',
"addedAt": '2026-05-08T09:05:00', "status": 'open', "tags": [] },
{ "id": 't7', "title": 'WO #2188 auto-marked Unsuccessful',
"description": 'Customer no-show twice — please review and decide on next step.',
"assignee": 'kirra', "addedBy": 'system', "priority": 'high', "source": 'automation',
"addedAt": '2026-05-08T06:00:00', "status": 'unsuccessful',
"tags": ['WO #2188'] },
{ "id": 't8', "title": 'Replace front pads + rotors — Forester',
"description": 'Parts arrived yesterday. Bay 2 from 10am.',
"assignee": 'ayron', "addedBy": 'kirra', "priority": 'med', "source": 'manual',
"addedAt": '2026-05-08T08:00:00', "status": 'open',
"tags": ['WO #2201'] },
{ "id": 't9', "title": 'Tidy bay 3 + sweep before lunch',
"description": '',
"assignee": 'ayron', "addedBy": 'rod', "priority": 'low', "source": 'imessage',
"addedAt": '2026-05-08T09:30:00', "status": 'open', "tags": [] },
{ "id": 't10', "title": 'Pickup parts from Repco @ 11:30',
"description": 'Two boxes for WO #2199 + an oil filter for stock.',
"assignee": 'ayron', "addedBy": 'lani', "priority": 'med', "source": 'manual',
"addedAt": '2026-05-08T08:20:00', "status": 'open', "tags": [] },
{ "id": 't11', "title": 'Approve quote on Job #2207 ($1,840)',
"description": 'Lani flagged this — needs your sign-off before sending.',
"assignee": 'rod', "addedBy": 'lani', "priority": 'high', "source": 'manual',
"addedAt": '2026-05-08T09:12:00', "status": 'open',
"tags": ['quote', 'WO #2207'] },
{ "id": 't12', "title": 'Review weekly automation report',
"description": '14 tasks created from email, 6 from iMessage, 2 form re-routes.',
"assignee": 'rod', "addedBy": 'system', "priority": 'low', "source": 'automation',
"addedAt": '2026-05-08T06:00:00', "status": 'open', "tags": [] },
]
SEED_AUDIT = [
{ "id": 'a1', "at": '2026-05-08T09:50:00', "actor": 'system', "action": 'form_rerouted',
"summary": 'Form from K. Wynne auto-switched: Service Booking → Billing form',
"target": 't4' },
{ "id": 'a2', "at": '2026-05-08T09:30:00', "actor": 'rod', "action": 'task_created',
"summary": 'Created task "Tidy bay 3 + sweep before lunch" for Ayron via iMessage',
"target": 't9' },
{ "id": 'a3', "at": '2026-05-08T09:12:00', "actor": 'lani', "action": 'task_assigned',
"summary": 'Assigned "Approve quote on Job #2207" to ROD',
"target": 't11' },
{ "id": 'a4', "at": '2026-05-08T09:05:00', "actor": 'ayron', "action": 'task_moved',
"summary": 'Moved "Sign off on brake job" from Ayron → Kirra',
"target": 't6' },
]
def seed_db():
# Create tables
models.Base.metadata.create_all(bind=engine)
db = SessionLocal()
# Add Users
for u in USERS:
is_admin = u['id'] in ['rod', 'ayron']
db_user = models.User(
id=u['id'],
name=u['name'],
role=u['role'],
hue=u['hue'],
initials=u['initials'],
email=f"{u['id']}@murchison-auto.co",
phone="+64 27 555 0184",
password_hash=auth.get_password_hash("password123"), # Default password
account_type='admin' if is_admin else 'standard'
)
db.merge(db_user)
# Add Tasks
for t in SEED_TASKS:
db_task = models.Task(
id=t['id'],
title=t['title'],
description=t['description'],
assignee_id=t['assignee'],
added_by=t['addedBy'],
priority=t['priority'],
source=t['source'],
status=t['status'],
added_at=datetime.fromisoformat(t['addedAt'])
)
db_task = db.merge(db_task)
# Add tags
for tag_name in t.get('tags', []):
tag = db.query(models.Tag).filter(models.Tag.tag == tag_name).first()
if not tag:
tag = models.Tag(tag=tag_name)
db.add(tag)
db.flush()
if tag not in db_task.tags:
db_task.tags.append(tag)
# Add Audit
for a in SEED_AUDIT:
db_audit = models.AuditLog(
id=a['id'],
at=datetime.fromisoformat(a['at']),
actor=a['actor'],
action=a['action'],
summary=a['summary'],
target=a['target']
)
db.merge(db_audit)
db.commit()
db.close()
if __name__ == "__main__":
seed_db()
print("Database seeded!")