|
7 | 7 | import pandas
|
8 | 8 | import sqlmodel
|
9 | 9 |
|
10 |
| -from . import model, timetracking, dataviz |
| 10 | +from loguru import logger |
| 11 | + |
| 12 | +from . import model, timetracking, dataviz, rendering, invoicing, calendar, cloud |
11 | 13 |
|
12 | 14 |
|
13 | 15 | class App:
|
@@ -163,3 +165,54 @@ def duration_to_revenue(
|
163 | 165 | by=by,
|
164 | 166 | )
|
165 | 167 | return plot
|
| 168 | + |
| 169 | + def billing( |
| 170 | + self, |
| 171 | + project_tags, |
| 172 | + out_dir, |
| 173 | + period_start, |
| 174 | + period_end=None, |
| 175 | + timetracking_method="calendar", |
| 176 | + ): |
| 177 | + """Generate time sheets and invoices for a given period""" |
| 178 | + # TODO: read method from user settings |
| 179 | + if timetracking_method == "calendar": |
| 180 | + timetracking_calendar = calendar.ICloudCalendar( |
| 181 | + icloud=cloud.login_iCloud(user_name=self.user.icloud_account.user_name), |
| 182 | + # TODO: read from user settings |
| 183 | + name="TimeTracking", |
| 184 | + ) |
| 185 | + else: |
| 186 | + raise ValueError(f"unsupported time tracking method: {timetracking_method}") |
| 187 | + |
| 188 | + for i, tag in enumerate(project_tags): |
| 189 | + project = self.get_project(tag=tag) |
| 190 | + logger.info(f"generating timesheet for {project.title}") |
| 191 | + timesheet = timetracking.generate_timesheet( |
| 192 | + source=timetracking_calendar, |
| 193 | + project=project, |
| 194 | + period_start=period_start, |
| 195 | + period_end=period_end, |
| 196 | + item_description=project.title, |
| 197 | + ) |
| 198 | + rendering.render_timesheet( |
| 199 | + user=self.user, |
| 200 | + timesheet=timesheet, |
| 201 | + style="anvil", |
| 202 | + document_format="pdf", |
| 203 | + out_dir=out_dir, |
| 204 | + ) |
| 205 | + logger.info(f"generating invoice for {project.title}") |
| 206 | + invoice = invoicing.generate_invoice( |
| 207 | + timesheets=[timesheet], |
| 208 | + contract=project.contract, |
| 209 | + date=datetime.date.today(), |
| 210 | + counter=(i + 1), |
| 211 | + ) |
| 212 | + rendering.render_invoice( |
| 213 | + user=self.user, |
| 214 | + invoice=invoice, |
| 215 | + style="anvil", |
| 216 | + document_format="pdf", |
| 217 | + out_dir=out_dir, |
| 218 | + ) |
0 commit comments