Skip to content

Commit 3405ccc

Browse files
committed
checkpoint: before debugging
1 parent 5763268 commit 3405ccc

File tree

5 files changed

+71
-23
lines changed

5 files changed

+71
-23
lines changed

app/core/database_storage_impl.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
from typing import Callable
2+
13
import re
24
from pathlib import Path
3-
from loguru import logger
4-
from typing import Callable
5-
import demo
5+
66
import sqlmodel
7+
from loguru import logger
8+
9+
from tuttle import demo
10+
711
from .abstractions import DatabaseStorage
812

913

app/invoicing/intent.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def __init__(self, client_storage: ClientStorage):
4545
self._user_data_source = UserDataSource()
4646
self._auth_intent = AuthIntent()
4747

48+
def get_user(self) -> IntentResult[User]:
49+
user = self._user_data_source.get_user()
50+
return IntentResult(was_intent_successful=True, data=user)
51+
4852
def get_active_projects_as_map(self) -> Mapping[int, Project]:
4953
return self._projects_intent.get_active_projects_as_map()
5054

@@ -115,6 +119,7 @@ def create_invoice(
115119
if render:
116120
# render timesheet
117121
try:
122+
logger.info(f"⚙️ Rendering timesheet for {project.title}...")
118123
rendering.render_timesheet(
119124
user=user,
120125
timesheet=timesheet,
@@ -129,6 +134,7 @@ def create_invoice(
129134
logger.exception(ex)
130135
# render invoice
131136
try:
137+
logger.info(f"⚙️ Rendering invoice for {project.title}...")
132138
rendering.render_invoice(
133139
user=user,
134140
invoice=invoice,

tuttle/demo.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,22 @@ def create_fake_contact(
5454
split_address_lines = fake.address().splitlines()
5555
street_line = split_address_lines[0]
5656
city_line = split_address_lines[1]
57+
try:
58+
# TODO: This has a German bias
59+
street = street_line.split(" ", 1)[0]
60+
number = street_line.split(" ", 1)[1]
61+
city = city_line.split(" ")[1]
62+
postal_code = city_line.split(" ")[0]
63+
except IndexError:
64+
street = street_line
65+
number = ""
66+
city = city_line
67+
postal_code = ""
5768
a = Address(
58-
street=street_line,
59-
number=city_line,
60-
city=city_line.split(" ")[1],
61-
postal_code=city_line.split(" ")[0],
69+
street=street,
70+
number=number,
71+
city=city,
72+
postal_code=postal_code,
6273
country=fake.country(),
6374
)
6475
first_name, last_name = fake.name().split(" ", 1)
@@ -212,6 +223,9 @@ def create_fake_invoice(
212223
if project is None:
213224
project = create_fake_project(fake)
214225

226+
if user is None:
227+
user = create_fake_user(fake)
228+
215229
invoice_number = next(invoice_number_counter)
216230
invoice = Invoice(
217231
number=str(invoice_number),
@@ -243,7 +257,11 @@ def create_fake_invoice(
243257
invoice=invoice,
244258
)
245259

260+
# an invoice is created together with a timesheet. For the sake of simplicity, timesheet and invoice items are not linked.
261+
timesheeet = create_fake_timesheet(fake, project)
262+
246263
if render:
264+
# render invoice
247265
try:
248266
rendering.render_invoice(
249267
user=user,
@@ -255,6 +273,18 @@ def create_fake_invoice(
255273
except Exception as ex:
256274
logger.error(f"❌ Error rendering invoice for {project.title}: {ex}")
257275
logger.exception(ex)
276+
# render timesheet
277+
try:
278+
rendering.render_timesheet(
279+
user=user,
280+
timesheet=timesheeet,
281+
out_dir=Path.home() / ".tuttle" / "Timesheets",
282+
only_final=True,
283+
)
284+
logger.info(f"✅ rendered timesheet for {project.title}")
285+
except Exception as ex:
286+
logger.error(f"❌ Error rendering timesheet for {project.title}: {ex}")
287+
logger.exception(ex)
258288

259289
return invoice
260290

@@ -281,11 +311,15 @@ def create_fake_data(
281311
fake = faker.Faker(locale=locales)
282312

283313
contacts = [create_fake_contact(fake) for _ in range(n)]
284-
clients = [create_fake_client(contact, fake) for contact in contacts]
285-
contracts = [create_fake_contract(client, fake) for client in clients]
286-
projects = [create_fake_project(contract, fake) for contract in contracts]
314+
clients = [
315+
create_fake_client(fake, invoicing_contact=contact) for contact in contacts
316+
]
317+
contracts = [create_fake_contract(fake, client=client) for client in clients]
318+
projects = [create_fake_project(fake, contract=contract) for contract in contracts]
287319

288-
invoices = [create_fake_invoice(project, user, fake) for project in projects]
320+
invoices = [
321+
create_fake_invoice(fake, project=project, user=user) for project in projects
322+
]
289323

290324
return projects, invoices
291325

tuttle/invoicing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ def generate_invoice(
3737
VAT_rate=contract.VAT_rate,
3838
description=timesheet.title,
3939
)
40+
# attach timesheet to invoice
41+
timesheet.invoice = invoice
4042
# TODO: replace with auto-incrementing numbers
4143
invoice.generate_number(counter=counter)
4244
return invoice

tuttle/model.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,12 @@ class Timesheet(SQLModel, table=True):
499499
description="Whether the Timesheet has been rendered as a PDF.",
500500
)
501501

502-
# Timesheet 1:1 Invoice
503-
# FIXME: Could not determine join condition between parent/child tables
504-
# invoice_id: Optional[int] = Field(default=None, foreign_key="invoice.id")
505-
# invoice: Optional["Invoice"] = OneToOneRelationship(
506-
# back_populates="timesheet",
507-
# )
502+
# Timesheet n:1 Invoice
503+
invoice_id: Optional[int] = Field(default=None, foreign_key="invoice.id")
504+
invoice: Optional["Invoice"] = Relationship(
505+
back_populates="timesheets",
506+
sa_relationship_kwargs={"lazy": "subquery"},
507+
)
508508

509509
# class Config:
510510
# arbitrary_types_allowed = True
@@ -535,12 +535,8 @@ class Invoice(SQLModel, table=True):
535535
description="The date of the invoice",
536536
)
537537

538-
# TODO: sent_date: datetime.datetime = Field(description="The date the invoice was sent.")
539-
# Invoice 1:1 Timesheet
540-
# timesheet_id: Optional[int] = Field(default=None, foreign_key="timesheet.id")
541-
# timesheet: Timesheet = OneToOneRelationship(
542-
# back_populates="invoice",
543-
# )
538+
# RELATIONSHIPTS
539+
544540
# Invoice n:1 Contract ?
545541
contract_id: Optional[int] = Field(default=None, foreign_key="contract.id")
546542
contract: Contract = Relationship(
@@ -553,6 +549,12 @@ class Invoice(SQLModel, table=True):
553549
back_populates="invoices",
554550
sa_relationship_kwargs={"lazy": "subquery"},
555551
)
552+
# Invoice 1:n Timesheet
553+
timesheets: List[Timesheet] = Relationship(
554+
back_populates="invoice",
555+
sa_relationship_kwargs={"lazy": "subquery"},
556+
)
557+
556558
# status -- corresponds to InvoiceStatus enum above
557559
sent: Optional[bool] = Field(default=False)
558560
paid: Optional[bool] = Field(default=False)

0 commit comments

Comments
 (0)