1313
1414from loguru import logger
1515
16- from . import model , timetracking , dataviz , rendering , invoicing , calendar , cloud
16+ from . import (
17+ model ,
18+ timetracking ,
19+ dataviz ,
20+ rendering ,
21+ invoicing ,
22+ calendar ,
23+ cloud ,
24+ os_functions ,
25+ )
1726from .preferences import Preferences
27+ from .model import (
28+ User ,
29+ Project ,
30+ Contract ,
31+ Invoice ,
32+ )
1833
1934
2035class Controller :
@@ -296,13 +311,16 @@ def billing(
296311 # finally store invoice
297312 self .store (invoice )
298313
299- def open_invoice (self , invoice ):
314+ def open_invoice (
315+ self ,
316+ invoice : Invoice ,
317+ ):
300318 """Open an invoice in the default application for PDF files"""
301319 invoice_file_path = (
302320 self .home
303321 / self .preferences .invoice_dir
304322 / Path (invoice .prefix )
305- / Path (f" { invoice .prefix } .pdf" )
323+ / Path (invoice .file_name )
306324 )
307325 if invoice_file_path .exists ():
308326 if platform .system () == "Darwin" : # macOS
@@ -315,13 +333,16 @@ def open_invoice(self, invoice):
315333 else :
316334 logger .error (f"invoice file { invoice_file_path } not found" )
317335
318- def quicklook_invoice (self , invoice ):
336+ def quicklook_invoice (
337+ self ,
338+ invoice : Invoice ,
339+ ):
319340 """Open an invoice in the preview application for PDF files"""
320341 invoice_file_path = (
321342 self .home
322343 / self .preferences .invoice_dir
323344 / Path (invoice .prefix )
324- / Path (f" { invoice .prefix } .pdf" )
345+ / Path (invoice .file_name )
325346 )
326347 if invoice_file_path .exists ():
327348 if platform .system () == "Darwin" : # macOS
@@ -330,3 +351,28 @@ def quicklook_invoice(self, invoice):
330351 logger .error (f"quicklook not supported on { platform .system ()} " )
331352 else :
332353 logger .error (f"invoice file { invoice_file_path } not found" )
354+
355+ def send_invoice (self , invoice : Invoice ):
356+ """Compose an email to the client with the invoice attached"""
357+ invoice_file_path = (
358+ self .home
359+ / self .preferences .invoice_dir
360+ / Path (invoice .prefix )
361+ / Path (invoice .file_name )
362+ )
363+ if invoice_file_path .exists ():
364+ if platform .system () == "Darwin" :
365+ email = invoicing .generate_invoice_email (
366+ invoice ,
367+ self .user ,
368+ )
369+ os_functions .compose_email (
370+ recipient = email ["recipient" ],
371+ subject = email ["subject" ],
372+ body = email ["body" ],
373+ attachment_path = invoice_file_path ,
374+ )
375+ else :
376+ logger .error (f"emailing not yet supported on { platform .system ()} " )
377+ else :
378+ logger .error (f"invoice file { invoice_file_path } not found" )
0 commit comments