27 desembre
This commit is contained in:
@@ -92,13 +92,14 @@ def get_investment_assets_to_net_worth_ratio(balances, min):
|
||||
return f"{bcolors.FAIL if result < min else bcolors.OKGREEN}{result} %{bcolors.ENDC}"
|
||||
|
||||
|
||||
def get_liquid_assets_to_net_worth_ratio(balances, min):
|
||||
def get_liquid_assets_to_net_worth_ratio(balances, pignorat, min):
|
||||
liquid = 0
|
||||
for account, balance in balances.items():
|
||||
if account.startswith("Assets:Liquid") or account.startswith("Assets:Invest"):
|
||||
liquid = balance if liquid == 0 else liquid + balance
|
||||
total_liquid = Amount(Decimal(0), "EUR") if liquid.get_only_position(
|
||||
) == None else liquid.get_only_position().units
|
||||
total_liquid = sub(total_liquid, Amount(pignorat, 'EUR'))
|
||||
result = round(
|
||||
(total_liquid.number / get_net_worth(balances).number) * 100, 2)
|
||||
return f"{bcolors.FAIL if result < min else bcolors.OKGREEN}{result} %{bcolors.ENDC}"
|
||||
@@ -148,18 +149,18 @@ def get_position_as_str(inventory):
|
||||
return Amount(Decimal(round(position.units.number, 2)), position.units.currency).to_string()
|
||||
|
||||
|
||||
def print_report(date, balances, expenses, net_monthly_income, net_yearly_income, debt_payments, mortgage_payments, savings):
|
||||
def print_report(date, balances, expenses, net_monthly_income, net_yearly_income, debt_payments, mortgage_payments, savings, pignorat):
|
||||
print(f"{bcolors.BOLD}Balance Sheet (date={date}){bcolors.ENDC}")
|
||||
draw_line()
|
||||
print(f"{bcolors.BOLD}Assets{bcolors.ENDC}")
|
||||
print(f"\t{bcolors.BOLD}Liquids{bcolors.ENDC}")
|
||||
print(f"\t{bcolors.BOLD}Comptes bancaris{bcolors.ENDC}")
|
||||
print(tabulate([
|
||||
["Corrent", get_sum_balances(
|
||||
balances, "Assets:Liquid:Caixabank:Corrent")],
|
||||
["Estalvi", get_sum_balances(balances, "Assets:Liquid:Estalvi")],
|
||||
["Compte d'inversió", get_sum_balances(
|
||||
balances, "Assets:Liquid:R4:EUR")],
|
||||
["Total líquids", get_sum_balances(balances, "Assets:Liquid:")],
|
||||
["Total", get_sum_balances(balances, "Assets:Liquid:")],
|
||||
]))
|
||||
print(f"\t{bcolors.BOLD}Inversions{bcolors.ENDC}")
|
||||
print(tabulate([
|
||||
@@ -169,6 +170,10 @@ def print_report(date, balances, expenses, net_monthly_income, net_yearly_income
|
||||
["Renta fixa", get_sum_balances(balances, "Assets:Invest:Fixed:")],
|
||||
["Total inversions", get_sum_balances(balances, "Assets:Invest:")],
|
||||
]))
|
||||
print(tabulate([
|
||||
["Inversions pignorades", Amount(
|
||||
round(pignorat, 2), 'EUR').to_string()],
|
||||
]))
|
||||
print(f"\t{bcolors.BOLD}Propietat personal{bcolors.ENDC}")
|
||||
print(tabulate([
|
||||
["Vivenda principal", get_sum_balances(
|
||||
@@ -241,7 +246,7 @@ def print_report(date, balances, expenses, net_monthly_income, net_yearly_income
|
||||
["Investment Assets to Net Worth Ratio",
|
||||
get_investment_assets_to_net_worth_ratio(balances, 50), "50 %"],
|
||||
["Liquid Assets to Net Worth Ratio",
|
||||
get_liquid_assets_to_net_worth_ratio(balances, 15), "15 %"],
|
||||
get_liquid_assets_to_net_worth_ratio(balances, pignorat, 15), "15 %"],
|
||||
["Savings Ratio", get_savings_ratio(
|
||||
balances, net_yearly_income, savings, 20), "20 %"],
|
||||
["Debt-Service Ratio",
|
||||
@@ -328,6 +333,22 @@ def get_savings(entries, options, date):
|
||||
return result
|
||||
|
||||
|
||||
def get_assets_pignorats(entries, options, date):
|
||||
assets_pignorats = {
|
||||
'R4RF': Decimal(1518.57),
|
||||
'VANEMMK': Decimal(14.99),
|
||||
'VANGL': Decimal(260)
|
||||
}
|
||||
result = Decimal(0)
|
||||
for _, curr in enumerate(assets_pignorats):
|
||||
pignorat_query = f"SELECT DISTINCT GETPRICE('{curr}', 'EUR', {
|
||||
date}) as price"
|
||||
rtypes, rrows = query.run_query(
|
||||
entries, options, pignorat_query)
|
||||
result = result + rrows[0].price * assets_pignorats[curr]
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Generate balance sheet report')
|
||||
@@ -350,8 +371,9 @@ def main():
|
||||
debt_payments, mortgage_payments = get_debt_payments(
|
||||
entries, options, date)
|
||||
savings = get_savings(entries, options, date)
|
||||
pignorat = get_assets_pignorats(entries, options, date)
|
||||
print_report(date, balances, expenses, net_monthly_income, net_yearly_income,
|
||||
debt_payments, mortgage_payments, savings)
|
||||
debt_payments, mortgage_payments, savings, pignorat)
|
||||
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user