Fix the rounding of security transactions in the QIF Importer (#373584).

The QIF file does not provide the total amount paid for the
  shares. What appears in the "T" line is the price paid for the
  shares *plus* commission ("O" line, if any).

Patch by Charles Day
BP

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16874 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2008-01-20 17:52:55 +00:00
parent 41c195d3f2
commit 4f56d12169

View File

@ -542,8 +542,32 @@
(gnc-far-split (xaccMallocSplit (gnc-get-current-book))))
(if (not num-shares) (set! num-shares (gnc-numeric-zero)))
(if (not share-price) (set! share-price (gnc-numeric-zero)))
(if (not split-amt) (set! split-amt (n* num-shares share-price)))
;; Determine the extended price of all shares without commission.
(if xtn-amt
;; Adjust for commission (if any).
(if commission-amt
(case qif-action
((sell sellx shrsout)
(set! split-amt (n+ xtn-amt commission-amt)))
(else
(set! split-amt (nsub xtn-amt commission-amt))))
(set! split-amt xtn-amt))
;; There's no grand total available.
(if share-price
;; Use the given share price, despite possible rounding.
(set! split-amt (n* num-shares share-price))
(set! split-amt (gnc-numeric-zero))))
;; Determine the share price.
(if (not share-price)
(set! share-price (gnc-numeric-zero))
(if (and xtn-amt (not (gnc-numeric-zero-p num-shares)))
;; There's a share price but it could be imprecise
;; enough to cause rounding. We can compute a better
;; share price ourselves. For more information, see
;; bug 373584.
(set! share-price (n/ split-amt num-shares))))
;; I don't think this should ever happen, but I want
;; to keep this check just in case.