gnucash/src/optional/python-bindings/example_scripts/simple_test.py
Phil Longstaff f229f9ac8e Python bindings patches by Mark Jenkins.
python_GetNthChild_remove.patch
remove the redundant GetNthChild code, gnc_account_nth_child supported

python_more_GUID.patch
Improve support for GUID


python_better_commodity.patch
* Removed custom __init__ from GncCommodity, not only is it wrong but 
the one
from GnuCashCoreClass is just fine.

* Supported the get_table method For Book

* Removed support for direct instantiation of GncCommodityTable. (via
gnc_commodity_table_new() ). Only methods and not the constructor
function are added to the class now. Python binding users can access a
GncCommodityTable instance via Book.get_table() and have no need to use
gnc_commodity_table_new(), which the apis advise is for internal use
only.


python_GncLot.patch
* included gnc-lot.h in gnucash_core.i again

* Made GncLot class use superclass __init__, it doesn't need its own.


python_more_documentation.patch
Documentation strings for many classes, which can be viewed in source 
and with python's help() mechanism.


python_business_module_load.patch
load the business module, not the business module specific backend


python_example_scripts.py
example scripts improved, new one added.  This new script originally 
came from this post:
http://lists.gnucash.org/pipermail/gnucash-devel/2008-July/023618.html


python_authors_update.patch
added Legal Aid Manitoba to credit line for Mark Jenkins


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18291 57a11ea4-9604-0410-9ed3-97b8803252fd
2009-09-05 00:11:31 +00:00

80 lines
1.8 KiB
Python

#!/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)
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)
split1.SetParent(trans1)
split3.SetValue(num2)
split3.SetAccount(savings_acct)
split3.SetParent(trans2)
trans1.SetCurrency(cad)
trans1.SetDescription("Groceries")
trans2.SetCurrency(cad)
trans2.SetDescription("Opening Savings Balance")
split2 = split1.GetOtherSplit()
split2.SetAccount(savings_acct)
split4 = split3.GetOtherSplit()
split4.SetAccount(opening_acct)
book.print_dirty()
book.mark_saved()
book.mark_closed()
book.print_dirty()
session.save()
session.end()
session.destroy()