r20057 - gnucash/trunk/src - Bug #638543: Add a GUI for the counter format and current value.

Christian Stimming cstim at code.gnucash.org
Mon Jan 10 16:39:40 EST 2011


Author: cstim
Date: 2011-01-10 16:39:40 -0500 (Mon, 10 Jan 2011)
New Revision: 20057
Trac: http://svn.gnucash.org/trac/changeset/20057

Modified:
   gnucash/trunk/src/app-utils/app-utils.scm
   gnucash/trunk/src/app-utils/options.scm
   gnucash/trunk/src/business/business-utils/business-options.scm
   gnucash/trunk/src/business/business-utils/business-prefs.scm
Log:
Bug #638543: Add a GUI for the counter format and current value.

Patch by Matthijs Kooijman:

This allows the user to change the format used for the various counters,
as well as see and change the current value of the counter.

This is a bit of hack right now, since the format and current counter
values are stored in the counter_formats and counters kvp slots
respectively, instead of options/<section> like the other options in the
File->properties window.

This is implemented by adding the make-counter-option and
make-counter-format-option, which both replace the scm->kvp and kvp->scm
functions defined by make-number-range-option and make-string-option
respectively. The replaced function simply ignores the "path" parameter
and instead saves to the "counter" or "counter_formats" slot hardcoded.

Modified: gnucash/trunk/src/app-utils/app-utils.scm
===================================================================
--- gnucash/trunk/src/app-utils/app-utils.scm	2011-01-10 21:39:29 UTC (rev 20056)
+++ gnucash/trunk/src/app-utils/app-utils.scm	2011-01-10 21:39:40 UTC (rev 20057)
@@ -43,7 +43,9 @@
 (export gnc:option-default-getter)
 (export gnc:option-generate-restore-form)
 (export gnc:option-scm->kvp)
+(export gnc:set-option-scm->kvp)
 (export gnc:option-kvp->scm)
+(export gnc:set-option-kvp->scm)
 (export gnc:option-value-validator)
 (export gnc:option-data)
 (export gnc:option-data-fns)

Modified: gnucash/trunk/src/app-utils/options.scm
===================================================================
--- gnucash/trunk/src/app-utils/options.scm	2011-01-10 21:39:29 UTC (rev 20056)
+++ gnucash/trunk/src/app-utils/options.scm	2011-01-10 21:39:40 UTC (rev 20057)
@@ -118,8 +118,12 @@
   (vector-ref option 8))
 (define (gnc:option-scm->kvp option)
   (vector-ref option 9))
+(define (gnc:set-option-scm->kvp option v)
+  (vector-set! option 9 v))
 (define (gnc:option-kvp->scm option)
   (vector-ref option 10))
