Exemplo n.º 1
0
 def setUp(self):
     self.domain1 = "gnc.engine"
     self.domain2 = "gnc.engine.scrub"
     level =  G_LOG_LEVEL_CRITICAL
     check1 = TestErrorStruct()
     check1.log_domain = self.domain1
     check1.log_level = level
     check1.msg = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
     test_add_error(check1)
     check2 = TestErrorStruct()
     check2.log_domain = self.domain1
     check2.log_level = level
     check2.msg = "[xaccTransScrubSplits()] Transaction doesn't have a currency!"
     test_add_error(check2)
     self.hdlr1 = test_set_list_handler(self.domain1, level, None)
     check3 = TestErrorStruct()
     check3.log_domain = "gnc.engine.scrub"
     check3.log_level = level
     check3.msg = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
     self.hdlr2 = test_set_checked_handler(self.domain2, level, check3)
     BookSession.setUp(self)
     self.trans = Transaction(self.book)
     #Evil bug means we must set a split for the transaction before making
     #any other changes (is slightly useful for later tests)
     self.split = Split(self.book)
     self.split.SetParent(self.trans)
     ############
     self.trans.SetCurrency(self.currency)
Exemplo n.º 2
0
    def test_transaction(self):
        domain1 = "gnc.engine.scrub"
        msg1 = "[xaccScrubUtilityGetOrMakeAccount()] No currency specified!"
        level = G_LOG_LEVEL_CRITICAL
        check1 = TestErrorStruct()
        check1.log_domain = domain1
        check1.log_level = level
        check1.msg = msg1
        hdlr1 = test_set_checked_handler(domain1, level, check1)
        domain2 = "gnc.engine"
        msg2 = "[xaccTransScrubSplits()] Transaction doesn't have a currency!"
        level = G_LOG_LEVEL_CRITICAL
        check2 = TestErrorStruct()
        check2.log_domain = domain2
        check2.log_level = level
        check2.msg = msg2
        hdlr2 = test_set_checked_handler(domain2, level, check2)

        TRANS = Transaction(self.book)
        self.split.SetParent(TRANS)
        TRANS.SetCurrency(self.currency)
        TRANS.SetDescription("Foo")
        self.assertEqual(TRANS.GetDescription(),
                         self.split.GetParent().GetDescription())

        g_log_remove_handler(domain2, hdlr2)
        g_log_remove_handler(domain1, hdlr1)
Exemplo n.º 3
0
def record_opening_balance(original_account, new_account, new_book,
                           opening_balance_per_currency, commodity_tuple
                           ):
    # create an opening balance if the account type is right
    if new_account.GetType() in ACCOUNT_TYPES_TO_OPEN:
        final_balance = original_account.GetBalance()
        if final_balance.num() != 0:
            # if there is a new currency type, associate with the currency
            # a Transaction which will be the opening transaction for that
            # currency and a GncNumeric value which will be the opening
            # balance acccount amount
            if commodity_tuple not in opening_balance_per_currency:
                trans = Transaction(new_book)
                trans.BeginEdit()
                opening_balance_per_currency[commodity_tuple] = (
                    trans, GncNumeric(0, 1) )
            trans, total = opening_balance_per_currency[commodity_tuple]

            new_total = total.sub(
                final_balance,
                GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT )
            
            initialize_split(
                new_book,
                final_balance,
                new_account, trans)
            opening_balance_per_currency[commodity_tuple] = \
                (trans, new_total )
Exemplo n.º 4
0
 def test_equal(self):
     COPY = self.split
     self.assertTrue(self.split.Equal(COPY, True, False, False))
     # test __eq__ implementation
     TRANS = Transaction(self.book)
     self.split.SetParent(TRANS)
     self.assertTrue(self.split == TRANS.GetSplitList()[0])
     self.assertTrue(self.split != Split(self.book))
