Skip to content

Commit

Permalink
Convert flows to target currency (#11)
Browse files Browse the repository at this point in the history
* Convert flows to target currency

* show error message if currency conversion fails

* fix tests
  • Loading branch information
andreasgerstmayr authored Mar 10, 2024
1 parent e9f0ba9 commit 405b96c
Show file tree
Hide file tree
Showing 10 changed files with 3,533 additions and 59 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ test-js-update:
run:
cd example; pipenv run fava example.beancount

run-debug:
cd example; pipenv run fava --debug example.beancount

format:
cd frontend; npx prettier -w . ../src/fava_portfolio_returns/templates/*.css
cd example; pipenv run black ../src/fava_portfolio_returns/__init__.py
cd example; find . -name '*.beancount' -exec pipenv run bean-format -c 59 -o "{}" "{}" \;

ci:
make build-js
make run &
make test-js

make format
git diff --exit-code
12 changes: 11 additions & 1 deletion example/beangrow.pbtxt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ groups {
name: "CORP"
investment: "Assets:US:ETrade:CORP"
}
group {
name: "CORP (converted to EUR)"
investment: "Assets:US:ETrade:CORP"
currency: "EUR"
}
group {
name: "CORPEUR"
investment: "Assets:US:ETrade:CORPEUR"
Expand All @@ -87,5 +92,10 @@ groups {
name: "CORPSPL"
investment: "Assets:US:ETrade:CORPSPL"
}
group {
name: "CORP (all)"
investment: "Assets:US:ETrade:CORP"
investment: "Assets:US:ETrade:CORPEUR"
currency: "USD"
}
}

3 changes: 3 additions & 0 deletions example/example.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -5138,6 +5138,8 @@ plugin "beancount.plugins.implicit_prices"
2022-02-18 price VHT 240.66 USD
2022-02-18 price GLD 144.57 USD

2023-01-01 price EUR 2.00 USD


* Test Stock CORP

Expand Down Expand Up @@ -5215,6 +5217,7 @@ plugin "beancount.plugins.implicit_prices"
; Income:US:ETrade:PnL ; 190 USD

2023-08-01 price CORP 3 USD
2023-08-01 price CORP 1.50 EUR

; 2023-08-01
; 0 CORP
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export function getCurrencyFormatter(currency: string) {
const currencyFormat = new Intl.NumberFormat(undefined, {
style: "currency",
currency,
});
return (value: any) => {
return currencyFormat.format(value);
};
export function getCurrencyFormatter(currency: string): (value: any) => string {
try {
return new Intl.NumberFormat(undefined, { style: "currency", currency }).format;
} catch {
return new Intl.NumberFormat().format;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/tests/e2e/__image_snapshots__/report_overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 405b96c

Please sign in to comment.