Bug #622778 Miscalculation in cashflow reports - Step 03

Introduce solution and some minor modifications to save some function calls.

Solution:

- Save the current split value
- Calculate the parent total transaction value
- Calculate the ratio of the split to the transaction value
- only consider splits of opposite sign for the flow colletion
- only consider the split value multiplied with the calculated
  ratio of those splits with opposite sign

Author:    Carsten Rinke <carsten.rinke@gmx.de>

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22971 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2013-05-10 19:06:37 +00:00
parent 8a95c0f0b7
commit 77ff603655

View File

@ -205,10 +205,29 @@
) )
(let* ( (let* (
(parent-currency (xaccTransGetCurrency parent)) (parent-currency (xaccTransGetCurrency parent))
(transaction-value (gnc-numeric-zero))
(split-value (xaccSplitGetValue split))
) )
;(gnc:debug (xaccTransGetDescription parent) ;(gnc:debug (xaccTransGetDescription parent)
; " - " ; " - "
; (gnc-commodity-get-printname parent-currency)) ; (gnc-commodity-get-printname parent-currency))
;; -------------------------------------------------------------
;; get the transaction value - needed to fix bug 622778
;; -------------------------------------------------------------
(for-each
(lambda (parent-split)
(let* (
(psv (xaccSplitGetValue parent-split))
)
(if (gnc-numeric-positive-p psv) ;; meaning: if (psv>0)
(set! transaction-value
(gnc-numeric-add transaction-value psv GNC-DENOM-AUTO GNC-DENOM-LCD)
)
)
)
)
(xaccTransGetSplitList parent)
)
;; ----------------------------------------- ;; -----------------------------------------
;; process all splits of current transaction ;; process all splits of current transaction
;; ----------------------------------------- ;; -----------------------------------------
@ -216,7 +235,6 @@
(lambda (s) (lambda (s)
(let* ( (let* (
(s-account (xaccSplitGetAccount s)) (s-account (xaccSplitGetAccount s))
(s-amount (xaccSplitGetAmount s))
(s-value (xaccSplitGetValue s)) (s-value (xaccSplitGetValue s))
(s-commodity (xaccAccountGetCommodity s-account)) (s-commodity (xaccAccountGetCommodity s-account))
) )
@ -235,9 +253,30 @@
(if (and ;; make sure we don't have (if (and ;; make sure we don't have
(not (null? s-account)) ;; any dangling splits (not (null? s-account)) ;; any dangling splits
(not (account-in-list? s-account accounts)) (not (account-in-list? s-account accounts))
;; only consider splits of opposite sign
(gnc-numeric-negative-p (gnc-numeric-mul s-value split-value 0 GNC-DENOM-REDUCE))
) )
(if (not (split-in-list? s seen-split-list)) (if (not (split-in-list? s seen-split-list))
(begin (let (
(split-transaction-ratio (gnc-numeric-zero))
)
;; -------------------------------------------------------------
;; get the share of the current split from the total transaction- needed to fix bug 622778
;; -------------------------------------------------------------
(set! split-transaction-ratio
(if (gnc-numeric-zero-p transaction-value)
;; If the transaction-value remained zero, then the transaction is
;; either 0 or we have a negative one-split-transaction.
;; Either way, it means that we can set the transaction value equal to the split-value,
;; and, in turn, the transaction ratio is 1.
(gnc:make-gnc-numeric 1 1)
;; else
(gnc-numeric-abs
(gnc-numeric-div split-value transaction-value 0 GNC-DENOM-REDUCE)
)
)
)
(set! s-value (gnc-numeric-mul split-transaction-ratio s-value GNC-DENOM-AUTO GNC-RND-ROUND))
(set! seen-split-list (cons s seen-split-list)) (set! seen-split-list (cons s seen-split-list))
(if (gnc-numeric-negative-p s-value) (if (gnc-numeric-negative-p s-value)
;; ----------------------------------------------- ;; -----------------------------------------------
@ -247,7 +286,7 @@
(pair (account-in-alist s-account money-in-alist)) (pair (account-in-alist s-account money-in-alist))
) )
;(gnc:debug "in:" (gnc-commodity-get-printname s-commodity) ;(gnc:debug "in:" (gnc-commodity-get-printname s-commodity)
; (gnc-numeric-to-double s-amount) ; (gnc-numeric-to-double (xaccSplitGetAmount s))
; (gnc-commodity-get-printname parent-currency) ; (gnc-commodity-get-printname parent-currency)
; (gnc-numeric-to-double s-value)) ; (gnc-numeric-to-double s-value))
(if (not pair) (if (not pair)
@ -264,7 +303,7 @@
(to-report-currency (to-report-currency
parent-currency parent-currency
(gnc-numeric-neg s-value) (gnc-numeric-neg s-value)
(gnc-transaction-get-date-posted parent) parent-date-posted
) )
) )
) )
@ -280,7 +319,7 @@
(pair (account-in-alist s-account money-out-alist)) (pair (account-in-alist s-account money-out-alist))
) )
;(gnc:debug "out:" (gnc-commodity-get-printname s-commodity) ;(gnc:debug "out:" (gnc-commodity-get-printname s-commodity)
; (gnc-numeric-to-double s-amount) ; (gnc-numeric-to-double (xaccSplitGetAmount s))
; (gnc-commodity-get-printname parent-currency) ; (gnc-commodity-get-printname parent-currency)
; (gnc-numeric-to-double s-value)) ; (gnc-numeric-to-double s-value))
(if (not pair) (if (not pair)
@ -297,7 +336,7 @@
(to-report-currency (to-report-currency
parent-currency parent-currency
s-value s-value
(gnc-transaction-get-date-posted parent) parent-date-posted
) )
) )
) )