Exemplo n.º 5
0
def add_transaction(book, item, currency):
    logging.info('Adding transaction for account "%s" (%s %s)..', item.account,
                 item.split_amount, currency.get_mnemonic())
    root = book.get_root_account()
    acc = lookup_account(root, item.account)

    tx = Transaction(book)
    tx.BeginEdit()
    tx.SetCurrency(currency)
    tx.SetDateEnteredTS(datetime.datetime.now())
    tx.SetDatePostedTS(item.date)
    tx.SetDescription(item.memo)

    s1 = Split(book)
    s1.SetParent(tx)
    s1.SetAccount(acc)
    amount = int(
        Decimal(item.split_amount.replace(',', '.')) * currency.get_fraction())
    s1.SetValue(GncNumeric(amount, currency.get_fraction()))
    s1.SetAmount(GncNumeric(amount, currency.get_fraction()))

    acc2 = lookup_account(root, item.split_category)
    s2 = Split(book)
    s2.SetParent(tx)
    s2.SetAccount(acc2)
    s2.SetValue(GncNumeric(amount * -1, currency.get_fraction()))
    s2.SetAmount(GncNumeric(amount * -1, currency.get_fraction()))

    tx.CommitEdit()
Exemplo n.º 6
0
def __transaction__str__(self):
    """__str__ method for Transaction class"""
    from gnucash import Transaction
    import time
    self = Transaction(instance=self)

    fmt_tuple = ('Date:', time.ctime(self.GetDate()), 'Description:',
                 self.GetDescription(), 'Notes:', self.GetNotes())

    transaction_str = "{0:6}{1:25} {2:14}{3:40} {4:7}{5:40}".format(
        *all_as_classwithcutting__format__(*fmt_tuple))
    transaction_str += "\n"

    splits_str = ""
    for n, split in enumerate(self.GetSplitList()):
        if not (type(split) == gnucash.Split):
            split = gnucash.Split(instance=split)

        transaction_flag = split.getflag("PRINT_TRANSACTION")
        split.setflag("PRINT_TRANSACTION", False)
        splits_str += "[{0:>2}] ".format(str(n))
        splits_str += str(split)
        splits_str += "\n"
        split.setflag("PRINT_TRANSACTION", transaction_flag)

    return transaction_str + splits_str
Exemplo n.º 7
0
 def setUp(self):
     BookSession.setUp(self)
     self.trans = Transaction(self.book)
     #Evil bug means we must set a split for the transaction before making
     #any other changes (is slightly useful for later tests)
     self.split = Split(self.book)
     self.split.SetParent(self.trans)
Exemplo n.º 8
0
 def test_equal(self):
     TRANS = self.trans
     self.assertTrue( TRANS.Equal(self.trans, True, False, False, False) )
     # test __eq__ implementation
     SPLIT = Split(self.book)
     SPLIT.SetParent(TRANS)
     self.assertTrue( self.trans == SPLIT.GetParent() )
     self.assertTrue( self.trans != Transaction(self.book) )
Exemplo n.º 9
0
def createRandomTransactions(book, accountA, accountB):
    split = Split(book)

    currency = book.get_table().lookup("CURRENCY", "EUR")

    print("Create 100 random transactions")
    for i in range(100):

        trans = Transaction(book)
        trans.BeginEdit()
        trans.SetCurrency(currency)
        trans.SetDate(randint(1, 28), randint(1, 12), randint(1900, 2000))
        trans.SetDescription("Transaction " + str(i))

        value = randint(0, 10000)

        value1 = GncNumeric(value, 100)
        value2 = GncNumeric(-value, 100)

        split1 = Split(book)
        split1.SetValue(value1)
        split1.SetAccount(accountA)
        split1.SetMemo("A" + str(i))
        split1.SetParent(trans)

        split2 = Split(book)
        split2.SetValue(value2)
        split2.SetAccount(accountB)
        split2.SetMemo("B" + str(i))
        split2.SetParent(trans)

        trans.CommitEdit()