+(define (gnc:set-option-kvp->scm option v)
+  (vector-set! option 10 v))
 (define (gnc:option-value-validator option)  
   (vector-ref option 11))
 (define (gnc:option-data option)

Modified: gnucash/trunk/src/business/business-utils/business-options.scm
===================================================================
--- gnucash/trunk/src/business/business-utils/business-options.scm	2011-01-10 21:39:29 UTC (rev 20056)
+++ gnucash/trunk/src/business/business-utils/business-options.scm	2011-01-10 21:39:40 UTC (rev 20057)
@@ -432,9 +432,53 @@
      validator
      #f #f #f #f)))
 
+;; This defines an option to set a counter value. This is a slightly
+;; different kind of option: Unlike all other options, the values edited
+;; by this option are not saved in the "options"/<section> kvm slot, but
+;; in the "counters" slot. This is mostly due to backwards compatibility
+;; and partly because counters are a bit different from other options
+;; anyway.
+;;
+;; This is implemented by overriding the scm->kvp and kvp->scm methods
+;; to ignore the kvp path passed and replace it with a hardcoded
+;; "counters".
+(define (gnc:make-counter-option
+         section
+         name
+	 key
+         sort-tag
+         documentation-string
+         default-value)
+  (let ((option (gnc:make-number-range-option section name sort-tag documentation-string default-value 0 999999999 0 1)))
+     (gnc:set-option-scm->kvp option (lambda (f p) (kvp-frame-set-slot-path-gslist f (inexact->exact ((gnc:option-getter option))) (list "counters" key))))
+     (gnc:set-option-kvp->scm option (lambda (f p)
+                               (let ((v (kvp-frame-get-slot-path-gslist f (list "counters" key))))
+                                 (if (and v (integer? v))
+                                     ((gnc:option-setter option) v)))))
+     option))
+
+;; This defines an option to set a counter format, which has the same
+;; exception as gnc:make-counter-option above.
+(define (gnc:make-counter-format-option
+         section
+         name
+	 key
+         sort-tag
+         documentation-string
+         default-value)
+  (let ((option (gnc:make-string-option section name sort-tag documentation-string default-value)))
+     (gnc:set-option-scm->kvp option (lambda (f p) (kvp-frame-set-slot-path-gslist f ((gnc:option-getter option)) (list "counter_formats" key))))
+     (gnc:set-option-kvp->scm option (lambda (f p)
+                               (let ((v (kvp-frame-get-slot-path-gslist f (list "counter_formats" key))))
+                                 (if (and v (string? v))
+                                     ((gnc:option-setter option) v)))))
+     option))
+
 (export gnc:make-invoice-option)
 (export gnc:make-customer-option)
 (export gnc:make-vendor-option)
 (export gnc:make-employee-option)
 (export gnc:make-owner-option)
 (export gnc:make-taxtable-option)
+(export gnc:make-counter-option)
+(export gnc:make-counter-format-option)

Modified: gnucash/trunk/src/business/business-utils/business-prefs.scm
===================================================================
--- gnucash/trunk/src/business/business-utils/business-prefs.scm	2011-01-10 21:39:29 UTC (rev 20056)
+++ gnucash/trunk/src/business/business-utils/business-prefs.scm	2011-01-10 21:39:40 UTC (rev 20057)
@@ -19,6 +19,47 @@
 ;; 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
 ;; Boston, MA  02110-1301,  USA       gnu at gnu.org
 
+(define gnc:*option-section-counters* (N_ "Counters"))
+
+;; This defines all available counter types to show options for. This a
+;; list that contains a sublist for each counter type, containing: The
+;; (untranslated) counter name, the format label, the previous number
+;; label, the format help text and the previous number help text.
+(define counter-types
+  (list (list "gncCustomer"     (N_ "Customer number format")
+                                (N_ "Customer number")
+                                (N_ "The format string to use for generating customer numbers. This is a printf-style format string.")
+                                (N_ "The previous customer number generated. This number will be incremented to generate the next customer number."))
+        (list "gncEmployee"     (N_ "Employee number format")
+                                (N_ "Employee number")
+                                (N_ "The format string to use for generating employee numbers. This is a printf-style format string.")
+                                (N_ "The previous employee number generated. This number will be incremented to generate the next employee number."))
+        (list "gncInvoice"      (N_ "Invoice number format")
+                                (N_ "Invoice number")
+                                (N_ "The format string to use for generating invoice numbers. This is a printf-style format string.")
+                                (N_ "The previous invoice number generated. This number will be incremented to generate the next invoice number."))
+        (list "gncBill"         (N_ "Bill number format")
+                                (N_ "Bill number")
+                                (N_ "The format string to use for generating bill numbers. This is a printf-style format string.")
+                                (N_ "The previous bill number generated. This number will be incremented to generate the next bill number."))
+        (list "gncExpVoucher"   (N_ "Expense voucher number format")
+                                (N_ "Expense voucher number")
+                                (N_ "The format string to use for generating expense voucher numbers. This is a printf-style format string.")
+                                (N_ "The previous expense voucher number generated. This number will be incremented to generate the next voucher number."))
+        (list "gncJob"          (N_ "Job number format")
+                                (N_ "Job number")
+                                (N_ "The format string to use for generating job numbers. This is a printf-style format string.")
+                                (N_ "The previous job number generated. This number will be incremented to generate the next job number."))
+        (list "gncOrder"        (N_ "Order number format")
+                                (N_ "Order number")
+                                (N_ "The format string to use for generating order numbers. This is a printf-style format string.")
+                                (N_ "The previous order number generated. This number will be incremented to generate the next order number."))
+        (list "gncVendor"       (N_ "Vendor number format")
+                                (N_ "Vendor number")
+                                (N_ "The format string to use for generating vendor numbers. This is a printf-style format string.")
+                                (N_ "The previous vendor number generated. This number will be incremented to generate the next vendor number."))
+))
+
 (define (book-options-generator options)
   (define (reg-option new-option)
     (gnc:register-option options new-option))
@@ -81,7 +122,9 @@
     gnc:*business-label* (N_ "Fancy Date Format")
     "g" (N_ "The default date format used for fancy printed dates")
     #f))
-    
+
+  ;; Accounts tab
+
   (reg-option 
    (gnc:make-simple-boolean-option
     gnc:*option-section-accounts* gnc:*option-name-trading-accounts*
@@ -95,6 +138,35 @@
     gnc:*option-section-budgeting* gnc:*option-name-default-budget*
     "a" (N_ "Budget to be used when none has been otherwise specified")))
 
+  ;; Counters Tab
+  (map (lambda (vals)
+               (let* (
+		      ; Unpack the list of strings for this counter type
+                      (key (car vals))
+                      (sort-string key)
+                      (format-label (cadr vals))
+                      (number-label (caddr vals))
+                      (format-description (cadddr vals))
+                      (number-description (cadddr (cdr vals)))
+                     )
+                     (begin
+		      ; For each counter-type we create an option for
+		      ; the last used number and the format string to
+		      ; use.
+                      (reg-option
+                       (gnc:make-counter-option
+                        gnc:*option-section-counters* number-label key
+                        (string-append sort-string "a") number-description 0))
+                      (reg-option
+                       (gnc:make-counter-format-option
+                        gnc:*option-section-counters* format-label key
+                        (string-append sort-string "b") format-description ""))
+                      )
+               )
+       )
+       ;; Make counter and format option for each defined counter
+       counter-types
+  )
 )
 
 



More information about the gnucash-changes mailing list