20 from gnucash.gnucash_business
import Customer, Employee, Vendor, Job, \
21 Address, Invoice, Entry, TaxTable, TaxTableEntry, GNC_AMT_TYPE_PERCENT, \
24 except ImportError
as import_error:
25 print(
"Problem importing modules.")
29 def get_all_lots(account):
30 """Return all lots in account and descendants""" 32 descs = account.get_descendants()
34 if type(desc).__name__ ==
'SwigPyObject':
35 desc = gnucash.Account(instance=desc)
40 def get_all_invoices_from_lots(account):
41 """Return all invoices in account and descendants 43 This is based on lots. So invoices without lots will be missed.""" 45 lot_list=get_all_lots(account)
48 if type(lot).__name__ ==
'SwigPyObject':
49 lot = gnucash.GncLot(instance=lot)
51 invoice=gnucash.gnucash_core_c.gncInvoiceGetInvoiceFromLot(lot.instance)
53 invoice_list.append(Invoice(instance=invoice))
56 def get_all_invoices(book, is_paid=None, is_active=None):
57 """Returns a list of all invoices in the book. 59 Posts a query to search for all invoices. 62 book the gnucash book to work with 64 is_paid int 1 to search for invoices having been paid, 0 for not, None to ignore. 65 is_active int 1 to search for active invoices 68 query = gnucash.Query()
69 query.search_for(
'gncInvoice')
73 query.add_boolean_match([gnucash.INVOICE_IS_PAID],
False, gnucash.QOF_QUERY_AND)
75 query.add_boolean_match([gnucash.INVOICE_IS_PAID],
True, gnucash.QOF_QUERY_AND)
81 query.add_boolean_match([
'active'],
False, gnucash.QOF_QUERY_AND)
83 query.add_boolean_match([
'active'],
True, gnucash.QOF_QUERY_AND)
84 elif is_active ==
None:
88 pred_data = gnucash.gnucash_core.QueryInt32Predicate(gnucash.QOF_COMPARE_EQUAL, 1)
89 query.add_term([gnucash.INVOICE_TYPE], pred_data, gnucash.QOF_QUERY_AND)
93 for result
in query.run():
94 invoice_list.append(Invoice(instance=result))
100 def get_all_customers(book):
101 """Returns all customers in book. 103 Posts a query to search for all customers. 106 book the gnucash book to work with 109 query = gnucash.Query()
110 query.search_for(
'gncCustomer')
115 for result
in query.run():
116 customer_list.append(Customer(instance=result))