Disable cash basis for now

Very buggy, gives incorrect results
This commit is contained in:
RunasSudo 2020-08-06 03:01:00 +10:00
parent 454801cd63
commit 4a9e4d34e9
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 6 additions and 57 deletions

View File

@ -20,7 +20,7 @@ ledger-pyreport is a lightweight Flask webapp for generating interactive and pri
* Correctly computes unrealised gains ([even when Ledger does not](https://yingtongli.me/blog/2020/03/31/ledger-gains.html))
* Accounts for both profit and loss, and other comprehensive income
* Simulates annual closing of books, with presentation of income/expenses on the balance sheet as retained earnings and current year earnings
* Can simulate cash basis accounting, using FIFO methodology to recode transactions involving liabilities and non-cash assets
* ~~Can simulate cash basis accounting, using FIFO methodology to recode transactions involving liabilities and non-cash assets~~ (Very buggy so disabled for now)
* Can separately report specified categories of income and expense, reporting per-category net profit
* Extensible through custom programming hooks

View File

@ -132,58 +132,7 @@ def balance_sheet(tb):
return tb
def account_to_cash(account, commodity):
# Apply FIFO methodology to match postings
balance = [] # list of [posting, amount to balance, amount remaining, balancing list of [posting, amount balanced]]
for transaction in account.ledger.transactions[:]:
if any(p.account == account for p in transaction.postings):
for posting in transaction.postings[:]:
if posting.account == account:
#transaction.postings.remove(posting)
pass
else:
# Try to balance postings
amount_to_balance = posting.amount.exchange(commodity, True).amount
while amount_to_balance != 0:
balancing_posting = next((b for b in balance if b[2] != 0 and math.copysign(1, b[2]) != math.copysign(1, amount_to_balance)), None)
if balancing_posting is None:
break
if abs(balancing_posting[2]) >= abs(amount_to_balance):
balancing_posting[3].append([posting, amount_to_balance])
balancing_posting[2] += amount_to_balance
amount_to_balance = Decimal(0)
break
else:
balancing_posting[3].append([posting, -balancing_posting[2]])
amount_to_balance += balancing_posting[2]
balancing_posting[2] = Decimal(0)
if amount_to_balance != 0:
# New unbalanced remainder
balance.append([posting, amount_to_balance, amount_to_balance, []])
transaction.postings = []
# Finalise balanced postings
for orig_posting, amount_to_balance, amount_remaining, balancing_postings in balance:
posting = Posting(orig_posting.transaction, orig_posting.account, Amount(amount_to_balance, commodity))
posting.transaction.postings.append(posting)
for balancing_posting, amount_balanced in balancing_postings:
posting.transaction.postings.append(Posting(posting.transaction, balancing_posting.account, Amount(amount_balanced, commodity)))
if balancing_posting in balancing_posting.transaction.postings:
balancing_posting.transaction.postings.remove(balancing_posting)
if amount_remaining != 0:
if posting.account.is_asset:
# Cash - charge any unbalanced remainder to Other Income
posting.transaction.postings.append(Posting(posting.transaction, account.ledger.get_account(config['cash_other_income']), Amount(-amount_remaining, commodity)))
else:
# Liabilities, etc. - discard any unbalanced remainder
posting.amount.amount -= amount_remaining
raise Exception('Not implemented')
# Adjust (in place) a ledger to convert accounting to a cash basis
def ledger_to_cash(ledger, commodity):

View File

@ -42,7 +42,7 @@
<option value="month">months</option>
</select>
</label>
<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>
{#<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>#}
</form>
</div>
@ -59,7 +59,7 @@
<option value="month">months</option>
</select>
</label>
<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>
{#<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>#}
</form>
</div>
@ -76,7 +76,7 @@
<option value="month">months</option>
</select>
</label>
<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>
{#<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>#}
<label>Scope: <select name="scope">
<option value="pandl" selected>P&L only</option>
<option value="oci">OCI only</option>
@ -111,7 +111,7 @@
<label>Begin date: <input name="date_beg" data-inputgroup="pstart" value="{{ pstart.strftime('%Y-%m-%d') }}" style="width: 6em;" oninput="txtc(this)"></label>
<label>End date: <input name="date_end" data-inputgroup="date" value="{{ date.strftime('%Y-%m-%d') }}" style="width: 6em;" oninput="txtc(this)"></label>
<button class="fy-btn">FY</button>
<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>
{#<label><input name="cash" data-inputgroup="cash" type="checkbox" oninput="chbc(this)"> Cash basis</label>#}
</form>
</div>