gnucash unstable: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Mar 30 17:21:00 EDT 2018
Updated via https://github.com/Gnucash/gnucash/commit/4601cfcb (commit)
via https://github.com/Gnucash/gnucash/commit/5922cbbc (commit)
via https://github.com/Gnucash/gnucash/commit/7cfb48fe (commit)
via https://github.com/Gnucash/gnucash/commit/84ab44bf (commit)
from https://github.com/Gnucash/gnucash/commit/c141edd9 (commit)
commit 4601cfcbc3123378b2b90efdd5fdc5c26ce9f5ae
Merge: c141edd 5922cbb
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Mar 30 14:16:30 2018 -0700
Merge Chris Lam's Bug 792800 Pull Request into unstable.
commit 5922cbbc4b4c83412df20d2a673d2e9460bdb7e9
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Mar 29 20:16:01 2018 +0800
invoice, easy-invoice.scm: %discount from html-table to string
Old code would nest a small single-row, 2-column html-table within the
entry-list html-table to display discount percentage and '%'. This is
an overkill and causes alignment issues. Display a string instead.
diff --git a/gnucash/report/business-reports/easy-invoice.scm b/gnucash/report/business-reports/easy-invoice.scm
index 8ebf791..439e592 100644
--- a/gnucash/report/business-reports/easy-invoice.scm
+++ b/gnucash/report/business-reports/easy-invoice.scm
@@ -139,19 +139,7 @@
(define (monetary-or-percent numeric currency entry-type)
(if (gnc:entry-type-percent-p entry-type)
- (let ((table (gnc:make-html-table)))
- (gnc:html-table-set-style!
- table "table"
- 'attribute (list "border" 0)
- 'attribute (list "cellspacing" 1)
- 'attribute (list "cellpadding" 0))
- (gnc:html-table-append-row!
- table
- (list numeric (_ "%")))
- (set-last-row-style!
- table "td"
- 'attribute (list "valign" "top"))
- table)
+ (string-append (gnc:default-html-gnc-numeric-renderer numeric #f) " " (_ "%"))
(gnc:make-gnc-monetary currency numeric)))
(define (add-entry-row table currency entry column-vector row-style cust-doc? credit-note?)
diff --git a/gnucash/report/business-reports/invoice.scm b/gnucash/report/business-reports/invoice.scm
index 8b5c503..7129849 100644
--- a/gnucash/report/business-reports/invoice.scm
+++ b/gnucash/report/business-reports/invoice.scm
@@ -134,19 +134,7 @@
(define (monetary-or-percent numeric currency entry-type)
(if (gnc:entry-type-percent-p entry-type)
- (let ((table (gnc:make-html-table)))
- (gnc:html-table-set-style!
- table "table"
- 'attribute (list "border" 0)
- 'attribute (list "cellspacing" 1)
- 'attribute (list "cellpadding" 0))
- (gnc:html-table-append-row!
- table
- (list numeric (_ "%")))
- (set-last-row-style!
- table "td"
- 'attribute (list "valign" "top"))
- table)
+ (string-append (gnc:default-html-gnc-numeric-renderer numeric #f) " " (_ "%"))
(gnc:make-gnc-monetary currency numeric)))
(define (add-entry-row table currency entry column-vector row-style cust-doc? credit-note?)
commit 7cfb48fea37231005b3c311eb1f4f9ced7417bda
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Tue Mar 27 22:01:50 2018 +0800
TR: Price Column shown in commodity SCU
xaccSplitGetSharePrice will typically return a gnc-numeric (or scm
rational) value. This leads to the TR showing a price of, eg. $22 +
12228521/25349850 which is not ideal. This commit will modify the
share price to round the exact rational to an inexact decimal
according to the account share price currency SCU. If the SCU is less
than 10000, increase the precision by 2 significant digits.
diff --git a/gnucash/report/standard-reports/transaction.scm b/gnucash/report/standard-reports/transaction.scm
index c216b28..1feee34 100644
--- a/gnucash/report/standard-reports/transaction.scm
+++ b/gnucash/report/standard-reports/transaction.scm
@@ -1072,11 +1072,20 @@ tags within description, notes or memo. ")
(add-if (column-uses? 'price)
(vector (_ "Price")
(lambda (split transaction-row?)
- (define trans (xaccSplitGetParent split))
- (gnc:make-html-table-cell/markup
- "number-cell"
- (gnc:make-gnc-monetary (xaccTransGetCurrency trans)
- (xaccSplitGetSharePrice split)))))))))
+ ;; share price is retrieved as an exact rational; convert for
+ ;; presentation to decimal, rounded to the currency SCU, optionally
+ ;; increasing precision by 2 significant digits.
+ (let* ((currency (xaccTransGetCurrency (xaccSplitGetParent split)))
+ (scu (gnc-commodity-get-fraction currency))
+ (price (xaccSplitGetSharePrice split))
+ (price-decimal (gnc-numeric-convert price
+ (if (< scu 10000)
+ (* scu 100)
+ scu)
+ GNC-HOW-RND-ROUND)))
+ (gnc:make-html-table-cell/markup
+ "number-cell"
+ (gnc:make-gnc-monetary currency price-decimal)))))))))
(if (and (null? left-cols-list)
(or (opt-val gnc:pagename-display "Totals")
commit 84ab44bfb6968670f68d68a52356c48dfd1404a0
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Mar 26 22:40:30 2018 +0800
Bug 792800 - Advanced Portfolio Report tries to divide by zero balance and aborts.
This fixes a numerical-overflow error identified in bug 792800. It is
related to negative-stock-balance situation.
diff --git a/gnucash/report/standard-reports/advanced-portfolio.scm b/gnucash/report/standard-reports/advanced-portfolio.scm
index b696674..0f382ee 100644
--- a/gnucash/report/standard-reports/advanced-portfolio.scm
+++ b/gnucash/report/standard-reports/advanced-portfolio.scm
@@ -47,6 +47,12 @@
(define optname-prefer-pricelist (N_ "Set preference for price list data"))
(define optname-brokerage-fees (N_ "How to report brokerage fees"))
+(define OVERFLOW-ERROR "<h3>Error</h3>There is an error processing the
+transaction '~a'. This may to be caused by a sell transaction causing
+a negative stock balance, and a subsequent buy transaction causing a
+zero balance. This leads to a division-by-zero error. It can be fixed
+by preventing negative stock balances.<br/>")
+
;; To avoid overflows in our calculations, define a denominator for prices and unit values
(define price-denom 100000000)
(define units-denom 100000000)
@@ -258,15 +264,18 @@
(cdar b-list)
GNC-DENOM-AUTO GNC-DENOM-REDUCE)
GNC-DENOM-AUTO GNC-DENOM-REDUCE)
- (gnc-numeric-add b-units
- (caar b-list) GNC-DENOM-AUTO GNC-DENOM-REDUCE)
+ (let ((denom (gnc-numeric-add b-units
+ (caar b-list) GNC-DENOM-AUTO GNC-DENOM-REDUCE)))
+ (if (zero? denom)
+ (throw 'div/0 (format #f "buying ~0,4f share units" b-units))
+ denom))
price-denom GNC-RND-ROUND)))
(append b-list
- (list (cons b-units (gnc-numeric-div
- b-value b-units price-denom GNC-RND-ROUND))))))
+ (list (cons b-units (gnc-numeric-div
+ b-value b-units price-denom GNC-RND-ROUND))))))
(else (append b-list
- (list (cons b-units (gnc-numeric-div
- b-value b-units price-denom GNC-RND-ROUND)))))))
+ (list (cons b-units (gnc-numeric-div
+ b-value b-units price-denom GNC-RND-ROUND)))))))
;; we have value and negative units, remove units from basis
((and (not (gnc-numeric-zero-p b-value))
@@ -336,8 +345,10 @@
((and (gnc-numeric-zero-p b-units)
(not (gnc-numeric-zero-p b-value)))
(let* ((current-value (sum-basis b-list GNC-DENOM-AUTO))
- (value-ratio (gnc-numeric-div (gnc-numeric-add b-value current-value GNC-DENOM-AUTO GNC-DENOM-REDUCE)
- current-value GNC-DENOM-AUTO GNC-DENOM-REDUCE)))
+ (value-ratio (if (zero? current-value)
+ (throw 'div/0 (format #f "spinoff of ~0,2f currency units" current-value))
+ (gnc-numeric-div (gnc-numeric-add b-value current-value GNC-DENOM-AUTO GNC-DENOM-REDUCE)
+ current-value GNC-DENOM-AUTO GNC-DENOM-REDUCE))))
(gnc:debug "this is a spinoff")
(gnc:debug "blist is " b-list " value ratio is " (gnc-numeric-to-string value-ratio))
@@ -1091,12 +1102,17 @@
table
headercols)
- (table-add-stock-rows
- table accounts to-date currency price-fn exchange-fn price-source
- include-empty show-symbol show-listing show-shares show-price basis-method
- prefer-pricelist handle-brokerage-fees
- total-basis total-value total-moneyin total-moneyout
- total-income total-gain total-ugain total-brokerage)
+ (catch 'div/0
+ (lambda ()
+ (table-add-stock-rows
+ table accounts to-date currency price-fn exchange-fn price-source
+ include-empty show-symbol show-listing show-shares show-price basis-method
+ prefer-pricelist handle-brokerage-fees
+ total-basis total-value total-moneyin total-moneyout
+ total-income total-gain total-ugain total-brokerage))
+ (lambda (k reason)
+ (gnc:html-document-add-object!
+ document (format #f OVERFLOW-ERROR reason))))
(set! sum-total-moneyin (gnc:sum-collector-commodity total-moneyin currency exchange-fn))
Summary of changes:
gnucash/report/business-reports/easy-invoice.scm | 14 +------
gnucash/report/business-reports/invoice.scm | 14 +------
.../report/standard-reports/advanced-portfolio.scm | 44 +++++++++++++++-------
gnucash/report/standard-reports/transaction.scm | 19 +++++++---
4 files changed, 46 insertions(+), 45 deletions(-)
More information about the gnucash-changes
mailing list