Custom Report > simply divide by 2
John Ralls
jralls at ceridwen.us
Sun Jan 10 11:28:56 EST 2016
> On Jan 10, 2016, at 7:53 AM, Drunal42 <andreas_pinter at inode.at> wrote:
>
> This is probably the dumbest question ever, but I'm not able to divde a given
> value by two.
>
> I took the cash-flow report and added another option there, which should
> basically do the following:
> If the flag is set, divide the "incoming" by two.
>
> I managed to add the option
> I managed to read the option
> I managed to create my own commodity-collector
> And I managed that it will be used instead of the money-in-collector from
> the standard report if the flag is set.
>
> But for the sake of god I'm not able to fill my own commodity-collector with
> half of what the money-in-collector contains.
> I tried
> (mycollector 'add report-currency (/ s-report-value 2))
> or
> (mycollector 'add report-currency (gnc-numeric-div s-report-value 2))
> or
> (mycollector 'add report-currency (gnc-number-div s-report-value
> (gnc-numberic-create 2 100)))
>
> where it originally said
> (money-in-collector 'add report-currency s-report value)
>
> all of the above give me an error in gnucash.
> It is really just a simple modification I need and I do not plan to create
> any additional / more complex reports. Therefore I have not setup any
> meaningful development environment yet. I assume it is simply a typing issue
> with the s-report-value being one type and 2 something else (I thought it
> should be a gnc-numeric as far as I understood it)
>
> Alternatively I tried to get the gnc-numeric value from the
> money-in-collector and then divide it by 2 before adding it to my own
> collector:
> (set! temp (gnc:sum-collector-commodity money-in-collector report-currency
> exchange-fn))
> (set! temp(gnc:gnc-monetary-amount temp))
> ;; divide by two here, somehow.
> (mycollector 'add report-currency temp)
>
> Any help is appreciated.
The last try was closest aside from the spelling errors, but you want (gnc-numeric-create 2 1). You also need to pass a precision and rounding parameter to gnc-numeric-div, so you probably want something like
(gnc-numeric-div s-report-value (gnc-numeric-create 2 1) GNC-DENOM-AUTO GNC-HOW-RND-NEVER)
Regards,
John Ralls
More information about the gnucash-user
mailing list