How to use the piecash.Split function in piecash

To help you get started, we’ve selected a few piecash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdementen / piecash / tests / test_transaction.py View on Github external
def test_create_basictransaction_validation_date(self, book_basic):
        EUR = book_basic.commodities(namespace="CURRENCY")
        racc = book_basic.root_account
        a = book_basic.accounts(name="asset")
        e = book_basic.accounts(name="exp")

        splits = [
            Split(account=a, value=100, memo=u"mémo asset"),
            Split(account=e, value=-10, memo=u"mémo exp"),
        ]

        with pytest.raises(GncValidationError):
            tr = Transaction(currency=EUR, description=u"wire from Hélène", notes=u"on St-Eugène day",
                             post_date=datetime(2014, 1, 1),
                             enter_date=datetime(2014, 1, 1),
                             splits=splits)

        with pytest.raises(GncValidationError):
            tr = Transaction(currency=EUR, description=u"wire from Hélène", notes=u"on St-Eugène day",
                             post_date=datetime(2014, 1, 1),
                             enter_date=time(10, 59, 00),
                             splits=splits)

        with pytest.raises(GncValidationError):
            tr = Transaction(currency=EUR, description=u"wire from Hélène", notes=u"on St-Eugène day",
github sdementen / piecash / tests / test_transaction.py View on Github external
def test_create_closedlot_addsplits(self, book_basic):
        EUR = book_basic.commodities(namespace="CURRENCY")
        racc = book_basic.root_account
        a = book_basic.accounts(name="asset")
        s = book_basic.accounts(name="broker")
        l = Lot(title=u"test mé", account=s, notes=u"ïlya")
        l.is_closed = 1
        # raise valueerror as lot is closed
        with pytest.raises(ValueError):
            tr = Transaction(currency=EUR, description="trade stock", notes=u"àçö",
                             post_date=date(2014, 1, 1),
                             enter_date=datetime(2014, 1, 1),
                             splits=[
                                 Split(account=a, value=10, memo=u"mémo asset"),
                                 Split(account=s, value=- 10, quantity=-2, memo=u"mémo brok", lot=l),
                             ])
github sdementen / piecash / tests / test_transaction.py View on Github external
def test_create_simpletlot_initialsplits(self, book_basic):
        EUR = book_basic.commodities(namespace="CURRENCY")
        racc = book_basic.root_account
        a = book_basic.accounts(name="asset")
        s = book_basic.accounts(name="broker")
        sp = []
        for i, am in enumerate([45, -35, -20]):
            tr = Transaction(currency=EUR, description="trade stock", notes=u"àçö",
                             post_date=date(2014, 1, 1 + i),
                             enter_date=datetime(2014, 1, 1 + i),
                             splits=[
                                 Split(account=a, value=am * 10, memo=u"mémo asset"),
                                 Split(account=s, value=-am * 10, quantity=-am, memo=u"mémo brok"),
                             ])
            sp.append(tr.splits(account=s))

        l = Lot(title=u"test mé", account=s, notes=u"ïlya", splits=sp)
        book_basic.flush()
github sdementen / piecash / tests / test_transaction.py View on Github external
def test_create_simpletlot_addsplits(self, book_basic):
        EUR = book_basic.commodities(namespace="CURRENCY")
        racc = book_basic.root_account
        a = book_basic.accounts(name="asset")
        s = book_basic.accounts(name="broker")
        l = Lot(title=u"test mé", account=s, notes=u"ïlya")
        for i, am in enumerate([45, -35, -20]):
            tr = Transaction(currency=EUR, description="trade stock", notes=u"àçö",
                             post_date=date(2014, 1, 1 + i),
                             enter_date=datetime(2014, 1, 1 + i),
                             splits=[
                                 Split(account=a, value=am * 10, memo=u"mémo asset"),
                                 Split(account=s, value=-am * 10, quantity=-am, memo=u"mémo brok", lot=l),
                             ])
        book_basic.flush()
github sdementen / piecash / tests / test_transaction.py View on Github external
def test_create_cdtytransaction(self, book_basic):
        EUR = book_basic.commodities(namespace="CURRENCY")
        racc = book_basic.root_account
        a = book_basic.accounts(name="asset")
        s = book_basic.accounts(name="broker")

        tr = Transaction(currency=EUR, description="buy stock", notes=u"on St-Eugène day",
                         post_date=date(2014, 1, 2),
                         enter_date=datetime(2014, 1, 3),
                         splits=[
                             Split(account=a, value=100, memo=u"mémo asset"),
                             Split(account=s, value=-90, memo=u"mémo brok"),
                         ])

        # check issue with quantity for broker split not defined
        with pytest.raises(GncValidationError):
            book_basic.validate()

        sb = tr.splits(account=s)
        sb.quantity = 15

        # check issue with quantity not same sign as value
        with pytest.raises(GncValidationError):
            book_basic.validate()

        sb.quantity = -15

        # verify imbalance issue
github hiromu2000 / mintcash / mintcash / main.py View on Github external
if [tr for tr in book.transactions if tr.num==str(tran['id'])]:
                #print 'already exists', tran['odate'], tran['merchant'], tran['amount']
                cnt = cnt + 1
                continue
            if tran['isDuplicate']:
                continue

            a1 = book.accounts(code=str(tran['categoryId']))
            a2 = book.accounts(name=tran['account'])
            amount = Decimal("%.2f" % tran['amount'])

            piecash.Transaction(currency=USD,
                                description=tran['merchant'],
                                splits=[
                                    piecash.Split(account=a1, value=amount),
                                    piecash.Split(account=a2, value=-1 * amount)
                                ],
                                post_date=tran['odate'].to_pydatetime().date(),
                                num=str(tran['id']))
        book.save()
        book.close()
github sdementen / piecash / examples / sandbox.py View on Github external
acc2 = Account(name="baz CAD", parent=s.book.root_account, account_type="STOCK", placeholder=False, commodity=CAD)
acc3 = Account(name="baz USD", parent=s.book.root_account, account_type="STOCK", placeholder=False, commodity=USD)
# acc1.commodity_scu = 1000
t = Transaction(description="foo",
                post_date=datetime.datetime.now(),
                enter_date=datetime.datetime.now(),
                currency=EUR)
Split(transaction=t,
      value=-25,
      quantity=-25,
      account=acc1)
Split(transaction=t,
      value=15,
      quantity=10,
      account=acc2)
Split(transaction=t,
      value=11,
      quantity=12,
      account=acc3)
print(t.splits)
imb = t.get_imbalances()
print(imb)
t.add_imbalance_splits()
s.save()
# print s.session.query(Split).filter(Split.value_magic>=1.0).all()
ffdsfdd

# print t.splits[0].value_gnc, t.splits[0].value_denom, t.splits[0].value_num

print(s.book.root_account.children.append(Account(name="rool", account_type="ASSET", placeholder=False, commodity=EUR)))
s.save()
print(s.transactions.get)
github sdementen / piecash / examples / sandbox.py View on Github external
from piecash import open_book, create_book, Account, Transaction, Split

# with create_book("all_account_types.gnucash", overwrite=True) as s:
# for actype in ACCOUNT_TYPES:
# if actype=="ROOT":
# continue
#         acc = Account(name=actype, account_type=actype, parent=s.book.root_account, commodity=s.book.root_account.commodity)
#     s.save()

with open_book("simple_sample.gnucash", acquire_lock=False, open_if_lock=True) as s:
    asset = s.accounts.get(name="Asset")
    expense = s.accounts.get(name="Expense")
    eur = asset.commodity
    tr = Transaction(currency=eur,
                     description="test",
                     splits=[Split(asset, 100), Split(expense, -100)])
    print(tr)
    fdsdf
    for tr in s.transactions:
        for sp in tr.splits:
            sp.account = asset

    fdsfsdfd

    for tr in s.transactions:
        print(tr)
        for sp in tr.splits:
            print("\t", sp)

    for acc in s.accounts:
        if acc.commodity:
            print(acc.commodity.base_currency)
github MisterY / gnucash-portfolio / gnucash_portfolio / securitiesaggregate.py View on Github external
def get_splits_query(self):
        """ Returns the query for all splits for this security """
        query = (
            self.book.session.query(Split)
            .join(Account)
            .filter(Account.type != AccountType.trading.value)
            .filter(Account.commodity_guid == self.security.guid)
        )
        return query
github MisterY / gnucash-portfolio / app / controllers / distributions_controller.py View on Github external
def __load_income_in_period_query(
        book: Book, account_ids: List[hex], in_model) -> List[Split]:
    """ Load all data by using the query directly """

    date_from = in_model.date_from
    date_to = in_model.date_to
    log(DEBUG, "fetching data for period %s - %s", date_from, date_to)

    query = (book.query(Split)
             .join(Transaction)
             .join(Account)
             .filter(Transaction.post_date >= date_from, Transaction.post_date <= date_to,
                     Account.guid.in_(account_ids))
             .order_by(Transaction.post_date)
            )

    if in_model.currency:
        query = (query
                 .join(Commodity)
                 .filter(Commodity.mnemonic == in_model.currency)
                )

    return query.all()