Exemplo n.º 10
0
 def add_transaction(self, item):
     """
     add new transaction
     item must have following keys
     """
     assert "date" in item.keys()
     assert "description" in item.keys()
     assert "notes" in item.keys()
     assert "soll" in item.keys()
     assert "soll_value" in item.keys()
     assert "haben" in item.keys()
     assert "haben_value" in item.keys()
     commod_tab = self.__book.get_table()
     currency = commod_tab.lookup('ISO4217', "EUR")
     logging.info('Adding transaction for account "%s" (%s %s)..',
                  item["soll"], item["soll_value"], currency.get_mnemonic())
     tx = Transaction(self.__book)
     tx.BeginEdit()
     tx.SetCurrency(currency)
     tx.SetDateEnteredTS(datetime.datetime.now())
     tx.SetDatePostedTS(item["date"])
     tx.SetDescription(item["description"])
     tx.SetNotes(item["notes"])
     if "num" in item.keys():
         tx.SetNum(item["num"])
     # soll
     acc = self.account_from_path(self.get_root(), item["soll"].split("."))
     s1 = Split(self.__book)
     s1.SetParent(tx)
     s1.SetAccount(acc)
     amount = int(item["soll_value"] * currency.get_fraction())
     s1.SetValue(GncNumeric(amount, currency.get_fraction()))
     s1.SetAmount(GncNumeric(amount, currency.get_fraction()))
     # haben
     acc2 = self.account_from_path(self.get_root(),
                                   item["haben"].split("."))
     s2 = Split(self.__book)
     s2.SetParent(tx)
     s2.SetAccount(acc2)
     amount = int(item["haben_value"] * currency.get_fraction())
     s2.SetValue(GncNumeric(amount, currency.get_fraction()))
     s2.SetAmount(GncNumeric(amount, currency.get_fraction()))
     tx.CommitEdit()
Exemplo n.º 11
0
    def _transfer(self, book, d):
        from_ac = book.get_root_account().lookup_by_code(d['TransferFromAC'])
        if not from_ac:
            raise LookupError('TransferFromAC ({0}) not found'.format(
                d['TransferFromAC']))

        to_ac = book.get_root_account().lookup_by_code(d['TransferToAC'])
        if not to_ac:
            raise LookupError('TransferToAC ({0}) not found'.format(
                d['TransferToAC']))

        if 'Currency' in d:
            currency = book.get_table().lookup('CURRENCY', d['Currency'])
        else:
            currency = book.get_table().lookup('CURRENCY', 'CHF')

        if not currency:
            raise LookupError('Currency ({0}) not found'.format(d['Currency']))

        trans = Transaction(book)
        trans.BeginEdit()
        trans.SetCurrency(currency)
        date = d.get('Date', datetime.date.today())
        trans.SetDate(date.day, date.month, date.year)
        # trans.SetDateEnteredTS(datetime.datetime.now())
        # trans.SetDatePostedTS(item.date)
        trans.SetDescription(
            d.get('Description', 'Auto Generated by Json import'))

        amount = int(d.get('Amount', 0) * currency.get_fraction())

        split1 = Split(book)
        split1.SetParent(trans)
        split1.SetAccount(from_ac)

        split1.SetValue(GncNumeric(amount, currency.get_fraction()))
        split1.SetAmount(GncNumeric(amount, currency.get_fraction()))

        split2 = Split(book)
        split2.SetParent(trans)
        split2.SetAccount(to_ac)

        split2.SetValue(GncNumeric(amount * -1, currency.get_fraction()))
        split2.SetAmount(GncNumeric(amount * -1, currency.get_fraction()))

        trans.CommitEdit()
        logging.info(
            'New Transfer: Amount {0} , from:{1},  to:{2}, memo: {3}'.format(
                d.get('Amount', 0), d['TransferFromAC'], d['TransferToAC'],
                d.get('Description', 'Auto Generated by Json import')))
