Fix treatment of unrealised gains in comparative statements
This commit is contained in:
parent
dc2c474b1b
commit
a9ac523d1b
@ -69,7 +69,7 @@ def trial():
|
||||
l = ledger.raw_transactions_at_date(date)
|
||||
if cash:
|
||||
l = accounting.ledger_to_cash(l, report_currency)
|
||||
trial_balances = [accounting.trial_balance(l, d, p, report_currency) for d, p in zip(dates, pstarts)]
|
||||
trial_balances = [accounting.trial_balance(l.clone(), d, p, report_currency) for d, p in zip(dates, pstarts)]
|
||||
|
||||
# Delete accounts with always zero balances
|
||||
accounts = sorted(l.accounts.values(), key=lambda a: a.name)
|
||||
@ -93,7 +93,7 @@ def balance():
|
||||
l = ledger.raw_transactions_at_date(date)
|
||||
if cash:
|
||||
l = accounting.ledger_to_cash(l, report_currency)
|
||||
balance_sheets = [accounting.balance_sheet(accounting.trial_balance(l, d, p, report_currency)) for d, p in zip(dates, pstarts)]
|
||||
balance_sheets = [accounting.balance_sheet(accounting.trial_balance(l.clone(), d, p, report_currency)) for d, p in zip(dates, pstarts)]
|
||||
|
||||
# Delete accounts with always zero balances
|
||||
accounts = list(l.accounts.values())
|
||||
@ -126,7 +126,7 @@ def pandl():
|
||||
l = ledger.raw_transactions_at_date(date_end)
|
||||
if cash:
|
||||
l = accounting.ledger_to_cash(l, report_currency)
|
||||
pandls = [accounting.trial_balance(l, de, db, report_currency) for de, db in zip(dates_end, dates_beg)]
|
||||
pandls = [accounting.trial_balance(l.clone(), de, db, report_currency) for de, db in zip(dates_end, dates_beg)]
|
||||
|
||||
# Delete accounts with always zero balances
|
||||
accounts = list(l.accounts.values())
|
||||
@ -167,8 +167,9 @@ def transactions():
|
||||
account = l.get_account(account)
|
||||
transactions = [t for t in l.transactions if t.date <= date_end and t.date >= date_beg and any(p.account == account for p in t.postings)]
|
||||
|
||||
opening_balance = accounting.trial_balance(l, date_beg - timedelta(days=1), date_beg, report_currency).get_balance(account).clean()
|
||||
closing_balance = accounting.trial_balance(l, date_end, date_beg, report_currency).get_balance(account).clean()
|
||||
# Use trial_balance_raw because ledger is already adjusted for unrealised gains, etc.
|
||||
opening_balance = accounting.trial_balance_raw(l, date_beg - timedelta(days=1), date_beg).get_balance(account).clean()
|
||||
closing_balance = accounting.trial_balance_raw(l, date_end, date_beg).get_balance(account).clean()
|
||||
|
||||
def matching_posting(transaction, amount):
|
||||
return next((p for p in transaction.postings if p.account == account and p.amount.currency == amount.currency), None)
|
||||
@ -179,8 +180,8 @@ def transactions():
|
||||
account = l.get_account(account)
|
||||
transactions = [t for t in l.transactions if t.date <= date_end and t.date >= date_beg and any(p.account == account for p in t.postings)]
|
||||
|
||||
opening_balance = accounting.trial_balance(l, date_beg - timedelta(days=1), date_beg, report_currency).get_balance(account).exchange(report_currency, True)
|
||||
closing_balance = accounting.trial_balance(l, date_end, date_beg, report_currency).get_balance(account).exchange(report_currency, True)
|
||||
opening_balance = accounting.trial_balance_raw(l, date_beg - timedelta(days=1), date_beg).get_balance(account).exchange(report_currency, True)
|
||||
closing_balance = accounting.trial_balance_raw(l, date_end, date_beg).get_balance(account).exchange(report_currency, True)
|
||||
|
||||
return flask.render_template('transactions.html', date_beg=date_beg, date_end=date_end, period=describe_period(date_end, date_beg), account=account, ledger=l, transactions=transactions, opening_balance=opening_balance, closing_balance=closing_balance, report_currency=report_currency, cash=cash, timedelta=timedelta)
|
||||
|
||||
|
@ -41,6 +41,8 @@
|
||||
{% if not amount.near_zero %}
|
||||
{% if account.name == config['current_year_earnings'] %}
|
||||
{{ amount|a('/pandl?' + {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'compare': '0', 'cash': 'on' if cash else '', 'scope': 'both'}|urlencode) }}
|
||||
{% elif account.name == config['current_year_oci'] %}
|
||||
{{ amount|a('/pandl?' + {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheet.pstart.strftime('%Y-%m-%d'), 'compare': '0', 'cash': 'on' if cash else '', 'scope': 'oci'}|urlencode) }}
|
||||
{% else %}
|
||||
{{ amount|a('/transactions?' + {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheet.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode) }}
|
||||
{% endif %}
|
||||
|
@ -29,6 +29,14 @@ class Ledger:
|
||||
|
||||
self.prices = []
|
||||
|
||||
def clone(self):
|
||||
result = Ledger(self.date)
|
||||
result.root_account = self.root_account
|
||||
result.accounts = self.accounts
|
||||
result.transactions = self.transactions[:]
|
||||
result.prices = self.prices
|
||||
return result
|
||||
|
||||
def get_account(self, name):
|
||||
if name == '':
|
||||
return self.root_account
|
||||
|
Reference in New Issue
Block a user