GnuCash  4.11-137-g155922540d+
Functions

some help for working with invoices, used in Python invoice export More...

Go to the source code of this file.

Functions

def gncinvoicefkt.get_all_lots (account)
 
def gncinvoicefkt.get_all_invoices_from_lots (account)
 
def gncinvoicefkt.get_all_invoices (book, is_paid=None, is_active=None)
 
def gncinvoicefkt.get_all_customers (book)
 

Detailed Description

some help for working with invoices, used in Python invoice export

Author
Christoph Holtermann (c.holtermann (at) gmx.de)
Date
2014-11

Credits to Tom Loft for the query to get_all_invoices as used in his REST-Api

Issues:

Definition in file gncinvoicefkt.py.

Function Documentation

◆ get_all_customers()

def gncinvoicefkt.get_all_customers (   book)
Returns all customers in book.

Posts a query to search for all customers.

arguments:
    book                the gnucash book to work with

Definition at line 100 of file gncinvoicefkt.py.

100 def get_all_customers(book):
101  """Returns all customers in book.
102 
103  Posts a query to search for all customers.
104 
105  arguments:
106  book the gnucash book to work with
107  """
108 
109  query = gnucash.Query()
110  query.search_for('gncCustomer')
111  query.set_book(book)
112 
113  customer_list = []
114 
115  for result in query.run():
116  customer_list.append(Customer(instance=result))
117 
118  query.destroy()
119 
120  return customer_list
121 

◆ get_all_invoices()

def gncinvoicefkt.get_all_invoices (   book,
  is_paid = None,
  is_active = None 
)
Returns a list of all invoices in the book.

Posts a query to search for all invoices.

arguments:
    book                the gnucash book to work with
keyword-arguments:
    is_paid     int     1 to search for invoices having been paid, 0 for not, None to ignore.
    is_active   int     1 to search for active invoices

Definition at line 56 of file gncinvoicefkt.py.

56 def get_all_invoices(book, is_paid=None, is_active=None):
57  """Returns a list of all invoices in the book.
58 
59  Posts a query to search for all invoices.
60 
61  arguments:
62  book the gnucash book to work with
63  keyword-arguments:
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
66  """
67 
68  query = gnucash.Query()
69  query.search_for('gncInvoice')
70  query.set_book(book)
71 
72  if is_paid == 0:
73  query.add_boolean_match([gnucash.INVOICE_IS_PAID], False, gnucash.QOF_QUERY_AND)
74  elif is_paid == 1:
75  query.add_boolean_match([gnucash.INVOICE_IS_PAID], True, gnucash.QOF_QUERY_AND)
76  elif is_paid == None:
77  pass
78 
79  # active = JOB_IS_ACTIVE
80  if is_active == 0:
81  query.add_boolean_match(['active'], False, gnucash.QOF_QUERY_AND)
82  elif is_active == 1:
83  query.add_boolean_match(['active'], True, gnucash.QOF_QUERY_AND)
84  elif is_active == None:
85  pass
86 
87  # return only invoices (1 = invoices)
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)
90 
91  invoice_list = []
92 
93  for result in query.run():
94  invoice_list.append(Invoice(instance=result))
95 
96  query.destroy()
97 
98  return invoice_list
99 

◆ get_all_invoices_from_lots()

def gncinvoicefkt.get_all_invoices_from_lots (   account)
Return all invoices in account and descendants

This is based on lots. So invoices without lots will be missed.

Definition at line 40 of file gncinvoicefkt.py.

40 def get_all_invoices_from_lots(account):
41  """Return all invoices in account and descendants
42 
43  This is based on lots. So invoices without lots will be missed."""
44 
45  lot_list=get_all_lots(account)
46  invoice_list=[]
47  for lot in lot_list:
48  if type(lot).__name__ == 'SwigPyObject':
49  lot = gnucash.GncLot(instance=lot)
50 
51  invoice=gnucash.gnucash_core_c.gncInvoiceGetInvoiceFromLot(lot.instance)
52  if invoice:
53  invoice_list.append(Invoice(instance=invoice))
54  return invoice_list
55 

◆ get_all_lots()

def gncinvoicefkt.get_all_lots (   account)
Return all lots in account and descendants

Definition at line 29 of file gncinvoicefkt.py.

29 def get_all_lots(account):
30  """Return all lots in account and descendants"""
31  ltotal=[]
32  descs = account.get_descendants()
33  for desc in descs:
34  if type(desc).__name__ == 'SwigPyObject':
35  desc = gnucash.Account(instance=desc)
36  ll=desc.GetLotList()
37  ltotal+=ll
38  return ltotal
39