示例#1
0
def test_accounting_equation_with_groups():
    clear_all_definitions()
    Asset.define("USD")

    assets = AccountGroup.define(name="assets")
    liabilities = AccountGroup.define(name="liabilities")
    equity = AccountGroup.define(name="equity")

    shareholder_equity = Account.define(name="shareholder_equity", asset="USD")
    wells_fargo = Account.define(name="wells_fargo", asset="USD")
    equipment = Account.define(name="equipment", asset="USD")
    cash = Account.define(name="cash", asset="USD")

    assets.add(cash)
    assets.add(equipment)
    equity.add(shareholder_equity)
    liabilities.add(wells_fargo)

    ipo_amount = AssetAmount(amount=D(100), asset="USD")
    ipo_entry = DoubleEntry(src=shareholder_equity,
                            dest=equipment,
                            asset_amount=ipo_amount)

    loan_amount = AssetAmount(amount=D(50), asset="USD")
    loan_entry = DoubleEntry(src=wells_fargo,
                             dest=cash,
                             asset_amount=loan_amount)

    with GeneralLedger.transaction_lock:
        GeneralLedger.realize(ipo_entry)
        GeneralLedger.realize(loan_entry)

    assert_true(GeneralLedger.balance()[Asset["USD"]].amount == D(0))
    assert_true(assets + liabilities +
                equity == AssetAmount(asset="USD", amount=D(0)))
示例#2
0
def test_double_entry_creation():
    prep_test_assets()
    ac0 = Account.define(name="PiggyBank", asset="EN")
    ac1 = Account.define(name="Sofa", asset="EN")
    DoubleEntry(src=ac0, dest=ac1, amount="100.0")
    DoubleEntry(src=ac0, dest=ac1, amount=100, asset="EN")
    DoubleEntry(src=ac0, dest=ac1, amount=D(100), asset=Asset["EN"])

    deposit = AccountEntry(account=ac0, amount=D(100.))
    withdrawal = AccountEntry(account=ac1, amount=D(100.))
    DoubleEntry(deposit=deposit, withdrawal=withdrawal)
示例#3
0
def test_cannot_commit_without_lock():
    prep_test_ledger()
    ipo_amount = AssetAmount(amount=D(100), asset="USD")
    ipo_entry = DoubleEntry(src="shareholder_equity",
                            dest="equipment",
                            asset_amount=ipo_amount)
    GeneralLedger.commit(ipo_entry)
示例#4
0
def test_cannot_unrealize_without_lock():
    prep_test_ledger()
    ipo_amount = AssetAmount(amount=D(100), asset="USD")
    ipo_entry = DoubleEntry(src="shareholder_equity",
                            dest="equipment",
                            asset_amount=ipo_amount)
    with GeneralLedger.transaction_lock:
        GeneralLedger.realize(ipo_entry)

    # Transaction fell through in real life.  Let's revert.
    GeneralLedger.unrealize(ipo_entry)
示例#5
0
def test_entries_balance_to_zero():
    clear_all_definitions()
    Asset.define("USD")
    assets = Account.define(name="Assets", asset="USD")
    liabilities = Account.define(name="Liabilities", asset="USD")
    equity = Account.define(name="Equity", asset="USD")

    ipo_amount = AssetAmount(amount=D(100), asset="USD")
    ipo_entry = DoubleEntry(src=equity, dest=assets, asset_amount=ipo_amount)

    loan_amount = AssetAmount(amount=D(50), asset="USD")
    loan_entry = DoubleEntry(src=liabilities,
                             dest=assets,
                             asset_amount=loan_amount)

    with GeneralLedger.transaction_lock:
        GeneralLedger.realize(ipo_entry)
        GeneralLedger.realize(loan_entry)

    assert_true(GeneralLedger.balance()[Asset["USD"]].amount == D(0))
示例#6
0
def tried_to_roll_back_committed_transaction():
    prep_test_ledger()
    ipo_amount = AssetAmount(amount=D(100), asset="USD")
    ipo_entry = DoubleEntry(src="shareholder_equity",
                            dest="equipment",
                            asset_amount=ipo_amount)
    with GeneralLedger.transaction_lock:
        GeneralLedger.realize(ipo_entry)

    # oops, network failed.  Better roll it back.

    with GeneralLedger.transaction_lock:
        GeneralLedger.rollback(ipo_entry)
示例#7
0
def test_commit_and_rollback_transaction():
    prep_test_ledger()
    ipo_amount = AssetAmount(amount=D(100), asset="USD")
    ipo_entry = DoubleEntry(src="shareholder_equity",
                            dest="equipment",
                            asset_amount=ipo_amount)
    with GeneralLedger.transaction_lock:
        GeneralLedger.commit(ipo_entry)

    # Network failed.  Remove the committed amount to free it back up.

    with GeneralLedger.transaction_lock:
        GeneralLedger.rollback(ipo_entry)
示例#8
0
def test_double_entry_str_repr__():
    prep_test_assets()
    ac0 = Account.define(name="PiggyBank", asset="EN")
    ac1 = Account.define(name="Sofa", asset="EN")
    de = DoubleEntry(src=ac0, dest=ac1, amount="100.0")
    logger.info("Found a {0!s} created like so: {0!r}".format(de))