|
| 1 | +# path: policylens/apps/claims/management/commands/seed_sample_data.py |
| 2 | +""" |
| 3 | +Seed deterministic sample data for local development. |
| 4 | +
|
| 5 | +This command is designed for repeatable demos and for week 5 UI development. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import random |
| 11 | +from datetime import date |
| 12 | + |
| 13 | +from django.core.management.base import BaseCommand |
| 14 | +from django.db import transaction |
| 15 | + |
| 16 | +from apps.claims.models import Claim, Policy, PolicyHolder |
| 17 | +from apps.claims.services import append_audit_event, create_claim |
| 18 | + |
| 19 | + |
| 20 | +class Command(BaseCommand): |
| 21 | + """Seed sample data into the database.""" |
| 22 | + |
| 23 | + help = "Seed deterministic sample data for PolicyLens." |
| 24 | + |
| 25 | + @transaction.atomic |
| 26 | + def handle(self, *args, **options) -> None: |
| 27 | + """Run the seed workflow.""" |
| 28 | + rng = random.Random(42) |
| 29 | + |
| 30 | + holders = [] |
| 31 | + for i in range(5): |
| 32 | + holder = PolicyHolder.objects.create( |
| 33 | + full_name=f"Sample Holder {i+1}", |
| 34 | + email=f"holder{i+1}@example.com", |
| 35 | + phone=f"+44 7700 900{i:03d}", |
| 36 | + ) |
| 37 | + holders.append(holder) |
| 38 | + |
| 39 | + policies = [] |
| 40 | + for i, holder in enumerate(holders, start=1): |
| 41 | + policy = Policy.objects.create( |
| 42 | + holder=holder, |
| 43 | + policy_number=f"PL-{1000 + i}", |
| 44 | + product_type=rng.choice( |
| 45 | + ["Home Insurance", "Motor Insurance", "Travel Insurance"] |
| 46 | + ), |
| 47 | + status=Policy.Status.ACTIVE, |
| 48 | + effective_date=date(2024, 1, 1), |
| 49 | + ) |
| 50 | + policies.append(policy) |
| 51 | + |
| 52 | + created_claims = [] |
| 53 | + for i in range(10): |
| 54 | + policy = rng.choice(policies) |
| 55 | + claim_type = rng.choice( |
| 56 | + [Claim.Type.CLAIM, Claim.Type.POLICY_CHANGE] |
| 57 | + ) |
| 58 | + priority = rng.choice( |
| 59 | + [Claim.Priority.LOW, |
| 60 | + Claim.Priority.NORMAL, |
| 61 | + Claim.Priority.HIGH] |
| 62 | + ) |
| 63 | + summary = rng.choice( |
| 64 | + [ |
| 65 | + "Customer submitted initial documents.", |
| 66 | + "Missing proof of address.", |
| 67 | + "Upload includes unclear photo.", |
| 68 | + "Policy change request with partial details.", |
| 69 | + "Claim notes mention third party involvement.", |
| 70 | + ] |
| 71 | + ) |
| 72 | + claim = create_claim( |
| 73 | + policy=policy, |
| 74 | + claim_type=claim_type, |
| 75 | + priority=priority, |
| 76 | + summary=summary, |
| 77 | + actor="seed", |
| 78 | + ) |
| 79 | + created_claims.append(claim) |
| 80 | + |
| 81 | + # Add one extra event for realism |
| 82 | + for claim in created_claims[:3]: |
| 83 | + append_audit_event( |
| 84 | + claim=claim, |
| 85 | + event_type="NOTE_ADDED", |
| 86 | + actor="seed", |
| 87 | + payload={"note": "Seeded note for timeline realism."}, |
| 88 | + ) |
| 89 | + |
| 90 | + self.stdout.write( |
| 91 | + self.style.SUCCESS( |
| 92 | + "Seeded " |
| 93 | + f"{len(holders)} holders, " |
| 94 | + f"{len(policies)} policies, " |
| 95 | + f"{len(created_claims)} claims." |
| 96 | + ) |
| 97 | + ) |
0 commit comments