Exemplo n.º 12
0
    def write_transactions(self, transactions):
        for transaction in transactions:

            tx = Transaction(self.book)
            tx.BeginEdit()
            tx.SetCurrency(self.currency)
            tx.SetDateEnteredTS(datetime.datetime.now())
            tx.SetDatePostedTS(transaction.datetime)
            tx.SetDescription(transaction.description)
            tx.SetNotes(transaction.note)

            for split in transaction.splits:
                sp = Split(self.book)
                sp.SetParent(tx)
                sp.SetAccount(GnucashBook.lookup_account(self, split.account))
                sp.SetMemo(split.memo)
                amount = int(
                    Decimal(split.amount) * self.currency.get_fraction())
                sp.SetValue(GncNumeric(amount, self.currency.get_fraction()))
                sp.SetAmount(GncNumeric(amount, self.currency.get_fraction()))

            tx.CommitEdit()
Exemplo n.º 13
0
def query_transactions(book, terms=[]):

    query = Query()
    query.search_for('Trans')
    query.set_book(book)

    if terms:
        for term in terms:
            query.add_term(*term)

    transactions = []

    for transaction in query.run():
        transaction = Transaction(
            instance=transaction)  # ToDo: query.run() should return objects
        transactions.append(transaction)

    query.destroy()
    return transactions
Exemplo n.º 14
0
    def test_assignlots(self):
        abc = GncCommodity(self.book, 'ABC Fund',
            'COMMODITY','ABC','ABC',100000)
        self.table.insert(abc)
        self.account.SetCommodity(abc)

        other = Account(self.book)
        other.SetCommodity(self.currency)

        tx = Transaction(self.book)
        tx.BeginEdit()
        tx.SetCurrency(self.currency)
        tx.SetDateEnteredSecs(datetime.now())
        tx.SetDatePostedSecs(datetime.now())

        s1a = Split(self.book)
        s1a.SetParent(tx)
        s1a.SetAccount(self.account)
        s1a.SetAmount(GncNumeric(1.3))
        s1a.SetValue(GncNumeric(100.0))

        s1b = Split(self.book)
        s1b.SetParent(tx)
        s1b.SetAccount(other)
        s1b.SetAmount(GncNumeric(-100.0))
        s1b.SetValue(GncNumeric(-100.0))

        s2a = Split(self.book)
        s2a.SetParent(tx)
        s2a.SetAccount(self.account)
        s2a.SetAmount(GncNumeric(-1.3))
        s2a.SetValue(GncNumeric(-100.0))

        s2b = Split(self.book)
        s2b.SetParent(tx)
        s2b.SetAccount(other)
        s2b.SetAmount(GncNumeric(100.0))
        s2b.SetValue(GncNumeric(100.0))

        tx.CommitEdit()

        self.account.ScrubLots()
        self.assertEqual(len(self.account.GetLotList()),1)
