44from textwrap import dedent
55from pathlib import Path
66import webbrowser
7+ import pkgutil
78
89import flet
910from flet import (
@@ -90,13 +91,60 @@ def __init__(
9091 def update (self ):
9192 super ().update ()
9293
93- def add_demo_data (self , event ):
94+ def on_click_load_demo_data (self , event ):
9495 """Install the demo data on button click."""
9596 demo .add_demo_data (self .app .con )
9697 self .main_column .controls .clear ()
9798 self .main_column .controls .append (
9899 Text ("Demo data installed ☑️" ),
99100 )
101+
102+ logger .info ("Demo data installed" )
103+ self .app .snackbar_message ("Demo data installed" )
104+ self .update ()
105+
106+ self .main_column .controls .append (
107+ views .make_card (
108+ [
109+ Text (
110+ dedent (
111+ """
112+ 2. Navigate the menu on the left to explore the demo data.
113+ """
114+ )
115+ )
116+ ]
117+ )
118+ )
119+
120+ self .main_column .controls .append (
121+ views .make_card (
122+ [
123+ Text (
124+ dedent (
125+ """
126+ 3. Navigate to the "Invoicing" page to generate some invoices.
127+ """
128+ )
129+ )
130+ ]
131+ )
132+ )
133+
134+ self .main_column .controls .append (
135+ views .make_card (
136+ [
137+ Text (
138+ dedent (
139+ """
140+ 4. Please use the help menu on the top right to tell us about issues or suggestions.
141+ """
142+ )
143+ )
144+ ]
145+ )
146+ )
147+
100148 self .update ()
101149
102150 def build (self ):
@@ -125,7 +173,7 @@ def build(self):
125173 ElevatedButton (
126174 "Install demo data" ,
127175 icon = icons .TOYS ,
128- on_click = self .add_demo_data ,
176+ on_click = self .on_click_load_demo_data ,
129177 ),
130178 ]
131179 ),
@@ -247,18 +295,27 @@ def on_click_generate_invoices(self, event):
247295 f"generating invoice and timesheet for { self .project_select .value } "
248296 )
249297 logger .info ("Generate invoices clicked" )
250- if not self .calendar_file_path :
298+ if ( self .calendar_file_path is None ) and ( self . calendar_data is None ) :
251299 self .app .snackbar_message (f"Please select a calendar file" )
252300 logger .error ("No calendar file selected!" )
253301 return
254302 try :
255- self .app .con .billing (
256- project_tags = [self .project_select .value ],
257- period_start = str (self .date_from_select .get_date ()),
258- period_end = str (self .date_to_select .get_date ()),
259- timetracking_method = "file_calendar" ,
260- calendar_file_path = self .calendar_file_path ,
261- )
303+ if self .calendar_file_path :
304+ self .app .con .billing (
305+ project_tags = [self .project_select .value ],
306+ period_start = str (self .date_from_select .get_date ()),
307+ period_end = str (self .date_to_select .get_date ()),
308+ timetracking_method = "file_calendar" ,
309+ calendar_file_path = self .calendar_file_path ,
310+ )
311+ elif self .calendar_data :
312+ self .app .con .billing (
313+ project_tags = [self .project_select .value ],
314+ period_start = str (self .date_from_select .get_date ()),
315+ period_end = str (self .date_to_select .get_date ()),
316+ timetracking_method = "file_calendar" ,
317+ calendar_file_content = self .calendar_data ,
318+ )
262319 self .app .snackbar_message (
263320 f"created invoice and timesheet for { self .project_select .value } - open the invoice folder to see the result"
264321 )
@@ -285,12 +342,12 @@ def on_click_open_invoice_folder(self, event):
285342
286343 def on_click_load_demo_calendar (self , event ):
287344 """Load the demo calendar file."""
288- self .calendar_file_path = Path (__file__ ).parent .parent / Path (
289- "tuttle_tests/data/TuttleDemo-TimeTracking.ics"
290- )
291- self .app .snackbar_message (
292- f"Loaded demo calendar file: { self .calendar_file_path } "
345+ self .calendar_data = pkgutil .get_data (
346+ "tuttle_tests" , "data/TuttleDemo-TimeTracking.ics"
293347 )
348+ assert len (self .calendar_data ) > 0
349+ logger .info (f"Loaded demo calendar file" )
350+ self .app .snackbar_message (f"Loaded demo calendar file" )
294351
295352 def update_content (self ):
296353 super ().update_content ()
0 commit comments