Hi Christoph,
While the query api isn’t available in Python yet, I’ve made some steps
towards this for the REST API I’ve been working on. Some of this code is
already available in the latest version of Gnucash, mostly in the Python
examples directory at
https://github.com/Gnucash/gnucash/blob/master/src/optional/python-bindings/example_scripts/rest-api/gnucash_rest.py
The code you’ll want is getInvoices which creates a query which then
adds a condition to check for paid/unpaid and active/inactive invoices.
I’ve done a little more work which I haven’t made available publicly
yet, but a work in progress version of this function is also attached.
If you have any queries please let me know.
Kind regards,
Tom
On 10/11/14 15:10, Christoph Holtermann wrote:
Dear developers,
to get my invoices to LaTeX I went to jinja2 templating engine
which works quite fine.
src/optional/python-bindings/example_scripts/gncinvoice_jinja.py
https://github.com/c-holtermann/gnucash/commit/15a69f120569a174837b467d54a22fb1b4345777
I want to be able to show a list of all invoices to select which one to extract.
This leads to my question:
What ways are there to list all invoices (with python) ?
I first went through all lots to get corresponding invoices - which leaves all
invoices without transactions. Did this in latex_invoices.py.
Then I realized that in the python business bindings there is
InvoiceLookupByID which is a good way to access invoices.
But it's not possible by this way to know all IDs.
When I use the way similar to the search dialogue like "all invoices
after 1970 january" I would probably get all invoices. But as far as I
know the query api is not yet open to python, is it ?
Is there another way to get all invoices ?
regards,
Christoph Holtermann
def getInvoices(book, customer, is_paid, is_active, date_due_from, date_due_to):
query = gnucash.Query()
query.search_for('gncInvoice')
query.set_book(book)
if is_paid == 0:
query.add_boolean_match([INVOICE_IS_PAID], False, QOF_QUERY_AND)
elif is_paid == 1:
query.add_boolean_match([INVOICE_IS_PAID], True, QOF_QUERY_AND)
# active = JOB_IS_ACTIVE
if is_active == 0:
query.add_boolean_match(['active'], False, QOF_QUERY_AND)
elif is_active == 1:
query.add_boolean_match(['active'], True, QOF_QUERY_AND)
QOF_PARAM_GUID = 'guid'
INVOICE_OWNER = 'owner'
if customer != None:
customer_guid = gnucash.gnucash_core.GUID()
gnucash.gnucash_core.GUIDString(customer, customer_guid)
query.add_guid_match([INVOICE_OWNER, QOF_PARAM_GUID], customer_guid, QOF_QUERY_AND)
#define INVOICE_DUE "date_due"
# QOF_DATE_MATCH_NORMAL = 1,
# QOF_DATE_MATCH_DAY = 2
# check date format is yyyy-mm-dd
if date_due_from != None:
pred_data = gnucash.gnucash_core.QueryDatePredicate(QOF_COMPARE_GTE, 2, datetime.datetime.strptime(date_due_from, "%Y-%m-%d").date())
query.add_term(['date_due'], pred_data, QOF_QUERY_AND)
if date_due_to != None:
pred_data = gnucash.gnucash_core.QueryDatePredicate(QOF_COMPARE_LTE, 2, datetime.datetime.strptime(date_due_to, "%Y-%m-%d").date())
query.add_term(['date_due'], pred_data, QOF_QUERY_AND)
# return only invoices (1 = invoices)
pred_data = gnucash.gnucash_core.QueryInt32Predicate(QOF_COMPARE_EQUAL, 1)
query.add_term([INVOICE_TYPE], pred_data, QOF_QUERY_AND)
invoices = []
for result in query.run():
invoices.append(gnucash_simple.invoiceToDict(gnucash.gnucash_business.Invoice(instance=result)))
query.destroy()
return invoices
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel