1515 Invitation , InvitationStatus , Message , MessageRole , MessageType ,
1616 MessageStatus , MessageLog , MessageTriggerSource , Payment , PaymentMethod ,
1717 PaymentStatus , SyncLog , SyncType , SyncLogStatus , ConversationStatus ,
18- ConversationState
18+ ConversationState , IntegrationConfig , Document
1919)
2020from datetime import datetime , timedelta , timezone
2121import logging
2424router = APIRouter ()
2525logger = logging .getLogger (__name__ )
2626
27- async def populate_demo_data (db : AsyncSession ):
27+ async def populate_demo_data (db : AsyncSession , owner_clerk_id : str ):
2828 # 1. Create a Demo Business
2929 business = Business (
3030 name = "Demo Home Services" ,
@@ -38,9 +38,6 @@ async def populate_demo_data(db: AsyncSession):
3838 await db .flush ()
3939
4040 # 2. Create Users
41- # Use the actual clerk ID from E2E tests if available, otherwise fallback
42- owner_clerk_id = "user_38td2lMr5JN9ZvyReFkzCKh6E2B"
43-
4441 owner = User (
4542 clerk_id = owner_clerk_id ,
4643 name = "Demo Owner" ,
@@ -90,13 +87,13 @@ async def populate_demo_data(db: AsyncSession):
9087
9188 # 4. Create Customers
9289 customers = [
93- Customer (business_id = business .id , name = "John Doe" , phone = "+353871234567" , email = "john@example.com" , street = "123 Main St" , city = "Dublin" , pipeline_stage = PipelineStage .CONTACTED ),
94- Customer (business_id = business .id , name = "Jane Smith" , phone = "+353871234569" , email = "jane@example.com" , street = "45 Grafton St" , city = "Dublin" , pipeline_stage = PipelineStage .QUOTED ),
95- Customer (business_id = business .id , name = "Alice Wonderland" , phone = "+353871111112" , email = "alice@example.com" , street = "123 O'Connell St" , city = "Dublin" , pipeline_stage = PipelineStage .CONTACTED ),
96- Customer (business_id = business .id , name = "Bob Builder" , phone = "+353874444444" , email = "bob@example.com" , street = "78 Wall St" , city = "Dublin" , pipeline_stage = PipelineStage .NOT_CONTACTED ),
97- Customer (business_id = business .id , name = "Charlie Brown" , phone = "+353875555555" , email = "charlie@example.com" , street = "10 Temple Bar" , city = "Dublin" , pipeline_stage = PipelineStage .NOT_CONTACTED ),
98- Customer (business_id = business .id , name = "John Smith" , phone = "+353871234568" , email = "john.smith@example.com" , street = "124 Main St" , city = "Dublin" , pipeline_stage = PipelineStage .CONTACTED ),
99- Customer (business_id = business .id , name = "Test Customer" , phone = "+353879999999" , email = "test@example.com" , street = "99 Test Rd" , city = "Dublin" , pipeline_stage = PipelineStage .NOT_CONTACTED ),
90+ Customer (business_id = business .id , name = "John Doe" , first_name = "John" , last_name = "Doe" , phone = "+353871234567" , email = "john@example.com" , street = "123 Main St" , city = "Dublin" , pipeline_stage = PipelineStage .CONTACTED ),
91+ Customer (business_id = business .id , name = "Jane Smith" , first_name = "Jane" , last_name = "Smith" , phone = "+353871234569" , email = "jane@example.com" , street = "45 Grafton St" , city = "Dublin" , pipeline_stage = PipelineStage .QUOTED ),
92+ Customer (business_id = business .id , name = "Alice Wonderland" , first_name = "Alice" , last_name = "Wonderland" , phone = "+353871111112" , email = "alice@example.com" , street = "123 O'Connell St" , city = "Dublin" , pipeline_stage = PipelineStage .CONTACTED ),
93+ Customer (business_id = business .id , name = "Bob Builder" , first_name = "Bob" , last_name = "Builder" , phone = "+353874444444" , email = "bob@example.com" , street = "78 Wall St" , city = "Dublin" , pipeline_stage = PipelineStage .NOT_CONTACTED ),
94+ Customer (business_id = business .id , name = "Charlie Brown" , first_name = "Charlie" , last_name = "Brown" , phone = "+353875555555" , email = "charlie@example.com" , street = "10 Temple Bar" , city = "Dublin" , pipeline_stage = PipelineStage .NOT_CONTACTED ),
95+ Customer (business_id = business .id , name = "John Smith" , first_name = "John" , last_name = "Smith" , phone = "+353871234568" , email = "john.smith@example.com" , street = "124 Main St" , city = "Dublin" , pipeline_stage = PipelineStage .CONTACTED ),
96+ Customer (business_id = business .id , name = "Test Customer" , first_name = "Test" , last_name = "Customer" , phone = "+353879999999" , email = "test@example.com" , street = "99 Test Rd" , city = "Dublin" , pipeline_stage = PipelineStage .NOT_CONTACTED ),
10097 ]
10198 db .add_all (customers )
10299 await db .flush ()
@@ -109,6 +106,9 @@ async def populate_demo_data(db: AsyncSession):
109106 description = "Fix leaking tap" ,
110107 status = JobStatus .COMPLETED ,
111108 value = 150.0 ,
109+ subtotal = 138.57 ,
110+ tax_amount = 11.43 ,
111+ tax_rate = 8.25 ,
112112 location = "123 Main St" ,
113113 employee_id = tech1 .id ,
114114 scheduled_at = datetime .now (timezone .utc ) - timedelta (days = 2 ),
@@ -121,6 +121,9 @@ async def populate_demo_data(db: AsyncSession):
121121 description = "Morning Repair" ,
122122 status = JobStatus .SCHEDULED ,
123123 value = 120.0 ,
124+ subtotal = 110.85 ,
125+ tax_amount = 9.15 ,
126+ tax_rate = 8.25 ,
124127 location = "45 Grafton St" ,
125128 employee_id = tech1 .id ,
126129 scheduled_at = datetime .now (timezone .utc ).replace (hour = 10 , minute = 0 , second = 0 , microsecond = 0 ) + timedelta (days = 1 )
@@ -132,6 +135,9 @@ async def populate_demo_data(db: AsyncSession):
132135 description = "Afternoon Install" ,
133136 status = JobStatus .SCHEDULED ,
134137 value = 300.0 ,
138+ subtotal = 277.14 ,
139+ tax_amount = 22.86 ,
140+ tax_rate = 8.25 ,
135141 location = "123 O'Connell St" ,
136142 employee_id = tech2 .id ,
137143 scheduled_at = datetime .now (timezone .utc ).replace (hour = 14 , minute = 0 , second = 0 , microsecond = 0 ) + timedelta (days = 1 )
@@ -143,6 +149,9 @@ async def populate_demo_data(db: AsyncSession):
143149 description = "John Boiler Repair" ,
144150 status = JobStatus .PENDING ,
145151 value = 500.0 ,
152+ subtotal = 461.89 ,
153+ tax_amount = 38.11 ,
154+ tax_rate = 8.25 ,
146155 location = "124 Main St" ,
147156 scheduled_at = datetime .now (timezone .utc ) + timedelta (days = 3 )
148157 )
@@ -153,6 +162,9 @@ async def populate_demo_data(db: AsyncSession):
153162 description = "Test Job" ,
154163 status = JobStatus .PENDING ,
155164 value = 100.0 ,
165+ subtotal = 92.38 ,
166+ tax_amount = 7.62 ,
167+ tax_rate = 8.25 ,
156168 location = "99 Test Rd" ,
157169 scheduled_at = datetime .now (timezone .utc ) + timedelta (days = 4 )
158170 )
@@ -163,6 +175,9 @@ async def populate_demo_data(db: AsyncSession):
163175 description = "Fix Leak" ,
164176 status = JobStatus .COMPLETED ,
165177 value = 150.0 ,
178+ subtotal = 138.57 ,
179+ tax_amount = 11.43 ,
180+ tax_rate = 8.25 ,
166181 location = "10 Temple Bar" ,
167182 scheduled_at = datetime .now (timezone .utc ) - timedelta (days = 1 )
168183 )
@@ -172,6 +187,9 @@ async def populate_demo_data(db: AsyncSession):
172187 description = "AC Service" ,
173188 status = JobStatus .SCHEDULED ,
174189 value = 200.0 ,
190+ subtotal = 184.76 ,
191+ tax_amount = 15.24 ,
192+ tax_rate = 8.25 ,
175193 location = "10 Temple Bar" ,
176194 scheduled_at = datetime .now (timezone .utc ) + timedelta (days = 2 )
177195 )
@@ -199,9 +217,9 @@ async def populate_demo_data(db: AsyncSession):
199217 business_id = business .id ,
200218 status = QuoteStatus .SENT ,
201219 total_amount = 500.0 ,
202- subtotal = 500.0 ,
203- tax_amount = 0.0 ,
204- tax_rate = 0.0 ,
220+ subtotal = 461.89 ,
221+ tax_amount = 38.11 ,
222+ tax_rate = 8.25 ,
205223 title = "Standard Maintenance" ,
206224 external_token = str (uuid .uuid4 ()),
207225 created_at = datetime .now (timezone .utc ) - timedelta (days = 3 )
@@ -230,6 +248,9 @@ async def populate_demo_data(db: AsyncSession):
230248 description = "Leaking pipe in kitchen" ,
231249 status = RequestStatus .PENDING ,
232250 urgency = Urgency .HIGH ,
251+ subtotal = 0 ,
252+ tax_amount = 0 ,
253+ tax_rate = 0 ,
233254 created_at = datetime .now (timezone .utc ) - timedelta (hours = 5 )
234255 )
235256 db .add (req1 )
@@ -309,7 +330,9 @@ async def reset_db(
309330 await conn .run_sync (Base .metadata .create_all )
310331
311332 # Re-populate
312- await populate_demo_data (db )
333+ if not current_user .clerk_id :
334+ raise HTTPException (status_code = 400 , detail = "Current user has no Clerk ID" )
335+ await populate_demo_data (db , current_user .clerk_id )
313336
314337 return {"status" : "SUCCESS" , "message" : "Database reset and demo data populated. You might need to sign in again if your user was deleted (but demo users were created)." }
315338 except Exception as e :
0 commit comments