[GNC] How To Get Job Object?

Robert Simmons rsimmons0 at gmail.com
Wed Aug 10 21:31:38 EDT 2022


gnucash.Query() looks like the real winner of the swiss army knife function.

Replacements for direct SQL queries. This one replaces SELECT max(id) FROM
jobs

def get_job_maxid():
    query = gnucash.Query()
    query.search_for('gncJob')
    query.set_book(book)
    job_ids = list()
    for result in query.run():
        job = gnucash.gnucash_business.Job(instance=result)
        job_ids.append(int(job.GetID()))
    if any(job_ids):
        return max(job_ids)

    return 0


Retrieve a customer by name:

def get_customer(name):
    query = gnucash.Query()
    query.search_for('gncCustomer')
    query.set_book(book)
    for result in query.run():
        cust = gnucash.gnucash_business.Customer(instance=result)
        if cust.GetName() == name:
            break
    else:
        cust = None
    query.destroy()
    return cust

I still can't find a way to increment the Job ID without writing directly
to the DB however. But I've reduced DB interaction to that last one (it's a
mystery).


More information about the gnucash-user mailing list