7 Session, Account, Transaction, Split, GncNumeric, SessionOpenMode)
9 FILE_1 =
"/tmp/example.gnucash" 11 with Session(
"xml://%s" % FILE_1, SessionOpenMode.SESSION_NEW_STORE)
as session:
18 trans1 = Transaction(book)
20 trans2 = Transaction(book)
25 comm_table = book.get_table()
26 cad = comm_table.lookup(
"CURRENCY",
"CAD")
32 book.set_root_account(root_acct)
35 root_acct.SetName(
"Root")
37 root_acct.append_child(expenses_acct)
38 root_acct.append_child(savings_acct)
39 root_acct.append_child(opening_acct)
42 expenses_acct.SetCommodity(cad)
43 expenses_acct.SetName(
"Expenses")
44 expenses_acct.SetType(9)
47 savings_acct.SetCommodity(cad)
48 savings_acct.SetName(
"Savings")
49 savings_acct.SetType(0)
52 opening_acct.SetCommodity(cad)
53 opening_acct.SetName(
"Opening Balance")
54 opening_acct.SetType(10)
57 split1.SetAccount(expenses_acct)
58 split1.SetParent(trans1)
61 split3.SetAccount(savings_acct)
62 split3.SetParent(trans2)
64 trans1.SetCurrency(cad)
65 trans1.SetDate(14, 3, 2006)
66 trans1.SetDescription(
"Groceries")
68 trans2.SetCurrency(cad)
69 trans2.SetDate(7, 11, 1995)
70 trans2.SetDescription(
"Opening Savings Balance")
73 split2.SetAccount(savings_acct)
74 split2.SetParent(trans1)
75 split2.SetValue(num1.neg())
78 split4.SetAccount(opening_acct)
79 split4.SetParent(trans2)
80 split4.SetValue(num2.neg())
The primary numeric class for representing amounts and values.