scheme to retrieve the customer associated with a transaction

Geert Janssens geert.gnucash at kobaltwit.be
Mon Mar 7 04:24:08 EST 2016


On Sunday 06 March 2016 01:36:28 Macho Philipovich wrote:
>      I'm not particularly interested in whether specific entries in a
>      Bill were marked as "Billable"—but only in determining which
> job and customer were set as the default chargebacks for the overall
> Bill. Glancing at the Gnucash source code, it looks to me as though
> something as simple as (gncInvoiceGetBillTo invoice) should do what I
> need, and return a GncOwner object representing either the job or
> customer, when these are set, or () when neither are. But I'm getting
> back () even for bills for which I believe a chargeback job has been
> set.
> 
>    Ok, I finally figured it all out!
>    It turns out that on Wednesday when I asked for "a couple of lines
> of code" to find the customer name and job objects associated with a
> particular split (chargebacks when it's a bill), what I in fact
> needed was something like this:
>    (define find-lot
>      (lambda (lots)
>        (if (null? lots)
>          '()
>          (if (null? (car lots)) (find-lot (cdr lots)) (car lots)))))
>    …
>      (let* (parent (xaccSplitGetParent split))
>        (split-list (xaccTransGetSplitList parent))
>        (lots       (map (lambda (x) (xaccSplitGetLot x)) split-list))
>        (invoice    (gncInvoiceGetInvoiceFromLot (find-lot lots)))
>        (billTo     (gncInvoiceGetBillTo invoice))
>        (isBill?    (string=? (gncInvoiceGetTypeString invoice)
> "Bill")) (owner      (if isBill? billTo (gncInvoiceGetOwner
> invoice))) (job        (gncOwnerGetJob owner))
>        (ownername  (gncOwnerGetName (gncJobGetOwner job)))
>        (jobname    (gncJobGetName job))
>    …
>    Now that I've got this done I can painlessly create multiple
> accounting reports that I'm required by law to produce every month.
> Thanks so much to the wonderful Gnucash developers!
>    —m

I'm glad you found it. Congratulations!

Geert


More information about the gnucash-user mailing list