Exemplo n.º 15
0
    def create_gnc_trade_txs(self, tx1:dict, tx2:dict):
        """
        Create and load Gnucash transactions to the Gnucash file
        :param tx1: first transaction
        :param tx2: matching transaction if a switch
        :return: nil
        """
        self.logger.print_info('create_gnc_trade_txs()', BLUE)
        # create a gnucash Tx
        gtx = Transaction(self.book)
        # gets a guid on construction

        gtx.BeginEdit()

        gtx.SetCurrency(self.currency)
        gtx.SetDate(tx1[TRADE_DAY], tx1[TRADE_MTH], tx1[TRADE_YR])
        # self.dbg.print_info("gtx date = {}".format(gtx.GetDate()), BLUE)
        self.logger.print_info("tx1[DESC] = {}".format(tx1[DESC]), YELLOW)
        gtx.SetDescription(tx1[DESC])

        # create the ASSET split for the Tx
        spl_ast = Split(self.book)
        spl_ast.SetParent(gtx)
        # set the account, value, and units of the Asset split
        spl_ast.SetAccount(tx1[ACCT])
        spl_ast.SetValue(GncNumeric(tx1[GROSS], 100))
        spl_ast.SetAmount(GncNumeric(tx1[UNITS], 10000))

        if tx1[SWITCH]:
            # create the second ASSET split for the Tx
            spl_ast2 = Split(self.book)
            spl_ast2.SetParent(gtx)
            # set the Account, Value, and Units of the second ASSET split
            spl_ast2.SetAccount(tx2[ACCT])
            spl_ast2.SetValue(GncNumeric(tx2[GROSS], 100))
            spl_ast2.SetAmount(GncNumeric(tx2[UNITS], 10000))
            # set Actions for the splits
            spl_ast2.SetAction("Buy" if tx1[UNITS] < 0 else "Sell")
            spl_ast.SetAction("Buy" if tx1[UNITS] > 0 else "Sell")
            # combine Notes for the Tx and set Memos for the splits
            gtx.SetNotes(tx1[NOTES] + " | " + tx2[NOTES])
            spl_ast.SetMemo(tx1[NOTES])
            spl_ast2.SetMemo(tx2[NOTES])
        else:
            # the second split is for a REVENUE account
            spl_rev = Split(self.book)
            spl_rev.SetParent(gtx)
            # set the Account, Value and Reconciled of the REVENUE split
            spl_rev.SetAccount(tx1[REVENUE])
            rev_gross = tx1[GROSS] * -1
            # self.dbg.print_info("revenue gross = {}".format(rev_gross))
            spl_rev.SetValue(GncNumeric(rev_gross, 100))
            spl_rev.SetReconcile(CREC)
            # set Notes for the Tx
            gtx.SetNotes(tx1[NOTES])
            # set Action for the ASSET split
            action = FEE if FEE in tx1[DESC] else ("Sell" if tx1[UNITS] < 0 else DIST)
            self.logger.print_info("action = {}".format(action))
            spl_ast.SetAction(action)

        # ROLL BACK if something went wrong and the two splits DO NOT balance
        if not gtx.GetImbalanceValue().zero_p():
            self.logger.print_error("Gnc tx IMBALANCE = {}!! Roll back transaction changes!"
                                    .format(gtx.GetImbalanceValue().to_string()))
            gtx.RollbackEdit()
            return

        if self.mode == PROD:
            self.logger.print_info("Mode = {}: Commit transaction changes.\n".format(self.mode), GREEN)
            gtx.CommitEdit()
        else:
            self.logger.print_info("Mode = {}: Roll back transaction changes!\n".format(self.mode), RED)
            gtx.RollbackEdit()
Exemplo n.º 16
0
 def test_transaction(self):
     TRANS = Transaction(self.book)
     self.split.SetParent(TRANS)
     TRANS.SetDescription("Foo")
     self.assertEquals( TRANS.GetDescription(), self.split.GetParent().GetDescription() )
Exemplo n.º 17
0
                                     opposing_acct_path))

                        if ignore_this_transaction:

                            debug_print('Ignoring transaction %s' %
                                        get_transaction_string(txinfo))

                        else:

                            debug_print('Adding transaction %s' %
                                        get_transaction_string(txinfo))
                            gnc_amount = decimal_to_gnc_numeric(
                                txinfo['amount'])

                            # From example script 'test_imbalance_transaction.py'
                            trans = Transaction(book)
                            trans.BeginEdit()
                            trans.SetCurrency(USD)
                            trans.SetDescription(str(txinfo['description']))
                            trans.SetDate(txinfo['date'].day,
                                          txinfo['date'].month,
                                          txinfo['date'].year)

                            split1 = Split(book)
                            split1.SetParent(trans)
                            split1.SetAccount(acct)
                            if txinfo.has_key('memo'):
                                split1.SetMemo(str(txinfo['memo']))
                            # The docs say both of these are needed:
                            # http://svn.gnucash.org/docs/HEAD/group__Transaction.html
                            split1.SetValue(gnc_amount)
