Skip to content

Commit

Permalink
report: load reports fom root accounts instead of external file
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Mar 25, 2019
1 parent d27b165 commit 83d9c54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions gnucash/gnome-utils/gnc-file.c
Expand Up @@ -25,6 +25,8 @@
#include <glib/gi18n.h>
#include <errno.h>
#include <string.h>
#include <libguile.h>
#include "guile-mappings.h"

#include "dialog-utils.h"
#include "assistant-xml-encoding.h"
Expand Down Expand Up @@ -1028,6 +1030,10 @@ gnc_post_file_open (GtkWindow *parent, const char * filename, gboolean is_readon
g_free ( message );
}

PWARN("post-load-file - load reports");
scm_call_0(scm_c_eval_string("gnc:load-all-reports"));
PWARN("post-load-file - load reports success");

// Fix account color slots being set to 'Not Set', should run once on a book
qof_event_suspend();
xaccAccountScrubColorNotSet (gnc_get_current_book());
Expand Down
4 changes: 2 additions & 2 deletions gnucash/gnucash-bin.c
Expand Up @@ -417,8 +417,8 @@ load_user_config(void)
g_free(config_filename);
}

update_message("loading saved reports");
try_load_config_array(saved_report_files);
/* update_message("loading saved reports"); */
/* try_load_config_array(saved_report_files); */
update_message("loading stylesheets");
try_load_config_array(stylesheet_files);
}
Expand Down
27 changes: 27 additions & 0 deletions gnucash/report/report-system/report.scm
Expand Up @@ -23,6 +23,9 @@
(use-modules (gnucash utilities))
(use-modules (gnucash app-utils))
(use-modules (gnucash gettext))
(use-modules (json parser))
(use-modules (json builder))

(eval-when (compile load eval expand)
(load-extension "libgncmod-report-system" "scm_init_sw_report_system_module"))
(use-modules (sw_report_system))
Expand Down Expand Up @@ -739,13 +742,37 @@ not found.")))
(define (gnc:save-all-reports)
(gnc-saved-reports-backup)
(gnc-saved-reports-write-to-file "" #t)
(let ((root (gnc-get-current-root-account))
(saved-reports (string-join
(map
(lambda (p)
(gnc:report-template-serialize (cdr p)))
(gnc:custom-report-templates-list))
"\n")))
(xaccAccountBeginEdit root)
(xaccAccountSetNotes root saved-reports)
(xaccAccountCommitEdit root)
;; need to make book dirty... don't know how...
(format #t "saving-reports: length ~a\n" (string-length saved-reports)))
(every identity
(map
(lambda (p)
(gnc:debug "saving report " (car p))
(gnc:report-template-save-to-savefile (cdr p)))
(gnc:custom-report-templates-list))))

(export gnc:load-all-reports)
(define (gnc:load-all-reports)
(display "(gnc:load-all-reports)\n")
(let ((saved-reports (xaccAccountGetNotes (gnc-get-current-root-account))))
(format #t "load-reports: length ~a\n" (string-length saved-reports))
(unless (string-null? saved-reports)
;; remove all custom reports
(for-each
(lambda (guid)
(hash-remove! *gnc:_report-templates_* guid))
(gnc:custom-report-template-guids))
(eval-string saved-reports))))

;; gets the renderer from the report template;
;; gets the stylesheet from the report;
Expand Down

0 comments on commit 83d9c54

Please sign in to comment.