GnuCash c935c2f+
Loading...
Searching...
No Matches
Functions | Variables

Some examples for qof queries. More...

Go to the source code of this file.

Functions

 qof.createAccounts (book)
 
 qof.createRandomTransactions (book, accountA, accountB)
 
 qof.query_transactions (book, terms=[])
 
 qof.query_splits (book, terms=[])
 

Variables

str qof.uri = "xml:///tmp/qof.gnucash"
 
 qof.book = ses.get_book()
 
 qof.accountA
 
 qof.accountB
 
 qof.transactions_all = query_transactions(book)
 
 qof.threshold = datetime.datetime(1950,1,1)
 
int qof.QOF_DATE_MATCH_NORMAL = 2
 
list qof.terms = [(['date-posted'], gnucash_core.QueryDatePredicate(QOF_COMPARE_GTE, QOF_DATE_MATCH_NORMAL, threshold), QOF_QUERY_AND)]
 
 qof.transactions_2 = query_transactions(book, terms)
 
bool qof.isRegex = False
 
 qof.transactions_3 = query_transactions(book, terms)
 
 qof.splits_1 = query_splits(book, terms)
 
 qof.splits_2 = query_splits(book, terms)
 
 qof.splits_4 = query_splits(book, terms)
 
 qof.splits_3 = query_splits(book, terms)
 

Detailed Description

Some examples for qof queries.

Author
Christoph Holtermann
Date
2022-03-06
Note
incomplete set of qof examples, to be extended

Definition in file qof.py.

Function Documentation

◆ createAccounts()

qof.createAccounts (   book)

Definition at line 23 of file qof.py.

23def createAccounts(book):
24 root_account = book.get_root_account()
25 commodtable = book.get_table()
26 currency = commodtable.lookup("CURRENCY", "EUR")
27 ses.save()
28
29 print('Create two accounts ("Account A", "Account B")')
30 accountA = Account(book)
31 accountA.SetCommodity(currency)
32 accountA.SetName("Account A")
33 root_account.append_child(accountA)
34
35 accountB = Account(book)
36 accountB.SetCommodity(currency)
37 accountB.SetName("Account B")
38 root_account.append_child(accountB)
39
40 #ses.save()
41
42 return accountA, accountB
43
STRUCTS.

◆ createRandomTransactions()

qof.createRandomTransactions (   book,
  accountA,
  accountB 
)

Definition at line 44 of file qof.py.

44def createRandomTransactions(book, accountA, accountB):
45 split = Split(book)
46
47 currency = book.get_table().lookup("CURRENCY", "EUR")
48
49 print("Create 100 random transactions")
50 for i in range(100):
51
52 trans = Transaction(book)
53 trans.BeginEdit()
54 trans.SetCurrency(currency)
55 trans.SetDate(randint(1,28), randint(1,12), randint(1900,2000))
56 trans.SetDescription("Transaction "+str(i))
57
58 value = randint(0,10000)
59
60 value1 = GncNumeric(value, 100)
61 value2 = GncNumeric(-value, 100)
62
63 split1 = Split(book)
64 split1.SetValue(value1)
65 split1.SetAccount(accountA)
66 split1.SetMemo("A" + str(i))
67 split1.SetParent(trans)
68
69 split2 = Split(book)
70 split2.SetValue(value2)
71 split2.SetAccount(accountB)
72 split2.SetMemo("B" + str(i))
73 split2.SetParent(trans)
74
75 trans.CommitEdit()
76
The primary numeric class for representing amounts and values.

◆ query_splits()

qof.query_splits (   book,
  terms = [] 
)

Definition at line 96 of file qof.py.

96def query_splits(book, terms=[]):
97
98 query = Query()
99 query.search_for('Split')
100 query.set_book(book)
101
102 if terms:
103 for term in terms:
104 query.add_term(*term)
105
106 splits = []
107
108 for split in query.run():
109 split = Split(instance=split) # ToDo: query.run() should return objects
110 splits.append(split)
111
112 query.destroy()
113 return splits
114
A Query.
Definition qofquery.cpp:75

◆ query_transactions()

qof.query_transactions (   book,
  terms = [] 
)

Definition at line 77 of file qof.py.

77def query_transactions(book, terms=[]):
78
79 query = Query()
80 query.search_for('Trans')
81 query.set_book(book)
82
83 if terms:
84 for term in terms:
85 query.add_term(*term)
86
87 transactions = []
88
89 for transaction in query.run():
90 transaction = Transaction(instance=transaction) # ToDo: query.run() should return objects
91 transactions.append(transaction)
92
93 query.destroy()
94 return transactions
95

Variable Documentation

◆ accountA

qof.accountA

Definition at line 118 of file qof.py.

◆ accountB

qof.accountB

Definition at line 118 of file qof.py.

◆ book

qof.book = ses.get_book()

Definition at line 117 of file qof.py.

◆ isRegex

bool qof.isRegex = False

Definition at line 135 of file qof.py.

◆ QOF_DATE_MATCH_NORMAL

int qof.QOF_DATE_MATCH_NORMAL = 2

Definition at line 129 of file qof.py.

◆ splits_1

qof.splits_1 = query_splits(book, terms)

Definition at line 145 of file qof.py.

◆ splits_2

qof.splits_2 = query_splits(book, terms)

Definition at line 151 of file qof.py.

◆ splits_3

qof.splits_3 = query_splits(book, terms)

Definition at line 164 of file qof.py.

◆ splits_4

qof.splits_4 = query_splits(book, terms)

Definition at line 158 of file qof.py.

◆ terms

list qof.terms = [(['date-posted'], gnucash_core.QueryDatePredicate(QOF_COMPARE_GTE, QOF_DATE_MATCH_NORMAL, threshold), QOF_QUERY_AND)]

Definition at line 130 of file qof.py.

◆ threshold

qof.threshold = datetime.datetime(1950,1,1)

Definition at line 128 of file qof.py.

◆ transactions_2

qof.transactions_2 = query_transactions(book, terms)

Definition at line 131 of file qof.py.

◆ transactions_3

qof.transactions_3 = query_transactions(book, terms)

Definition at line 137 of file qof.py.

◆ transactions_all

qof.transactions_all = query_transactions(book)

Definition at line 124 of file qof.py.

◆ uri

str qof.uri = "xml:///tmp/qof.gnucash"

Definition at line 21 of file qof.py.