1 febrer 2025
This commit is contained in:
@@ -28,7 +28,7 @@ def get_last_month_timestamps(date):
|
||||
year = int(date.split("-")[0])
|
||||
d = datetime(year, month, 1)
|
||||
end_date = d - timedelta(days=1)
|
||||
start_date = f"{end_date.year}-{end_date.month}-01"
|
||||
start_date = f"{end_date.year}-{end_date.month:02d}-01"
|
||||
return start_date, end_date.strftime("%Y-%m-%d")
|
||||
|
||||
def get_sum_balances(balances, account_prefix):
|
||||
@@ -94,6 +94,12 @@ def get_solvency_ratio(balances, min):
|
||||
result = round((get_net_worth(balances).number / total_assets.number) * 100, 2)
|
||||
return f"{bcolors.FAIL if result < min else bcolors.OKGREEN}{result} %{bcolors.ENDC}"
|
||||
|
||||
def get_interest_coverage_ratio(gross_monthly_income, debt_payments, mortgage_payments, min):
|
||||
interest = debt_payments.number + mortgage_payments.number
|
||||
interest = interest if interest > 0 else 1
|
||||
result = round(gross_monthly_income / interest, 2)
|
||||
return f"{bcolors.FAIL if result < min else bcolors.OKGREEN}{result}{bcolors.ENDC}"
|
||||
|
||||
def get_max_leveraged_investment(balances):
|
||||
total_assets = Amount.from_string(get_sum_balances(balances, "Assets:"))
|
||||
return Amount(round(total_assets.number * Decimal(0.9), 2), total_assets.currency).to_string()
|
||||
@@ -177,7 +183,7 @@ def print_report(date, balances, expenses, income, debt_payments, mortgage_payme
|
||||
["Savings Ratio", get_savings_ratio(balances, income, savings, 20), "20 %"],
|
||||
["Debt-Service Ratio", get_debt_service_ratio(balances, income, debt_payments, 35), "35 %"],
|
||||
["Non-Mortgage Debt-Service Ratio", get_non_mortgage_debt_service_ratio(balances, income, mortgage_payments, 15), "15 %"],
|
||||
["Solvency Ratio", get_solvency_ratio(balances, 50), "50 %"]
|
||||
["Interest Coverage Ratio", get_interest_coverage_ratio(income, debt_payments, mortgage_payments, 1.5), "1.5"]
|
||||
]))
|
||||
|
||||
def get_balances(entries, options, date):
|
||||
@@ -206,7 +212,7 @@ def get_income(entries, options, date):
|
||||
def get_debt_payments(entries, options, date):
|
||||
# FIX: Agafar nomes els pagaments de deute, enlloc de també les addicions de deute
|
||||
start_date, end_date = get_last_month_timestamps(date)
|
||||
debt_payments_query = f"SELECT convert(sum(position), \"EUR\") as position FROM date <= {end_date} WHERE account ~ 'Liabilities:' AND date >= {start_date}"
|
||||
debt_payments_query = f"SELECT convert(sum(position), \"EUR\") as position FROM date <= {end_date} WHERE account ~ 'Expenses:R4:Interessos' AND date >= {start_date}"
|
||||
mortgage_payments_query = f"SELECT convert(sum(position), \"EUR\") as position FROM date <= {end_date} WHERE account ~ 'Liabilities:Hipoteca:' AND date >= {start_date}"
|
||||
rtypes, rrows_debt = query.run_query(
|
||||
entries, options, debt_payments_query)
|
||||
|
||||
Reference in New Issue
Block a user