2020-04-09 19:11:16 +00:00
|
|
|
"""Test data.is_opening_balance_txn function"""
|
|
|
|
# Copyright © 2020 Brett Smith
|
2021-01-08 21:57:43 +00:00
|
|
|
# License: AGPLv3-or-later WITH Beancount-Plugin-Additional-Permission-1.0
|
2020-04-09 19:11:16 +00:00
|
|
|
#
|
2021-01-08 21:57:43 +00:00
|
|
|
# Full copyright and licensing details can be found at toplevel file
|
|
|
|
# LICENSE.txt in the repository.
|
2020-04-09 19:11:16 +00:00
|
|
|
|
|
|
|
from decimal import Decimal
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from . import testutil
|
|
|
|
|
|
|
|
from conservancy_beancount import data
|
|
|
|
|
|
|
|
def test_typical_opening():
|
2020-04-28 19:33:30 +00:00
|
|
|
txn = testutil.OpeningBalance()
|
2020-04-09 19:11:16 +00:00
|
|
|
assert data.is_opening_balance_txn(txn)
|
|
|
|
|
|
|
|
def test_multiacct_opening():
|
|
|
|
txn = testutil.Transaction(postings=[
|
|
|
|
('Assets:Receivable:Accounts', 100),
|
|
|
|
(next(testutil.OPENING_EQUITY_ACCOUNTS), -100),
|
|
|
|
('Liabilities:Payable:Accounts', -150),
|
|
|
|
(next(testutil.OPENING_EQUITY_ACCOUNTS), 150),
|
|
|
|
])
|
|
|
|
assert data.is_opening_balance_txn(txn)
|
|
|
|
|
|
|
|
def test_opening_with_fx():
|
2020-04-28 19:33:30 +00:00
|
|
|
txn = testutil.OpeningBalance()
|
2020-04-09 19:11:16 +00:00
|
|
|
equity_post = txn.postings[-1]
|
|
|
|
txn.postings[-1] = equity_post._replace(
|
|
|
|
units=testutil.Amount(equity_post.units.number * Decimal('.9'), 'EUR'),
|
|
|
|
cost=testutil.Cost('1.11111'),
|
|
|
|
)
|
|
|
|
assert data.is_opening_balance_txn(txn)
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('acct1,acct2,number', [
|
|
|
|
('Assets:Receivable:Accounts', 'Income:Donations', 100),
|
|
|
|
('Expenses:Other', 'Liabilities:Payable:Accounts', 200),
|
|
|
|
('Expenses:Other', 'Equity:Retained:Costs', 300),
|
|
|
|
# Release from restriction
|
|
|
|
('Equity:Funds:Unrestricted', 'Equity:Funds:Restricted', 400),
|
2020-12-29 17:20:53 +00:00
|
|
|
# Donation from project fund
|
|
|
|
('Equity:Funds:Restricted', 'Income:Donations', 500),
|
2020-04-09 19:11:16 +00:00
|
|
|
])
|
|
|
|
def test_not_opening_balance(acct1, acct2, number):
|
|
|
|
txn = testutil.Transaction(postings=[
|
|
|
|
(acct1, number),
|
|
|
|
(acct2, -number),
|
|
|
|
])
|
|
|
|
assert not data.is_opening_balance_txn(txn)
|