class BusinessSession( BookSession ): def setUp(self): BookSession.setUp(self) self.today = datetime.today() self.bank = Account(self.book) self.bank.SetType(ACCT_TYPE_BANK) self.bank.SetCommodity(self.currency) self.income = Account(self.book) self.income.SetType(ACCT_TYPE_INCOME) self.income.SetCommodity(self.currency) self.receivable = Account(self.book) self.receivable.SetType(ACCT_TYPE_RECEIVABLE) self.receivable.SetCommodity(self.currency) self.customer = Customer(self.book,'CustomerID',self.currency) self.vendor = Vendor(self.book,'VendorID',self.currency) self.employee = Employee(self.book,'EmployeeID',self.currency) self.job = Job(self.book,'JobID',self.customer) self.invoice = Invoice(self.book,'InvoiceID',self.currency,self.customer) self.invoice.SetDateOpened(self.today) entry = Entry(self.book) entry.SetDate(self.today) entry.SetDescription("Some income") entry.SetQuantity(GncNumeric(1)) entry.SetInvAccount(self.income) entry.SetInvPrice(GncNumeric(100)) self.invoice.AddEntry(entry) self.invoice.PostToAccount(self.receivable, self.today, self.today, "", True, False)
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 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)
def recursivly_build_account_tree(original_parent_account, new_parent_account, new_book, new_commodity_table, opening_balance_per_currency, account_types_to_open): for child in original_parent_account.get_children(): original_account = child new_account = Account(new_book) # attach new account to its parent new_parent_account.append_child(new_account) # copy simple attributes for attribute in ('Name', 'Type', 'Description', 'Notes', 'Code', 'TaxRelated', 'Placeholder'): # new_account.SetAttribute( original_account.GetAttribute() ) getattr(new_account, 'Set' + attribute)(getattr(original_account, 'Get' + attribute)()) # copy commodity orig_commodity = original_account.GetCommodity() namespace = orig_commodity.get_namespace() mnemonic = orig_commodity.get_mnemonic() new_commodity = new_commodity_table.lookup(namespace, mnemonic) if new_commodity == None: new_commodity = orig_commodity.clone(new_book) new_commodity_table.insert(new_commodity) new_account.SetCommodity(new_commodity) record_opening_balance( original_account, new_account, new_book, opening_balance_per_currency, (namespace, mnemonic), ) recursivly_build_account_tree(original_account, new_account, new_book, new_commodity_table, opening_balance_per_currency, account_types_to_open)
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()
"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) a4 = Account(book) root.append_child(a4)
def test_findsplit(self): ACCT = Account(self.book) ACCT.SetCommodity(self.currency) self.split.SetAccount( ACCT ) SPLIT = self.trans.FindSplitByAccount( ACCT ) self.assertTrue( SPLIT.Equal(self.split, True, False, False) )
# # 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)
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 #Set up Opening Balance account opening_acct.SetCommodity(cad) opening_acct.SetName("Opening Balance") opening_acct.SetType(10) #ACCT_TYPE_EQUITY = 10 split1.SetValue(num1) split1.SetAccount(expenses_acct)
def test_account(self): ACCT = Account(self.book) ACCT.SetCommodity(self.currency) self.split.SetAccount(ACCT) self.assertTrue(ACCT.Equal(self.split.GetAccount(), True))