From eab53d44b3bc8cf1828c45a3134d85c0180b0e76 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 8 Apr 2019 22:56:25 +0800 Subject: [PATCH] [report] rewrite gnc:report-template-has-unique-name? --- gnucash/report/report-system/report.scm | 16 ++++++---------- .../report-system/test/test-report-system.scm | 13 +++++++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/gnucash/report/report-system/report.scm b/gnucash/report/report-system/report.scm index 30874460c8..5d6f1e8745 100644 --- a/gnucash/report/report-system/report.scm +++ b/gnucash/report/report-system/report.scm @@ -489,16 +489,12 @@ not found."))) ;; to test if the new name is unique among the existting custom reports. ;; If not the calling function can prevent the name from being updated. (define (gnc:report-template-has-unique-name? templ-guid new-name) - (let* ((unique? #t)) - (if new-name - (hash-for-each - (lambda (id rec) - (if (and (not (equal? templ-guid id)) - (gnc:report-template-is-custom/template-guid? id) - (equal? new-name (gnc:report-template-name rec))) - (set! unique? #f))) - *gnc:_report-templates_*)) - unique?)) + (or (not new-name) + (not (any + (lambda (tmpl) + (and (not (equal? (car tmpl) templ-guid)) + (equal? (gnc:report-template-name (cdr tmpl)) new-name))) + (gnc:custom-report-templates-list))))) ;; Generate a unique custom template name using the given string as a base ;; If this string already exists as a custom template name, a diff --git a/gnucash/report/report-system/test/test-report-system.scm b/gnucash/report/report-system/test/test-report-system.scm index 22ba89b4c9..a683e375f3 100644 --- a/gnucash/report/report-system/test/test-report-system.scm +++ b/gnucash/report/report-system/test/test-report-system.scm @@ -196,6 +196,19 @@ (test-equal "(gnc:is-custom-report-type report) #f" #f (gnc:is-custom-report-type report)) + (test-assert "gnc:report-template-has-unique-name? #t" + (gnc:report-template-has-unique-name? + "54c2fc051af64a08ba2334c2e9179e24" + "Test Report Templatx")) + (test-assert "gnc:report-template-has-unique-name? #f" + (not + (gnc:report-template-has-unique-name? + "54c2fc051af64a08ba2334c2e9179e24" + "Test Report Template"))) + (test-assert "gnc:report-template-has-unique-name? #t" + (gnc:report-template-has-unique-name? + "54c2fc051af64a08ba2334c2e9179e24" + #f)) (test-assert "gnc:report-serialize = string" (string? (gnc:report-serialize report)))))