WIP transaction precise

This commit is contained in:
Benjamin Loison 2024-10-03 21:22:30 +02:00
parent 31b81fa33e
commit 046835064d
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8
2 changed files with 23 additions and 38 deletions

View File

@ -14,55 +14,38 @@ PRINT_TRANSACTIONS = False
MAIN_BANK_ACCOUNT = 'compte_de_cheques'
# As far as I know there was no debit yet.
otherBankAccountsCredits = {}
debits = []
credits_ = []
# Precise bank account
allTransactions = []
for folder in os.listdir():#[-2:]:
def appendTransactions()
for folder in os.listdir():
if folder != MAIN_BANK_ACCOUNT:
print(folder)
for file in os.listdir(folder):#[-1:]:
for file in os.listdir(folder):
print(file)
filePath = f'{folder}/{file}'
initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath)
#print(totalMonthlyCredit)
#import json
#print(json.dumps(transactions, indent = 4))
otherBankAccountsCredits[fileDatetime] = otherBankAccountsCredits.get(fileDatetime, 0) + totalMonthlyCredit
_initialAmount, _totalMonthlyDebit, _totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath)
for transaction in transactions:
transaction['bank account'] = folder
allTransactions += [transaction]
#exit(1)
os.chdir(f'{MAIN_BANK_ACCOUNT}/')
totalMonthlyDebits = []
totalMonthlyCredits = []
totalMonthlyDifferences = []
totals = []
firstDatetime = None
lastDatetime = None
for folder in sorted(os.listdir()):
for file in sorted(os.listdir(folder)):
filePath = f'{folder}/{file}'
print(filePath)
initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath)
print('Initial amount', initialAmount)
print()
totals += [initialAmount]
print(f'Total monthly debit: {totalMonthlyDebit}')
print(f'Total monthly credit: {totalMonthlyCredit}')
totalMonthlyDebits += [totalMonthlyDebit]
otherBankAccountsCredit = otherBankAccountsCredits.get(fileDatetime, 0)
print(f'{otherBankAccountsCredit=}')
totalMonthlyCredit += otherBankAccountsCredit
totalMonthlyCredits += [totalMonthlyCredit]
totalMonthlyDifference = totalMonthlyCredit - totalMonthlyDebit
totalMonthlyDifferences += [totalMonthlyDifference]
for transaction in transactions:
transaction['bank account'] = MAIN_BANK_ACCOUNT
allTransactions += [transaction]
if PRINT_TRANSACTIONS:
for transaction in transactions:
# , transaction['currentAmount']
print(transaction['date'], transaction['valeur'], transaction['amount'])
print(transaction['comment'])
print()
if firstDatetime is None:
firstDatetime = fileDatetime
printTransaction(transaction)
#break
#break
lastDatetime = getDatetimeFromFileName(file)

View File

@ -29,12 +29,10 @@ def toFloat(group):
return float(group.replace(',', '.').replace(' ', ''))
def getDateFollowing(date, initialDate):
#print(f'start {date}')
date = datetime.strptime(date, '%d.%m').replace(year = initialDate.year)
# To support new year.
if date < initialDate:
date = date.replace(year = date.year + 1)
#print(f'end {date}')
return date
def readPdfBankStatement(filePath):
@ -57,8 +55,6 @@ def readPdfBankStatement(filePath):
if soldeCrediteurAuRegexMatch is not None or (line.startswith('Date Nature des opérations Valeur Débit Crédit') and not firstPage):
if soldeCrediteurAuRegexMatch is not None:
initialDate = datetime.strptime(soldeCrediteurAuRegexMatch.group(1), '%d.%m.%Y')
print(f'{initialDate=}')
#exit(1)
initialAmount = toFloat(soldeCrediteurAuRegexMatch.group(2))
#currentAmount = initialAmount
started = True
@ -106,3 +102,9 @@ def readPdfBankStatement(filePath):
'comment': '\n'.join(comment)
}]
return initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime
def printTransaction(transaction):
# , transaction['currentAmount']
print(transaction['date'], transaction['valeur'], transaction['amount'])
print(transaction['comment'])
print()