Skip to content

Commit

Permalink
Merge pull request #28 from polarmutex/fix-fava-update-1-19
Browse files Browse the repository at this point in the history
Fix fava update 1 19
  • Loading branch information
polarmutex authored Jun 6, 2021
2 parents 5825a6d + ab039aa commit f56c14b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
18 changes: 17 additions & 1 deletion fava_envelope/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""

from fava.ext import FavaExtensionBase
from fava import __version__ as fava_version
from beancount.core.number import Decimal, D

from .modules.beancount_envelope import BeancountEnvelope
Expand All @@ -26,7 +27,7 @@ def get_budgets_months_available(self,currency):
return self.income_tables.columns

def check_month_in_available_months(self,month,currency):
if currency and month:
if month:
if month in self.get_budgets_months_available(currency):
return True
return False
Expand Down Expand Up @@ -75,6 +76,7 @@ def generate_income_query_tables(self, month):

def generate_envelope_query_tables(self, month):

print(month)
envelope_table_types = []
envelope_table_types.append(("Account", str(str)))
envelope_table_types.append(("Budgeted", str(Decimal)))
Expand All @@ -93,3 +95,17 @@ def generate_envelope_query_tables(self, month):
envelope_table_rows.append(row)

return (envelope_table_types, envelope_table_rows)

def use_new_querytable(self):
"""
from redstreet/fava_investor
fava added the ledger as a first required argument to
querytable.querytable after version 1.18, so in order to support both,
we have to detect the version and adjust how we call it from inside our
template
"""
split_version = fava_version.split('.')
if len(split_version) != 2:
split_version = split_version[:2]
major, minor = split_version
return int(major) > 1 or (int(major) == 1 and int(minor) > 18)
9 changes: 9 additions & 0 deletions fava_envelope/templates/EnvelopeBudget.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% set new_querytable = extension.use_new_querytable() %}
{% import "_query_table.html" as querytable with context %}
{% set currency = request.args.get('currency') %}
{% if currency == None%}
Expand Down Expand Up @@ -27,7 +28,15 @@ <h3><b>{% if not (module == m) %}<a href="{{ url_for_current(month=m,currency=cu
<h3>{{ month }}</h3>

{% set income_table = extension.generate_income_query_tables(month) %}
{% if new_querytable %}
{{ querytable.querytable(ledger, None, income_table[0], income_table[1]) }}
{% else %}
{{ querytable.querytable(None, income_table[0], income_table[1]) }}
{% endif %}

{% set envelope_table = extension.generate_envelope_query_tables(month) %}
{% if new_querytable %}
{{ querytable.querytable(ledger, None, envelope_table[0], envelope_table[1]) }}
{% else %}
{{ querytable.querytable(None, envelope_table[0], envelope_table[1]) }}
{% endif %}

0 comments on commit f56c14b

Please sign in to comment.