Skip to content

Commit

Permalink
[commodity-utils] remove price-is-not-zero? and work-done
Browse files Browse the repository at this point in the history
because now we're not adding invalid prices to pricelist, and avoids
set! calls

also fix typo in deprecation message
  • Loading branch information
christopherlam committed May 3, 2019
1 parent fbcf488 commit f2aacf9
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions gnucash/report/report-system/commodity-utilities.scm
Expand Up @@ -90,11 +90,6 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(gnc:make-gnc-monetary foreign-commodity foreign-numeric)
domestic date))

;; Returns true if the given pricealist element is a non-zero price.
(define (gnc:price-is-not-zero? elem)
(and (cadr elem)
(not (zero? (cadr elem)))))

;; Create a list of all prices of 'price-commodity' measured in the currency
;; 'report-currency'. The prices are taken from all splits in
;; 'currency-accounts' up until the date 'end-date'. Returns a list of
Expand Down Expand Up @@ -202,22 +197,21 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
(all-splits (get-all-splits currency-accounts end-date))
(interesting-splits (sort (filter interesting-split? all-splits) date<?))
(work-to-do (length commodity-list))
(work-done 0))
(work-to-do (length commodity-list)))
(map
(lambda (c)
(lambda (c work-done)
(define (split-has-commodity? s)
(or (gnc-commodity-equiv c (xaccTransGetCurrency (xaccSplitGetParent s)))
(gnc-commodity-equiv c (xaccAccountGetCommodity (xaccSplitGetAccount s)))))
(set! work-done (1+ work-done))
(if start-percent
(gnc:report-percent-done
(+ start-percent (* delta-percent (/ work-done work-to-do)))))
(cons c
(gnc:get-commodity-totalavg-prices-internal
currency-accounts end-date c report-currency
(filter split-has-commodity? interesting-splits))))
commodity-list)))
commodity-list
(iota work-to-do))))

;; Get the instantaneous prices for the 'price-commodity', measured in
;; amounts of the 'report-currency'. The prices are taken from all
Expand Down Expand Up @@ -284,19 +278,17 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
"gnc:get-commoditylist-inst-prices is deprecated.")
(let ((currency-accounts
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
(work-to-do (length commodity-list))
(work-done 0))
(work-to-do (length commodity-list)))
(map
(lambda (c)
(begin
(set! work-done (+ 1 work-done))
(if start-percent
(gnc:report-percent-done
(+ start-percent (* delta-percent (/ work-done work-to-do)))))
(cons c
(gnc:get-commodity-inst-prices
currency-accounts end-date c report-currency))))
commodity-list)))
(lambda (c work-done)
(if start-percent
(gnc:report-percent-done
(+ start-percent (* delta-percent (/ work-done work-to-do)))))
(cons c
(gnc:get-commodity-inst-prices
currency-accounts end-date c report-currency)))
commodity-list
(iota work-to-do))))


;; Find the price in 'pricelist' that's nearest to 'date'. The
Expand Down

0 comments on commit f2aacf9

Please sign in to comment.