GnuCash c935c2f+
Loading...
Searching...
No Matches
gncinvoicefkt.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4
17
18try:
19 import gnucash
20 from gnucash.gnucash_business import Customer, Employee, Vendor, Job, \
21 Address, Invoice, Entry, TaxTable, TaxTableEntry, GNC_AMT_TYPE_PERCENT, \
22 GNC_DISC_PRETAX
23 import str_methods
24except ImportError as import_error:
25 print("Problem importing modules.")
26 print(import_error)
27 sys.exit(2)
28
29def 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 ll=desc.GetLotList()
35 ltotal+=ll
36 return ltotal
37
38def get_all_invoices_from_lots(account):
39 """Return all invoices in account and descendants
40
41 This is based on lots. So invoices without lots will be missed."""
42
43 lot_list=get_all_lots(account)
44 invoice_list=[]
45 for lot in lot_list:
46 invoice=gnucash.gnucash_core_c.gncInvoiceGetInvoiceFromLot(lot.instance)
47 if invoice:
48 invoice_list.append(Invoice(instance=invoice))
49 return invoice_list
50
51def get_all_invoices(book, is_paid=None, is_active=None):
52 """Returns a list of all invoices in the book.
53
54 Posts a query to search for all invoices.
55
56 arguments:
57 book the gnucash book to work with
58 keyword-arguments:
59 is_paid int 1 to search for invoices having been paid, 0 for not, None to ignore.
60 is_active int 1 to search for active invoices
61 """
62
63 query = gnucash.Query()
64 query.search_for('gncInvoice')
65 query.set_book(book)
66
67 if is_paid == 0:
68 query.add_boolean_match([gnucash.INVOICE_IS_PAID], False, gnucash.QOF_QUERY_AND)
69 elif is_paid == 1:
70 query.add_boolean_match([gnucash.INVOICE_IS_PAID], True, gnucash.QOF_QUERY_AND)
71 elif is_paid == None:
72 pass
73
74 # active = JOB_IS_ACTIVE
75 if is_active == 0:
76 query.add_boolean_match(['active'], False, gnucash.QOF_QUERY_AND)
77 elif is_active == 1:
78 query.add_boolean_match(['active'], True, gnucash.QOF_QUERY_AND)
79 elif is_active == None:
80 pass
81
82 # return only invoices (1 = invoices)
83 pred_data = gnucash.gnucash_core.QueryInt32Predicate(gnucash.QOF_COMPARE_EQUAL, 1)
84 query.add_term([gnucash.INVOICE_TYPE], pred_data, gnucash.QOF_QUERY_AND)
85
86 invoice_list = []
87
88 for result in query.run():
89 invoice_list.append(Invoice(instance=result))
90
91 query.destroy()
92
93 return invoice_list
94
95def get_all_customers(book):
96 """Returns all customers in book.
97
98 Posts a query to search for all customers.
99
100 arguments:
101 book the gnucash book to work with
102 """
103
104 query = gnucash.Query()
105 query.search_for('gncCustomer')
106 query.set_book(book)
107
108 customer_list = []
109
110 for result in query.run():
111 customer_list.append(Customer(instance=result))
112
113 query.destroy()
114
115 return customer_list