|
4 | 4 | import sys
|
5 | 5 | import datetime
|
6 | 6 | from typing import Type
|
| 7 | +import platform |
| 8 | +import subprocess |
7 | 9 |
|
8 | 10 | import pandas
|
9 | 11 | import sqlmodel
|
@@ -257,6 +259,8 @@ def billing(
|
257 | 259 | period_end=period_end,
|
258 | 260 | item_description=project.title,
|
259 | 261 | )
|
| 262 | + # FIXME: store timesheet |
| 263 | + # self.store(timesheet) |
260 | 264 | logger.info(f"✅ timesheet generated for {project.title}")
|
261 | 265 | try:
|
262 | 266 | rendering.render_timesheet(
|
@@ -289,3 +293,40 @@ def billing(
|
289 | 293 | except Exception as ex:
|
290 | 294 | logger.error(f"❌ Error rendering invoice for {project.title}: {ex}")
|
291 | 295 | logger.exception(ex)
|
| 296 | + # finally store invoice |
| 297 | + self.store(invoice) |
| 298 | + |
| 299 | + def open_invoice(self, invoice): |
| 300 | + """Open an invoice in the default application for PDF files""" |
| 301 | + invoice_file_path = ( |
| 302 | + self.home |
| 303 | + / self.preferences.invoice_dir |
| 304 | + / Path(invoice.prefix) |
| 305 | + / Path(f"{invoice.prefix}.pdf") |
| 306 | + ) |
| 307 | + if invoice_file_path.exists(): |
| 308 | + if platform.system() == "Darwin": # macOS |
| 309 | + subprocess.call(("open", invoice_file_path)) |
| 310 | + elif platform.system() == "Windows": # Windows |
| 311 | + os.startfile(invoice_file_path) |
| 312 | + else: # linux variants |
| 313 | + subprocess.call(("xdg-open", invoice_file_path)) |
| 314 | + |
| 315 | + else: |
| 316 | + logger.error(f"invoice file {invoice_file_path} not found") |
| 317 | + |
| 318 | + def quicklook_invoice(self, invoice): |
| 319 | + """Open an invoice in the preview application for PDF files""" |
| 320 | + invoice_file_path = ( |
| 321 | + self.home |
| 322 | + / self.preferences.invoice_dir |
| 323 | + / Path(invoice.prefix) |
| 324 | + / Path(f"{invoice.prefix}.pdf") |
| 325 | + ) |
| 326 | + if invoice_file_path.exists(): |
| 327 | + if platform.system() == "Darwin": # macOS |
| 328 | + subprocess.call(["qlmanage", "-p", invoice_file_path]) |
| 329 | + else: |
| 330 | + logger.error(f"quicklook not supported on {platform.system()}") |
| 331 | + else: |
| 332 | + logger.error(f"invoice file {invoice_file_path} not found") |
0 commit comments