2019-04-04 14:50:05 +02:00
|
|
|
#!/usr/bin/env python3
|
2010-12-17 20:36:40 +00:00
|
|
|
## @file
|
|
|
|
|
# @brief Example Script simple sqlite create
|
2010-12-27 15:36:15 +00:00
|
|
|
# @ingroup python_bindings_examples
|
2010-06-30 19:26:57 +00:00
|
|
|
|
2020-06-12 12:24:05 +02:00
|
|
|
from gnucash import Session, Account, SessionOpenMode
|
2010-06-30 19:26:57 +00:00
|
|
|
from os.path import abspath
|
|
|
|
|
from gnucash.gnucash_core_c import ACCT_TYPE_ASSET
|
|
|
|
|
|
2020-06-12 12:24:05 +02:00
|
|
|
s = Session('sqlite3://%s' % abspath('test.blob'), SessionOpenMode.SESSION_NEW_STORE)
|
2010-06-30 19:26:57 +00:00
|
|
|
# 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()
|