After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 483393 - Reports: Allow mixed denominators in numeric collectors
Reports: Allow mixed denominators in numeric collectors
Status: VERIFIED FIXED
Product: GnuCash
Classification: Other
Component: Reports
unspecified
Other All
: Normal normal
: ---
Assigned To: Charles Day
Andreas Köhler
Depends on:
Blocks: backport
 
 
Reported: 2007-10-04 15:17 UTC by tbic
Modified: 2018-06-29 21:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
create patch from proposed solution (678 bytes, patch)
2008-07-10 07:11 UTC, Rolf Leggewie
committed Details | Review

Description tbic 2007-10-04 15:17:10 UTC
collecting commidities with different denom's causes a failure.


Fix:

;; Same as above but with gnc:numeric
(define (gnc:make-numeric-collector)
  (let ;;; values
      ((value (gnc:numeric-zero)))
    (lambda (action amount)  ;;; Dispatch function
      (case action
        ((add) (if (gnc:gnc-numeric? amount)
                  (set! value (gnc:numeric-add-fixed amount value))
                  (gnc:warn
                   "gnc:numeric-collector called with wrong argument: " amount)))
        ((total) value)
        (else (gnc:warn "bad gnc:numeric-collector action: " action))))))


should be:

;; Same as above but with gnc:numeric
(define (gnc:make-numeric-collector)
  (let ;;; values
      ((value (gnc:numeric-zero)))
    (lambda (action amount)  ;;; Dispatch function
      (case action
        ((add) (if (gnc:gnc-numeric? amount)
                  (set! value (gnc:numeric-add amount value GNC-DENOM-AUTO GNC-DENOM-LCD))
                  (gnc:warn
                   "gnc:numeric-collector called with wrong argument: " amount)))
        ((total) value)
        (else (gnc:warn "bad gnc:numeric-collector action: " action))))))
Comment 1 Christian Stimming 2007-10-27 09:45:45 UTC
You say
 (gnc:numeric-add amount value GNC-DENOM-AUTO GNC-DENOM-LCD))
instead of
 (gnc:numeric-add-fixed amount value))
? Are you sure this doesn't fix any of the current use cases of this?
Comment 2 tbic 2007-10-29 20:14:09 UTC
I am not sure of what you are asking.
Comment 3 Boris Zbarsky 2008-03-02 18:37:25 UTC
For what it's worth, this bit me today.  The asset pie chart report was completely dropping some accounts because they had subaccounts denominated in the same commodity but with different smallest fractions.  As a result, the commodity collector ended up with a gnc_numeric_error(GNC_ERROR_DENOM_DIFF) as the numeric for that commodity, and summing over the collector gave an error return.

The change proposed in comment 0 makes a lot of sense to me based on my (admittedly limited) understanding of gnc-numeric.
Comment 4 Rolf Leggewie 2008-07-10 07:11:50 UTC
Created attachment 114286 [details] [review]
create patch from proposed solution

(In reply to comment #0)
> Fix:

I made this into a patch so it turns up on Bugzilla's open patch search at http://bugzilla.gnome.org/reports/patch-report.cgi?product=GnuCash
Comment 5 Charles Day 2008-07-27 22:03:32 UTC
Nothing wrong with the math, but I wondered about the performance.

I thought that using LCD on each add might be horribly expensive, but because of the gnc_numeric library is written, there's really no significant cost when the denominators are already equal. And when they are different, the performance hit is minimized by some code that identifies the special case where one denominator is a multiple of the other. So this looks OK to me.

But I'll go ahead and run some simple performance tests.

There are a couple of other places where the same modifications might be made.
Comment 6 Charles Day 2008-07-28 20:12:08 UTC
Fix committed as r17433. Requesting backport for 2.2.

I did some cursory performance tests with 15 years of data. The patched version was no slower. In fact, I was surprised to find that it ran marginally faster.
Comment 7 Andreas Köhler 2008-09-15 14:57:16 UTC
Applied to branches/2.2 as r17514 for inclusion in GnuCash 2.2.7.
Thanks.
Comment 8 John Ralls 2018-06-29 21:51:13 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=483393. Please update any external references or bookmarks.