def createAccounts(book): root_account = book.get_root_account() commodtable = book.get_table() currency = commodtable.lookup("CURRENCY", "EUR") ses.save() print('Create two accounts ("Account A", "Account B")') accountA = Account(book) accountA.SetCommodity(currency) accountA.SetName("Account A") root_account.append_child(accountA) accountB = Account(book) accountB.SetCommodity(currency) accountB.SetName("Account B") root_account.append_child(accountB) #ses.save() return accountA, accountB
def find_or_make_account(account_tuple, root_account, book, currency): current_account_name, account_path = account_tuple[0], account_tuple[1:] current_account = root_account.lookup_by_name(current_account_name) if current_account == None: current_account = Account(book) current_account.SetName(current_account_name) current_account.SetCommodity(currency) root_account.append_child(current_account) if len(account_path) > 0: return find_or_make_account(account_path, current_account, book, currency) else: account_commod = current_account.GetCommodity() if (account_commod.get_mnemonic(), account_commod.get_namespace() ) == \ (currency.get_mnemonic(), currency.get_namespace()) : return current_account else: return None
def new_tax(root, book, USD, row): if row['type'] == 'Sales Tax Item': tablename = row['item'] parent = root.lookup_by_name(row['account']) account = Account(book) parent.append_child(account) account.SetName(tablename) account.SetType(ACCT_TYPE_LIABILITY) account.SetCommodity(USD) rate = gnc_numeric_from(row['rate']) # Skip existing tax table and create new ones try: assert ( not isinstance(book.TaxTableLookupByName(tablename), TaxTable) ) TaxTable(book, tablename, TaxTableEntry(account, True, rate)) except AssertionError: print '"%s" tax table already exists, skipping' \ % tablename # Add method to update rate return 0 return 1
#!/usr/bin/env python3 ## @file # @brief Example Script simple sqlite create # @ingroup python_bindings_examples from gnucash import Session, Account from os.path import abspath from gnucash.gnucash_core_c import ACCT_TYPE_ASSET s = Session('sqlite3://%s' % abspath('test.blob'), is_new=True) # this seems to make a difference in more complex cases s.save() book = s.book root = book.get_root_account() a = Account(book) root.append_child(a) a.SetName('wow') a.SetType(ACCT_TYPE_ASSET) commod_table = book.get_table() a.SetCommodity( commod_table.lookup('CURRENCY', 'CAD') ) s.save() s.end()
print('example:') print( "python3 simple_business_create.py sqlite3:///home/blah/blah.gnucash") exit() try: s = Session(argv[1], SessionOpenMode.SESSION_NEW_STORE) book = s.book root = book.get_root_account() commod_table = book.get_table() CAD = commod_table.lookup('CURRENCY', 'CAD') a = Account(book) root.append_child(a) a.SetName('Assets') a.SetType(ACCT_TYPE_ASSET) a.SetCommodity(CAD) a2 = Account(book) a.append_child(a2) a2.SetName('Receivables') a2.SetType(ACCT_TYPE_RECEIVABLE) a2.SetCommodity(CAD) a3 = Account(book) root.append_child(a3) a3.SetName('Income') a3.SetType(ACCT_TYPE_INCOME) a3.SetCommodity(CAD)
# You should try it out with a gnucash file with tranding accounts enabled # and trading accounts disabled session = Session(argv[1]) book = session.book root = book.get_root_account() 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)
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) #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) root_acct.append_child(savings_acct) root_acct.append_child(opening_acct) #Set up Expenses account expenses_acct.SetCommodity(cad) expenses_acct.SetName("Expenses") expenses_acct.SetType(9) #ACCT_TYPE_EXPENSE = 9 #Set up Savings account savings_acct.SetCommodity(cad) savings_acct.SetName("Savings") savings_acct.SetType(0) #ACCT_TYPE_BANK = 0