Exemplo n.º 18
0
def create_split_transaction(book,
                             bank_acc_name,
                             exp_acc_name,
                             trans_date,
                             description,
                             amount,
                             vat_incl=True):
    """
    @todo: more generic handling of assets/income/expenses/liabilities
    """
    root = book.get_root_account()
    comm_table = book.get_table()
    currency = comm_table.lookup("CURRENCY", settings.GNUCASH_CURRENCY)

    bank_acc = root.lookup_by_name(bank_acc_name)
    exp_acc = root.lookup_by_name(exp_acc_name)
    if vat_incl:
        vat_acc = root.lookup_by_name(settings.GNUCASH_VAT_ACCOUNT)

    trans1 = Transaction(book)
    trans1.BeginEdit()

    num1 = gnc_numeric_from_decimal(amount)  # total
    if vat_incl:
        num2 = gnc_numeric_from_decimal(
            (amount / Decimal(settings.GNUCASH_VAT_RATE)).quantize(
                Decimal("0.01")))  # subtotal
        num3 = gnc_numeric_from_decimal(
            amount - (amount / Decimal(settings.GNUCASH_VAT_RATE)).quantize(
                Decimal("0.01")))  # vat
    else:
        num2 = num1  # total

    if bank_acc_name == settings.GNUCASH_CARD_ACCOUNT:
        num1 = num1.neg()
        num2 = num2.neg()
        try:
            num3 = num3.neg()
        except NameError:
            pass

    split1 = Split(book)
    split1.SetAccount(exp_acc)
    split1.SetParent(trans1)
    split1.SetValue(num2.neg())

    if vat_incl:
        split2 = Split(book)
        split2.SetAccount(vat_acc)
        split2.SetParent(trans1)
        split2.SetValue(num3.neg())

    split3 = Split(book)
    split3.SetAccount(bank_acc)
    split3.SetParent(trans1)
    split3.SetValue(num1)

    trans1.SetCurrency(currency)
    trans1.SetDate(trans_date.day, trans_date.month, trans_date.year)
    trans1.SetDescription(description)

    trans1.CommitEdit()
Exemplo n.º 19
0
#!/usr/bin/env python
# Creates a basic set of accounts and a couple of transactions

from gnucash import Session, Account, Transaction, Split, GncNumeric

FILE_1 = "/tmp/example.gnucash"

session = Session("xml:%s" % FILE_1, True)

book = session.book
root_acct = Account(book)
expenses_acct = Account(book)
savings_acct = Account(book)
opening_acct = Account(book)
trans1 = Transaction(book)
trans2 = Transaction(book)
split1 = Split(book)
split3 = Split(book)
comm_table = book.get_table()
cad = comm_table.lookup("CURRENCY", "CAD")

num1 = GncNumeric(4, 1)
num2 = GncNumeric(100, 1)

#Set new root account
book.set_root_account(root_acct)

#Set up root account and add sub-accounts
root_acct.SetName("Root")
root_acct.SetType(13)  #ACCT_TYPE_ROOT = 13
root_acct.append_child(expenses_acct)
Exemplo n.º 20
0
 def NewTransaction(self):
     t = Transaction(self._book)
     t.BeginEdit()
     t.SetCurrency(self.commods['USD'])
     return t
