Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
dvorak0 committed Jan 22, 2024
1 parent ba3ffe9 commit 46e8c09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# fava-monthly-expenses

## Screenshot
![screenshot](./showcase.webm)
## Get Started
add this line to your main beancount file:

Expand Down
12 changes: 3 additions & 9 deletions monthly_expenses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class MonthlyExpenses(FavaExtensionBase): # pragma: no cover

report_title = "Monthly Expenses"

def valid(self):
return "ok" if "account_used_to_get_valid_month" in self.config else "missing account_used_to_get_valid_month"


def get_all_report(self):
return [self.build_report_for_account(account) for account in self.config['accounts']]

Expand Down Expand Up @@ -54,7 +50,7 @@ def build_report_for_account(self, account):
entries = self.ledger.all_entries
opts = self.ledger.options
if "operating_currency" not in opts or len(opts["operating_currency"]) == 0:
return "","","",account,"missing operating_currency"
return "", "", "" ,account, "missing operating_currency"
currency = opts["operating_currency"][0]
cols, rows = run_query(entries, opts,
f"SELECT account, YEAR(date) AS year, convert(sum(position),'{currency}') AS amount\
Expand All @@ -70,7 +66,7 @@ def build_report_for_account(self, account):
df = df.replace({'month_count': month_count})
print(df)
if df.empty:
return "","","",account,"no transaction under this account"
return "" ,"" ,"" ,account , "no transaction under this account"
df[f'amount ({currency})'] = df[f'amount ({currency})'] / df['month_count']
df = df.drop(columns=['month_count'])
df.rename(columns={"account": "Account", "year": "Year", f"amount ({currency})": f"Amount ({currency})"}, inplace=True)
Expand All @@ -82,9 +78,7 @@ def build_report_for_account(self, account):
n_levels = df["Account"].str.count(":").max() + 1

if n_levels == account.count(":") + 1:
print("account is at the lowest level")
return "","","",account,"no finer level under this account"

return "", "", "", account, "no finer level under this account"

cols = ["Account_L{}".format(k) for k in range(n_levels)]
df[cols] = df["Account"].str.split(':', n=n_levels - 1, expand=True)
Expand Down

0 comments on commit 46e8c09

Please sign in to comment.