Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for fava 1.2.5 #85

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fava_investor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def use_new_querytable(self):
we have to detect the version and adjust how we call it from inside our
template
"""
if "dev" in fava_version:
return True
split_version = fava_version.split('.')
if len(split_version) != 2:
split_version = split_version[:2]
Expand Down
2 changes: 1 addition & 1 deletion fava_investor/common/beancountinvestorapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_operating_currencies(self):

def get_operating_currencies_regex(self):
currencies = self.get_operating_currencies()
return '(' + '|'.join(currencies) + ')'
return '(' + '|'.join(map(lambda cur: '^cur$', currencies)) + ')'

def get_account_open_close(self):
return getters.get_account_open_close(self.entries)
Expand Down
6 changes: 3 additions & 3 deletions fava_investor/common/favainvestorapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class FavaInvestorAPI:
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"""
Expand All @@ -28,7 +28,7 @@ def root_tree(self):
def query_func(self, sql):
# Based on the fava version, determine if we need to add a new
# positional argument to fava's execute_query()
if version.parse(fava_version) >= version.parse("1.22"):
if version.parse(fava_version) >= version.parse("1.22") or "dev" in fava_version:
_, rtypes, rrows = g.ledger.query_shell.execute_query(g.filtered.entries, sql)
else:
_, rtypes, rrows = g.ledger.query_shell.execute_query(sql)
Expand All @@ -39,7 +39,7 @@ def get_operating_currencies(self):

def get_operating_currencies_regex(self):
currencies = self.get_operating_currencies()
return '(' + '|'.join(currencies) + ')'
return '(' + '|'.join(map(lambda cur: '^cur$', currencies)) + ')'

def get_account_open_close(self):
return getters.get_account_open_close(g.filtered.entries)
Expand Down
3 changes: 2 additions & 1 deletion fava_investor/common/libinvestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import decimal
from beancount.core.inventory import Inventory
from beancount.core import convert
from fava.core.conversion import convert_position


class Node(object):
Expand Down Expand Up @@ -74,7 +75,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])
Expand Down
3 changes: 2 additions & 1 deletion fava_investor/modules/assetalloc_class/libassetalloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = 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
Expand Down
2 changes: 1 addition & 1 deletion fava_investor/modules/cashdrag/libcashdrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def find_cash_commodities(accapi, options):
operating_currencies = accapi.get_operating_currencies()
cash_commodities += operating_currencies
cash_commodities = set(cash_commodities)
commodities_pattern = '(' + '|'.join(cash_commodities) + ')'
commodities_pattern = '(' + '|'.join(map(lambda cur: f'^{cur}$', cash_commodities)) + ')'
return commodities_pattern, operating_currencies[0]


Expand Down
1 change: 1 addition & 0 deletions fava_investor/modules/summarizer/libsummarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from beancount.core import realization
from beancount.core import convert
from fava_investor.common.libinvestor import build_table_footer
from fava.core.conversion import convert_position


# TODO:
Expand Down
10 changes: 4 additions & 6 deletions fava_investor/templates/Investor.html
Original file line number Diff line number Diff line change
@@ -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') %}
Expand All @@ -11,7 +10,7 @@
('summarizer', _('Summarizer')),
('minimizegains', _('Gains Minimizer'))
] %}
<h3><b>{% if not (module == key) %}<a href="{{ url_for('extension_report', report_name='Investor', module=key) }}">{{ label }}</a>{% else %} {{ label }}{% endif %}</b></h3>
<h3><b>{% if not (module == key) %}<a href="{{ url_for('extension_report', extension_name='Investor', module=key) }}">{{ label }}</a>{% else %} {{ label }}{% endif %}</b></h3>
{% endfor %}
</div>

Expand All @@ -23,8 +22,6 @@ <h3><b>{% if not (module == key) %}<a href="{{ url_for('extension_report', repor
</i>
{% endif %}

<svelte-component type="charts"></svelte-component>

<!-- -------------------------------------------------------------------------------- -->
{% macro table_list_renderer(title, tables) -%}
<h2>{{ title }}</h2>
Expand Down Expand Up @@ -206,7 +203,7 @@ <h3>What not to buy</h3>
{% endmacro %}

{% macro asset_allocation_hierarchy(serialised_tree, label='Asset Allocation') %}
{% do charts.chart_data.append({
{% do chart_data.append({
'type': 'hierarchy',
'label': label,
'data': {
Expand All @@ -219,10 +216,11 @@ <h3>What not to buy</h3>
{% if (module == 'aa_class') %}
<h2>Portfolio: Asset Allocation by Class</h2>

{% set chart_data = [] %}
{% set results = extension.build_assetalloc_by_class() %}

{{ asset_allocation_hierarchy(results[0].serialise(results[0]['currency']), label='Asset Allocation') }}
<svelte-component type="charts"><script type="application/json">{{ charts.chart_data|tojson }}</script></svelte-component>
<svelte-component type="charts"><script type="application/json">{{ chart_data|tojson }}</script></svelte-component>

{{ asset_tree(results[0]) }}

Expand Down