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).
_______________________________________________
gnucash-user mailing list
[email protected]
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-----
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.

Reply via email to