Exemplo n.º 21
0
  root = book.get_root_account()
  currency = book.get_table().lookup('ISO4217', conf.get(args.settings, 'Currency'))

  for tx in txs:
    src_acc = lookup_account(root, tx['src_account'])
    dest_acc = lookup_account(root, tx['dest_account'])

    if src_acc == None:
      print "Couldn't find src account '%s'" % tx['src_account']
      continue

    if dest_acc == None:
      print "Couldn't find dest account '%s'" % tx['dest_account']
      continue

    gtx = Transaction(book)
    gtx.BeginEdit()
    gtx.SetCurrency(currency)
    gtx.SetDateEnteredTS(today)
    gtx.SetDatePostedTS(tx['date']) # or another datetime object for the transaction's "register date"
    gtx.SetDescription(str(tx['label']))

    amount = tx['amount'] * 100

    sp1 = Split(book) # First half of transaction
    sp1.SetParent(gtx)

    # The lookup string needs to match your account path exactly.
    sp1.SetAccount(dest_acc)
    # amount is an int (no $ or .), so $5.23 becomes amount=523
    sp1.SetValue(GncNumeric(amount, 100)) # Assuming you only have one split
Exemplo n.º 22
0
    amount2 = amount * (-1)
    print("amount2 = {0}".format(amount2))

    #     print("new guid = {0}".format(guid_to_string(guid_new_return())))

    acct1_name = argv[2]
    acct2_name = argv[3]
    acct1 = root.lookup_by_name(acct1_name)
    acct2 = root.lookup_by_name(acct2_name)
    #     acct1 = root.lookup_by_code(acct1_code)

    #     type_acct1 = acct1.GetTypeStr()
    #     type_acct2 = acct2.GetTypeStr()

    # create a new Tx
    tx = Transaction(book)
    # gets a guid on construction
    print("tx guid = {0}".format(tx.GetGUID().to_string()))

    tx.BeginEdit()

    # create two splits for the Tx
    s1 = Split(book)
    s1.SetParent(tx)
    # gets a guid on construction
    print("s1 guid = {0}".format(s1.GetGUID().to_string()))
    s2 = Split(book)
    s2.SetParent(tx)
    # gets a guid on construction
    print("s2 guid = {0}".format(s2.GetGUID().to_string()))
Exemplo n.º 23
0
root.get_instance()
commod_tab = session.book.get_table()
CAD = commod_tab.lookup("ISO4217", "CAD")
USD = commod_tab.lookup("ISO4217", "USD")
account = Account(book)
account2 = Account(book)
root.append_child(account)
root.append_child(account2)
account.SetCommodity(CAD)
account.SetName("blahblah")
account.SetType(3)
account2.SetCommodity(USD)
account2.SetName("blahblahsdfs ")
account2.SetType(3)

a = Transaction(book)
a.BeginEdit()

s = Split(book)
s.SetParent(a)
s2 = Split(book)
s2.SetParent(a)

a.SetCurrency(CAD)
s.SetAccount(account)
s.SetValue(GncNumeric(2))
s.SetAmount(GncNumeric(2))

s2.SetAccount(account2)
s2.SetValue(GncNumeric(4))
s2.SetAmount(GncNumeric(4))
Exemplo n.º 24
0
## @file
# @brief Creates a basic set of accounts and a couple of transactions
# @ingroup python_bindings_examples

from gnucash import Session, Account, Transaction, Split, GncNumeric

FILE_1 = "/tmp/example.gnucash"

session = Session("xml://%s" % FILE_1, is_new=True)

book = session.book
root_acct = Account(book)
expenses_acct = Account(book)
savings_acct = Account(book)
opening_acct = Account(book)
trans1 = Transaction(book)
trans1.BeginEdit()
trans2 = Transaction(book)
trans2.BeginEdit()

split1 = Split(book)
split3 = Split(book)
comm_table = book.get_table()
cad = comm_table.lookup("CURRENCY", "CAD")

num1 = GncNumeric(4, 1)
num2 = GncNumeric(100, 1)

#Set new root account
book.set_root_account(root_acct)
Exemplo n.º 25
0
def __transaction__str__(self):
    """__str__ method for Transaction class"""
    from gnucash import Transaction

    self=Transaction(instance=self)
    return unicode(self).encode('utf-8')