diff --git a/fava_investor/common/beancountinvestorapi.py b/fava_investor/common/beancountinvestorapi.py index 7d36ec4..2157482 100644 --- a/fava_investor/common/beancountinvestorapi.py +++ b/fava_investor/common/beancountinvestorapi.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from beancount.core import convert from beancount import loader from beancount.core import getters from beancount.core import prices @@ -14,6 +15,7 @@ class AccAPI: def __init__(self, beancount_file, options): self.entries, _, self.options_map = loader.load_file(beancount_file) self.options = options + self.convert_position = convert.convert_position def end_date(self): return None # Only used in fava (UI selection context) diff --git a/fava_investor/common/favainvestorapi.py b/fava_investor/common/favainvestorapi.py index 849787e..8b31a16 100644 --- a/fava_investor/common/favainvestorapi.py +++ b/fava_investor/common/favainvestorapi.py @@ -1,13 +1,18 @@ from beancount.core import getters -from fava.template_filters import cost_or_value +# from fava.template_filters import cost_or_value from fava import __version__ as fava_version from packaging import version from fava.context import g +from fava.core.conversion import convert_position +from beancount.core import realization class FavaInvestorAPI: + def __init__(self): + self.convert_position = convert_position + def build_price_map(self): - return g.ledger.price_map + return g.ledger.prices def build_filtered_price_map(self, pcur, base_currency): """pcur and base_currency are currency strings""" @@ -20,7 +25,7 @@ def get_commodity_directives(self): return {entry.currency: entry for entry in g.filtered.ledger.all_entries_by_type.Commodity} def realize(self): - return g.filtered.root_account + return realization.realize(g.filtered.entries) def root_tree(self): return g.filtered.root_tree @@ -48,7 +53,7 @@ def get_account_open(self): # TODO: below is probably fava only, and needs to be made beancount friendly return g.ledger.all_entries_by_type.Open - def cost_or_value(self, node, date, include_children): - if include_children: - return cost_or_value(node.balance_children, date) - return cost_or_value(node.balance, date) + # def cost_or_value(self, node, date, include_children): + # if include_children: + # return cost_or_value(node.balance_children, date) + # return cost_or_value(node.balance, date) diff --git a/fava_investor/common/libinvestor.py b/fava_investor/common/libinvestor.py index a89f4db..326b499 100644 --- a/fava_investor/common/libinvestor.py +++ b/fava_investor/common/libinvestor.py @@ -3,7 +3,8 @@ import collections import decimal from beancount.core.inventory import Inventory -from beancount.core import convert +from beancount.core import convert # noqa: F401 +from fava.core.conversion import convert_position class Node(object): @@ -93,7 +94,7 @@ def sum_inventories(invs): total = '' if t == Inventory: total = sum_inventories([getattr(r, label) for r in rows]) - total = total.reduce(convert.convert_position, accapi.get_operating_currencies()[0], + total = total.reduce(convert_position, accapi.get_operating_currencies()[0], accapi.build_price_map()) elif t == decimal.Decimal: total = sum([getattr(r, label) for r in rows]) diff --git a/fava_investor/modules/assetalloc_class/libassetalloc.py b/fava_investor/modules/assetalloc_class/libassetalloc.py index b3e5f5e..8ff0e42 100644 --- a/fava_investor/modules/assetalloc_class/libassetalloc.py +++ b/fava_investor/modules/assetalloc_class/libassetalloc.py @@ -5,6 +5,7 @@ import collections import re +# from fava.core.conversion import convert_position from beancount.core import convert from beancount.core import inventory from beancount.core import position @@ -100,7 +101,7 @@ def bucketize(vbalance, accapi): # what we want is the conversion to be done on the end date, or on a date # closest to it, either earlier or later. convert_position does this via bisect - amount = convert.convert_position(pos, base_currency, price_map, date=end_date) + amount = accapi.convert_position(pos, base_currency, price_map, date=end_date) if amount.currency == pos.units.currency and amount.currency != base_currency: # Ideally, we would automatically figure out the currency to hop via, based on the cost # currency of the position. However, with vbalance, cost currency info is not diff --git a/fava_investor/modules/summarizer/libsummarizer.py b/fava_investor/modules/summarizer/libsummarizer.py index d813041..c3a1038 100644 --- a/fava_investor/modules/summarizer/libsummarizer.py +++ b/fava_investor/modules/summarizer/libsummarizer.py @@ -7,6 +7,7 @@ from beancount.core.data import Close from beancount.core import realization from beancount.core import convert +from fava.core.conversion import convert_position from fava_investor.common.libinvestor import build_table_footer @@ -167,7 +168,7 @@ def get_balance(realacc, account, pm, currency): subtree = realization.get(realacc, account) balance = realization.compute_balance(subtree) vbalance = balance.reduce(convert.get_units) - market_value = vbalance.reduce(convert.convert_position, currency, pm) + market_value = vbalance.reduce(convert_position, currency, pm) val = libinvestor.val(market_value) return val # return int(val) diff --git a/fava_investor/templates/Investor.html b/fava_investor/templates/Investor.html index 3c4dcf1..540288e 100644 --- a/fava_investor/templates/Investor.html +++ b/fava_investor/templates/Investor.html @@ -1,5 +1,4 @@ {% import "_query_table.html" as querytable with context %} -{% import "_charts.html" as charts with context %} {% set new_querytable = extension.use_new_querytable() %} {% set module = request.args.get('module') %} @@ -11,7 +10,7 @@ ('summarizer', _('Summarizer')), ('minimizegains', _('Gains Minimizer')) ] %} -