mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Querying and listing all invoices now possible
This commit is contained in:
parent
9595062e5f
commit
765d73f903
@ -46,12 +46,12 @@ def main(argv=None):
|
||||
filename_template = None
|
||||
filename_output = None
|
||||
no_output = False
|
||||
list_invoices = True
|
||||
list_invoices = False
|
||||
invoice_number = None
|
||||
invoice_id = None
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(argv[1:], "fhI:t:o:", ["help"])
|
||||
opts, args = getopt.getopt(argv[1:], "fhlI:t:o:", ["help"])
|
||||
except getopt.error, msg:
|
||||
raise Usage(msg)
|
||||
|
||||
@ -70,6 +70,9 @@ def main(argv=None):
|
||||
if opt[0] in ["-t"]:
|
||||
filename_template = opt[1]
|
||||
print "using template file", filename_template
|
||||
if opt[0] in ["-l"]:
|
||||
list_invoices = True
|
||||
print "listing invoices"
|
||||
|
||||
# Check for correct input
|
||||
if len(args)>1:
|
||||
@ -81,11 +84,15 @@ def main(argv=None):
|
||||
|
||||
# Check for correct template
|
||||
if not filename_template:
|
||||
no_output = True
|
||||
if not list_invoices:
|
||||
raise Usage("No template given !")
|
||||
|
||||
# Check for output file
|
||||
if not filename_output:
|
||||
if filename_template:
|
||||
filename_output = filename_template + ".out"
|
||||
print "no output filename given, will be:", filename_output
|
||||
|
||||
except Usage, err:
|
||||
if err.msg == "Help:":
|
||||
@ -105,8 +112,9 @@ def main(argv=None):
|
||||
print "or mysql://user:password@host/databasename"
|
||||
print
|
||||
print "-f force open = ignore lock"
|
||||
print "-l list all invoices"
|
||||
print "-h or --help for this help"
|
||||
print "-I ID invoice with this ID"
|
||||
print "-I ID use invoice ID"
|
||||
print "-t filename use filename as template file"
|
||||
print "-o filename use filename as output file"
|
||||
|
||||
@ -126,12 +134,12 @@ def main(argv=None):
|
||||
comm_table = book.get_table()
|
||||
EUR = comm_table.lookup("CURRENCY", "EUR")
|
||||
|
||||
# invoice_list = get_all_invoices(book)
|
||||
invoice_list = get_all_invoices(book)
|
||||
|
||||
# if list_invoices:
|
||||
# for number,invoice in enumerate(invoice_list):
|
||||
# print str(number)+")"
|
||||
# print invoice
|
||||
if list_invoices:
|
||||
for number,invoice in enumerate(invoice_list):
|
||||
print str(number)+")"
|
||||
print invoice
|
||||
|
||||
if not (no_output):
|
||||
|
||||
|
@ -39,17 +39,48 @@ def get_all_invoices_from_lots(account):
|
||||
invoice_list.append(Invoice(instance=invoice))
|
||||
return invoice_list
|
||||
|
||||
def get_all_invoices(book):
|
||||
"""Returns all invoices in the book."""
|
||||
def 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
|
||||
"""
|
||||
|
||||
query = gnucash.Query()
|
||||
query.search_for('gncInvoice')
|
||||
query.set_book(book)
|
||||
|
||||
if is_paid == 0:
|
||||
query.add_boolean_match([gnucash.INVOICE_IS_PAID], False, gnucash.QOF_QUERY_AND)
|
||||
elif is_paid == 1:
|
||||
query.add_boolean_match([gnucash.INVOICE_IS_PAID], True, gnucash.QOF_QUERY_AND)
|
||||
elif is_paid == None:
|
||||
pass
|
||||
|
||||
# active = JOB_IS_ACTIVE
|
||||
if is_active == 0:
|
||||
query.add_boolean_match(['active'], False, gnucash.QOF_QUERY_AND)
|
||||
elif is_active == 1:
|
||||
query.add_boolean_match(['active'], True, gnucash.QOF_QUERY_AND)
|
||||
elif is_active == None:
|
||||
pass
|
||||
|
||||
# return only invoices (1 = invoices)
|
||||
pred_data = gnucash.gnucash_core.QueryInt32Predicate(gnucash.QOF_COMPARE_EQUAL, 1)
|
||||
query.add_term([gnucash.INVOICE_TYPE], pred_data, gnucash.QOF_QUERY_AND)
|
||||
|
||||
invoice_list = []
|
||||
invoice = True
|
||||
invoice_id = 0
|
||||
while invoice:
|
||||
invoice_id += 1
|
||||
invoice = book.InvoiceLookupByID('%06d' % invoice_id)
|
||||
if invoice:
|
||||
invoice_list.append(invoice)
|
||||
|
||||
result = query.run()
|
||||
for result in query.run():
|
||||
invoice_list.append(Invoice(instance=result))
|
||||
|
||||
query.destroy()
|
||||
|
||||
return invoice_list
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user