2222
2323import geno .settings as geno_settings
2424from cohiva .utils .pdf import PdfGenerator
25- from finance .accounting import Account , AccountingManager , AccountKey
25+ from finance .accounting import Account , AccountingBook , AccountingManager , AccountKey
2626
2727from .models import (
2828 Address ,
@@ -71,6 +71,7 @@ def create_invoices(
7171 ) # name="Mietzins wiederkehrend")
7272
7373 messages = []
74+ count = {"invoices" : 0 , "contracts" : 0 }
7475 with AccountingManager (messages ) as book :
7576 if not book :
7677 return messages
@@ -86,8 +87,10 @@ def create_invoices(
8687 )
8788 if isinstance (result , str ):
8889 return result
89- count = result
90- messages .append ("%s Rechnungen" % count )
90+ if result > 0 :
91+ count ["invoices" ] += result
92+ count ["contracts" ] += 1
93+ messages .append (f"{ count ['invoices' ]} Rechnungen für { count ['contracts' ]} Verträge" )
9194 return messages
9295
9396
@@ -529,13 +532,13 @@ def setup_account(account, contract):
529532 account .set_code (building = ru .building )
530533 else :
531534 logger .error (
532- "Could not find building for contract %s, using default account with no postfix %s. "
533- % ( contract , account .prefix )
535+ f "Could not find building for contract id { contract . pk } , "
536+ f" using default account with no postfix { account .prefix } ."
534537 )
535538 send_error_mail (
536539 "get_income_account_code()" ,
537- "Could not find building for contract %s, using default account with no postfix %s. "
538- % ( contract , account .prefix ) ,
540+ f "Could not find building for contract id { contract . pk } , "
541+ f"using default account with no postfix { account .prefix } ." ,
539542 )
540543 return account
541544
@@ -685,24 +688,25 @@ def add_invoice_obj(
685688
686689def delete_invoice_transaction (invoice ):
687690 if not invoice .fin_transaction_ref :
688- logger .warning ("Trying to delete an invoice without a fin_transaction_ref: %s" % invoice )
691+ logger .warning (f "Trying to delete an invoice without a fin_transaction_ref: { invoice . pk } " )
689692 return None
690693 try :
691- with AccountingManager () as book :
694+ book_type_id , _ = AccountingBook .decode_transaction_id (invoice .fin_transaction_ref )
695+ with AccountingManager (book_type_id = book_type_id ) as book :
692696 book .delete_transaction (invoice .fin_transaction_ref )
693697 except Exception :
694698 logger .error (
695- "Could not delete transaction %s linked to invoice %s. "
696- % ( invoice . fin_transaction_ref , invoice )
699+ f "Could not delete transaction { invoice . fin_transaction_ref } "
700+ f"linked to invoice { invoice . pk } ."
697701 )
698702 send_error_mail (
699703 "delete_invoice_transaction()" ,
700- "Could not delete transaction %s linked to invoice %s. "
701- % ( invoice . fin_transaction_ref , invoice ) ,
704+ f "Could not delete transaction { invoice . fin_transaction_ref } "
705+ f"linked to invoice { invoice . pk } ." ,
702706 )
703707 return None
704708 logger .info (
705- "Deleted fin_transaction_ref %s for invoice %s." % ( invoice . fin_transaction_ref , invoice )
709+ f "Deleted fin_transaction_ref { invoice . fin_transaction_ref } for invoice { invoice . pk } ."
706710 )
707711 return None
708712
0 commit comments