Skip to content

Commit 385c9af

Browse files
committed
WIP: demo invoice workflow
1 parent 016cc20 commit 385c9af

File tree

4 files changed

+150
-10
lines changed

4 files changed

+150
-10
lines changed

app/Tuttle.py

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from loguru import logger
2+
from textwrap import dedent
23

34
import flet
45
from flet import (
@@ -14,17 +15,14 @@
1415
TextButton,
1516
Icon,
1617
Dropdown,
17-
dropdown,
18+
Markdown,
1819
)
19-
from flet import icons, colors
20+
from flet import icons, colors, dropdown
2021

2122
from layout import DesktopAppLayout
2223

2324
import views
24-
from views import (
25-
ContactView,
26-
ContactView2,
27-
)
25+
import widgets
2826

2927
from tuttle.controller import Controller
3028
from tuttle.model import (
@@ -171,6 +169,8 @@ def update_content(self):
171169

172170

173171
class InvoicingPage(AppPage):
172+
"""A page for the invoicing workflow."""
173+
174174
def __init__(
175175
self,
176176
app: App,
@@ -194,13 +194,75 @@ def update_content(self):
194194
autofocus=True,
195195
)
196196

197-
self.main_column.controls.append(
197+
date_from_select = widgets.DateSelector()
198+
date_to_select = widgets.DateSelector()
199+
200+
self.main_column.controls = [
201+
Row(
202+
[
203+
Text("Invoicing Workflow Demo", style="headlineMedium"),
204+
]
205+
),
198206
Row(
199207
[
208+
views.make_card(
209+
[
210+
Text(
211+
dedent(
212+
"""
213+
1. select a time tracking data source
214+
"""
215+
)
216+
)
217+
]
218+
)
219+
]
220+
),
221+
Row(
222+
[
223+
views.make_card(
224+
[
225+
Text(
226+
dedent(
227+
"""
228+
2. select a project and date range
229+
"""
230+
)
231+
)
232+
]
233+
)
234+
]
235+
),
236+
Row(
237+
[
238+
Icon(icons.WORK),
200239
project_select,
201240
]
202-
)
203-
)
241+
),
242+
Row(
243+
[
244+
# Icon(icons.DATE_RANGE),
245+
date_from_select,
246+
Icon(icons.ARROW_FORWARD),
247+
date_to_select,
248+
TextButton(
249+
"Select",
250+
on_click=lambda event: logger.info(
251+
f"Selected date range: {date_from_select.get_date()} -> {date_to_select.get_date()}"
252+
),
253+
),
254+
]
255+
),
256+
Row(
257+
[
258+
ElevatedButton(
259+
"Generate invoice",
260+
icon=icons.EDIT_NOTE,
261+
# on_click=self.add_demo_data,
262+
),
263+
]
264+
),
265+
]
204266
self.update()
205267

206268

app/views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Optional, List, Tuple
2+
import datetime
3+
14
from flet import (
25
UserControl,
36
Card,
@@ -222,3 +225,14 @@ def make_project_view(project: Project):
222225
padding=10,
223226
)
224227
)
228+
229+
230+
def make_card(content):
231+
"""Make a card with the given content."""
232+
return Card(
233+
Container(
234+
Row(content),
235+
padding=10,
236+
expand=True,
237+
)
238+
)

app/widgets.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import datetime
2+
3+
from flet import (
4+
UserControl,
5+
Container,
6+
Row,
7+
Icon,
8+
IconButton,
9+
Text,
10+
Dropdown,
11+
)
12+
from flet import icons, colors, dropdown
13+
14+
15+
class DateSelector(UserControl):
16+
"""Timeframe selector."""
17+
18+
def __init__(self):
19+
super().__init__()
20+
21+
self.day_dropdown = Dropdown(
22+
label="D",
23+
options=[dropdown.Option(day) for day in range(1, 32)],
24+
width=50,
25+
)
26+
27+
self.month_dropdown = Dropdown(
28+
label="M",
29+
options=[dropdown.Option(month) for month in range(1, 13)],
30+
width=50,
31+
)
32+
33+
self.year_dropdown = Dropdown(
34+
label="Y",
35+
options=[dropdown.Option(year) for year in range(2015, 2025)],
36+
width=100,
37+
)
38+
39+
self.view = Container(
40+
content=Row(
41+
[
42+
Icon(
43+
icons.CALENDAR_MONTH,
44+
),
45+
self.day_dropdown,
46+
self.month_dropdown,
47+
self.year_dropdown,
48+
],
49+
alignment="center",
50+
),
51+
padding=10,
52+
)
53+
54+
def build(self):
55+
return self.view
56+
57+
def get_date(self) -> datetime.date:
58+
"""Return the selected timeframe."""
59+
date = datetime.date(
60+
year=int(self.year_dropdown.value),
61+
month=int(self.month_dropdown.value),
62+
day=int(self.day_dropdown.value),
63+
)
64+
return date

tuttle/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def query(self, entity_type: Type[SQLModel]):
111111
sqlmodel.select(entity_type),
112112
).all()
113113
if len(entities) == 0:
114-
logger.warning("No instances of {entity_type} found")
114+
logger.warning(f"No instances of {entity_type} found")
115115
else:
116116
logger.info(f"Found {len(entities)} instances of {entity_type}")
117117
return entities

0 commit comments

Comments
 (0)