Implement extensions

This commit is contained in:
RunasSudo 2020-04-15 11:13:28 +10:00
parent 327493be3e
commit 887751f439
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
6 changed files with 48 additions and 1 deletions

View File

@ -21,6 +21,7 @@ ledger-pyreport is a lightweight Flask webapp for generating interactive and pri
* Accounts for both profit and loss, and other comprehensive income * 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 * 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
* Extensible through custom programming hooks
## Background, demo and screenshots ## Background, demo and screenshots

View File

@ -23,3 +23,6 @@ current_year_earnings: 'Equity:Current Year Earnings'
cash_asset_accounts: ['Assets:Current:Cash on Hand', 'Assets:Current:Cash at Bank'] cash_asset_accounts: ['Assets:Current:Cash on Hand', 'Assets:Current:Cash at Bank']
# Which account to charge non-cash transactions to in cash basis mode, when no other account is suitable # Which account to charge non-cash transactions to in cash basis mode, when no other account is suitable
cash_other_income: 'Income:Other Income' cash_other_income: 'Income:Other Income'
# Extensions to load
extensions: []

View File

@ -1,5 +1,5 @@
# Set up how we will call Ledger # Set up how we will call Ledger
ledger_file: demo/ledger.journal ledger_file: ledger.journal
ledger_args: [] ledger_args: []
report_commodity: '$' report_commodity: '$'
@ -23,3 +23,7 @@ current_year_earnings: 'Equity:Retained Earnings:Current Year Earnings'
cash_asset_accounts: ['Assets:Current:Cash on Hand', 'Assets:Current:Cash at Bank', 'Assets:Current:International Account'] cash_asset_accounts: ['Assets:Current:Cash on Hand', 'Assets:Current:Cash at Bank', 'Assets:Current:International Account']
# Which account to charge non-cash transactions to in cash basis mode, when no other account is suitable # Which account to charge non-cash transactions to in cash basis mode, when no other account is suitable
cash_other_income: 'Income:Other Income' cash_other_income: 'Income:Other Income'
# Extensions to load
extensions:
- ext_pending.py

30
demo/ext_pending.py Normal file
View File

@ -0,0 +1,30 @@
# ledger-pyreport
# Copyright © 2020 Lee Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Extension to move pending postings to a pending transactions account
_ledger_raw_transactions_at_date = ledger.raw_transactions_at_date
def ledger_raw_transactions_at_date(*args, **kwargs):
l = _ledger_raw_transactions_at_date(*args, **kwargs)
for transaction in l.transactions:
for posting in transaction.postings:
if posting.state == Posting.State.PENDING:
posting.account = l.get_account('Liabilities:Current:Pending Transactions')
return l
ledger.raw_transactions_at_date = ledger_raw_transactions_at_date

View File

@ -38,4 +38,8 @@
Expenses:Depreciation $500.00 Expenses:Depreciation $500.00
Assets:Non-current:Plant:Less Accumulated Depreciation Assets:Non-current:Plant:Less Accumulated Depreciation
2019-10-02 Pending transaction
Expenses:Stationery $10.00
! Assets:Current:Cash at Bank
P 2019-10-01 00:00:00 EUR $1.30 P 2019-10-01 00:00:00 EUR $1.30

View File

@ -359,3 +359,8 @@ def debug_imbalances():
total_cr = sum((p.amount for t in transactions for p in t.postings if p.amount < 0), Balance()).exchange(report_commodity, True) total_cr = sum((p.amount for t in transactions for p in t.postings if p.amount < 0), Balance()).exchange(report_commodity, True)
return flask.render_template('transactions.html', date=date, pstart=pstart, period=describe_period(date, pstart), account=None, ledger=l, transactions=transactions, total_dr=total_dr, total_cr=total_cr, report_commodity=report_commodity, cash=cash) return flask.render_template('transactions.html', date=date, pstart=pstart, period=describe_period(date, pstart), account=None, ledger=l, transactions=transactions, total_dr=total_dr, total_cr=total_cr, report_commodity=report_commodity, cash=cash)
# Load extensions
for ext_name in config['extensions']:
with open(ext_name, 'r') as f:
exec(f.read())