gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sun Nov 3 08:43:45 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/535632b0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/32a34035 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/be4e4524 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/977b1fcf (commit)
	from  https://github.com/Gnucash/gnucash/commit/0abc09cc (commit)



commit 535632b02515d0bbca3ba01ef2f2bfb7f0edf442
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 3 18:41:54 2019 +0800

    Bug 787295 - Allow UI jump from Business accounts to their relevant invoice/bill/voucher
    
    This enables UI jump via Transaction or Right-click menu to open the
    invoice for editing.

diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 42aead836..308c40916 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -54,6 +54,7 @@
 #include "dialog-find-account.h"
 #include "dialog-find-transactions.h"
 #include "dialog-print-check.h"
+#include "dialog-invoice.h"
 #include "dialog-transfer.h"
 #include "dialog-utils.h"
 #include "assistant-stock-split.h"
@@ -184,6 +185,7 @@ static void gnc_plugin_page_register_cmd_transaction_report (GtkAction *action,
 static void gnc_plugin_page_register_cmd_associate_file_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
 static void gnc_plugin_page_register_cmd_associate_location_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
 static void gnc_plugin_page_register_cmd_execassociated_transaction (GtkAction *action, GncPluginPageRegister *plugin_page);
+static void gnc_plugin_page_register_cmd_jump_associated_invoice (GtkAction *action, GncPluginPageRegister *plugin_page);
 
 static void gnc_plugin_page_help_changed_cb( GNCSplitReg *gsr, GncPluginPageRegister *register_page );
 static void gnc_plugin_page_popup_menu_cb( GNCSplitReg *gsr, GncPluginPageRegister *register_page );
@@ -197,6 +199,8 @@ static void gnc_plugin_page_register_event_handler (QofInstance *entity,
         GncPluginPageRegister *page,
         GncEventData *ed);
 
+static GncInvoice * invoice_from_trans (Transaction *trans);
+
 /************************************************************/
 /*                          Actions                         */
 /************************************************************/
@@ -209,6 +213,7 @@ static void gnc_plugin_page_register_event_handler (QofInstance *entity,
 #define ASSOCIATE_TRANSACTION_FILE_LABEL      N_("_Associate File with Transaction")
 #define ASSOCIATE_TRANSACTION_LOCATION_LABEL  N_("_Associate Location with Transaction")
 #define EXECASSOCIATED_TRANSACTION_LABEL N_("_Open Associated File/Location")
+#define JUMP_ASSOCIATED_INVOICE_LABEL     N_("Open Associated Invoice")
 #define CUT_SPLIT_LABEL                  N_("Cu_t Split")
 #define COPY_SPLIT_LABEL                 N_("_Copy Split")
 #define PASTE_SPLIT_LABEL                N_("_Paste Split")
@@ -222,6 +227,7 @@ static void gnc_plugin_page_register_event_handler (QofInstance *entity,
 #define ASSOCIATE_TRANSACTION_FILE_TIP   N_("Associate a file with the current transaction")
 #define ASSOCIATE_TRANSACTION_LOCATION_TIP    N_("Associate a location with the current transaction")
 #define EXECASSOCIATED_TRANSACTION_TIP   N_("Open the associated file or location with the current transaction")
+#define JUMP_ASSOCIATED_INVOICE_TIP      N_("Open the associated invoice")
 #define CUT_SPLIT_TIP                    N_("Cut the selected split into clipboard")
 #define COPY_SPLIT_TIP                   N_("Copy the selected split into clipboard")
 #define PASTE_SPLIT_TIP                  N_("Paste the split from the clipboard")
@@ -339,6 +345,11 @@ static GtkActionEntry gnc_plugin_page_register_actions [] =
         EXECASSOCIATED_TRANSACTION_TIP,
         G_CALLBACK (gnc_plugin_page_register_cmd_execassociated_transaction)
     },
+    {
+        "JumpAssociatedInvoiceAction", NULL, JUMP_ASSOCIATED_INVOICE_LABEL, NULL,
+        JUMP_ASSOCIATED_INVOICE_TIP,
+        G_CALLBACK (gnc_plugin_page_register_cmd_jump_associated_invoice)
+    },
 
     /* View menu */
 
@@ -513,6 +524,7 @@ static action_toolbar_labels toolbar_labels[] =
     { "AssociateTransactionFileAction",     N_("Associate File") },
     { "AssociateTransactionLocationAction", N_("Associate Location") },
     { "ExecAssociatedTransactionAction",    N_("Open File/Location") },
+    { "JumpAssociatedInvoiceAction",        N_("Open Invoice") },
     { NULL, NULL },
 };
 
@@ -890,6 +902,7 @@ static const char* tran_action_labels[] =
     ASSOCIATE_TRANSACTION_FILE_LABEL,
     ASSOCIATE_TRANSACTION_LOCATION_LABEL,
     EXECASSOCIATED_TRANSACTION_LABEL,
+    JUMP_ASSOCIATED_INVOICE_LABEL,
     NULL
 };
 
@@ -904,6 +917,7 @@ static const char* tran_action_tips[] =
     ASSOCIATE_TRANSACTION_FILE_TIP,
     ASSOCIATE_TRANSACTION_LOCATION_TIP,
     EXECASSOCIATED_TRANSACTION_TIP,
+    JUMP_ASSOCIATED_INVOICE_TIP,
     NULL
 };
 
@@ -937,6 +951,7 @@ gnc_plugin_page_register_ui_update (gpointer various, GncPluginPageRegister *pag
     GtkAction *action;
     gboolean expanded, voided, read_only = FALSE;
     Transaction *trans;
+    GncInvoice *inv;
     CursorClass cursor_class;
     const char *uri;
 
@@ -1009,6 +1024,12 @@ gnc_plugin_page_register_ui_update (gpointer various, GncPluginPageRegister *pag
                                          "ExecAssociatedTransactionAction");
     gtk_action_set_sensitive (GTK_ACTION(action), (uri && *uri));
 
+    /* Set 'ExecAssociatedInvoice' */
+    inv = invoice_from_trans(trans);
+    action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page),
+                                         "JumpAssociatedInvoiceAction");
+    gtk_action_set_sensitive (GTK_ACTION(action), (!(!inv)));
+
     gnc_plugin_business_split_reg_ui_update (GNC_PLUGIN_PAGE(page));
 
     /* If we are in a readonly book, make any modifying action inactive */
@@ -4307,6 +4328,60 @@ gnc_plugin_page_register_cmd_execassociated_transaction (GtkAction *action,
 
 }
 
+static GncInvoice * invoice_from_trans (Transaction *trans)
+{
+    GncInvoice *invoice;
+    SplitList *splits;
+
+    g_return_if_fail (GNC_IS_TRANSACTION(trans));
+    invoice = gncInvoiceGetInvoiceFromTxn(trans);
+
+    if (invoice)
+        return invoice;
+
+    for (splits = xaccTransGetSplitList (trans); splits; splits = splits->next)
+    {
+        Split *split = splits->data;
+        GNCLot *lot;
+
+        if (!split)
+            continue;
+
+        lot = xaccSplitGetLot (split);
+        if (!lot)
+            continue;
+
+        invoice = gncInvoiceGetInvoiceFromLot (lot);
+        if (!invoice)
+            continue;
+
+        return invoice;
+    }
+
+    return NULL;
+}
+
+static void
+gnc_plugin_page_register_cmd_jump_associated_invoice (GtkAction *action,
+        GncPluginPageRegister *plugin_page)
+{
+    GncPluginPageRegisterPrivate *priv;
+    SplitRegister *reg;
+    GncInvoice *invoice;
+
+    ENTER("(action %p, plugin_page %p)", action, plugin_page);
+
+    g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
+    reg = gnc_ledger_display_get_split_register (priv->gsr->ledger);
+    invoice = invoice_from_trans (xaccSplitGetParent
+                                  (gnc_split_register_get_current_split (reg)));
+    if (invoice)
+        gnc_ui_invoice_edit (NULL, invoice);
+
+    LEAVE(" ");
+}
+
 static void
 gnc_plugin_page_register_cmd_blank_transaction (GtkAction *action,
         GncPluginPageRegister *plugin_page)
diff --git a/gnucash/ui/gnc-plugin-page-register-ui.xml b/gnucash/ui/gnc-plugin-page-register-ui.xml
index 23d64d558..517afcbca 100644
--- a/gnucash/ui/gnc-plugin-page-register-ui.xml
+++ b/gnucash/ui/gnc-plugin-page-register-ui.xml
@@ -25,6 +25,8 @@
       <menuitem name="AssociateTransactionFile" action="AssociateTransactionFileAction"/>
       <menuitem name="AssociateTransactionLocation" action="AssociateTransactionLocationAction"/>
       <menuitem name="ExecAssociateTransaction" action="ExecAssociatedTransactionAction"/>
+      <separator name="TransactionSep4"/>
+      <menuitem name="JumpAssociateInvoice" action="JumpAssociatedInvoiceAction"/>
     </menu>
 
     <menu name="View" action="ViewAction">
@@ -101,6 +103,8 @@
       <menuitem name="AssociateTransactionLocation" action="AssociateTransactionLocationAction"/>
       <menuitem name="ExecAssociateTransaction" action="ExecAssociatedTransactionAction"/>
       <separator name="PopupSep4"/>
+      <menuitem name="JumpAssociateInvoice"    action="JumpAssociatedInvoiceAction"/>
+      <separator name="PopupSep5"/>
       <menuitem name="BlankTransaction"        action="BlankTransactionAction"/>
       <menuitem name="SplitTransaction"        action="SplitTransactionAction"/>
       <menuitem name="EditExchangeRate"        action="EditExchangeRateAction"/>

commit 32a340350d2239c2e71408f69a2d4a4b11bf2cfb
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 3 13:41:29 2019 +0800

    Bug 797468 - Receivable Aging report - phantom company with negative total
    
    usability fix - warn if no documents were selected

diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index b1f96523a..6f8657e82 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -937,6 +937,14 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(pw->docs_list_tree_view));
         gtk_tree_selection_selected_foreach (selection, get_selected_lots, &selected_lots);
 
+        if ((gtk_tree_selection_count_selected_rows (selection) == 0) &&
+            !(gnc_verify_dialog ( GTK_WINDOW(pw->dialog), FALSE,
+                                  _("No documents were selected to assign this payment to. This may create an unattached payment. Do you wish to continue?"))))
+        {
+            gnc_resume_gui_refresh ();
+            return;
+        }
+
         /* When the payment amount is 0, the selected documents cancel each other out
          * so no money is actually transferred.
          * For non-zero payments money will be transferred between the post account

commit be4e4524242031b7575178e4a5900a39f5fdfe8a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 3 11:47:08 2019 +0800

    with-output-to-file -> call-with-output-file

diff --git a/gnucash/report/report-system/test/test-extras.scm b/gnucash/report/report-system/test/test-extras.scm
index 210708381..eeb7b0292 100644
--- a/gnucash/report/report-system/test/test-extras.scm
+++ b/gnucash/report/report-system/test/test-extras.scm
@@ -53,11 +53,11 @@
     (if test-title
         (gnc:html-document-set-title! document test-title))
     (let ((render (gnc:html-document-render document)))
-      (with-output-to-file (format #f "/tmp/~a-~a.html"
+      (call-with-output-file (format #f "/tmp/~a-~a.html"
                                    (string-map sanitize-char prefix)
                                    (string-map sanitize-char test-title))
-        (lambda ()
-          (display render)))
+        (lambda (p)
+          (display render p)))
       render)))
 
 (define (strip-string s1 s2)
diff --git a/gnucash/report/report-system/test/test-report-html.scm b/gnucash/report/report-system/test/test-report-html.scm
index 5c672690c..9a1cd8c52 100644
--- a/gnucash/report/report-system/test/test-report-html.scm
+++ b/gnucash/report/report-system/test/test-report-html.scm
@@ -892,9 +892,9 @@ HTML Document Title</title></head><body></body>\n\
       (gnc:html-document-set-style-sheet! doc (gnc:html-style-sheet-find "Default"))
       (gnc:html-document-add-object! doc table)
       (let ((render (gnc:html-document-render doc)))
-        (with-output-to-file (format #f "/tmp/html-acct-table-~a.html" prefix)
-          (lambda ()
-            (display render)))
+        (call-with-output-file (format #f "/tmp/html-acct-table-~a.html" prefix)
+          (lambda (p)
+            (display render p)))
         (xml->sxml render
                    #:trim-whitespace? #t
                    #:entities '((nbsp . "\xa0")
diff --git a/gnucash/report/report-system/trep-engine.scm b/gnucash/report/report-system/trep-engine.scm
index fbcce9f05..7509a40ad 100644
--- a/gnucash/report/report-system/trep-engine.scm
+++ b/gnucash/report/report-system/trep-engine.scm
@@ -2204,9 +2204,9 @@ be excluded from periodic reporting.")
               (if (list? csvlist)
                   (catch #t
                     (lambda ()
-                      (with-output-to-file filename
-                        (lambda ()
-                          (display (lists->csv (append infolist csvlist))))))
+                      (call-with-output-file filename
+                        (lambda (p)
+                          (display (lists->csv (append infolist csvlist)) p))))
                     (lambda (key . args)
                       ;; Translators: ~a error type, ~a filename, ~s error details
                       (let ((fmt (N_ "error ~a during csv output to ~a: ~s")))

commit 977b1fcf9d38bf7e29b23abfb66690427138b090
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 3 11:38:23 2019 +0800

    [qif-guess-map] with-output-to-file -> call-with-output-file
    
    with-output-to-file will redirect stdout to file.
    call-with-output-file is better because it accepts a port for it. thus
    stdout remains available to log tracefile.

diff --git a/gnucash/import-export/qif-imp/qif-guess-map.scm b/gnucash/import-export/qif-imp/qif-guess-map.scm
index f19ab0c52..067013dee 100644
--- a/gnucash/import-export/qif-imp/qif-guess-map.scm
+++ b/gnucash/import-export/qif-imp/qif-guess-map.scm
@@ -184,13 +184,14 @@
 ;;  of bogus accounts if you have funny stuff in your map.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(define (qif-import:write-map hashtab)
+(define (qif-import:write-map hashtab port)
   (let ((table '()))
-    (hash-fold
-     (lambda (key value p)
-       (set! table (cons (cons key (record-fields->list value)) table))
-       #f) #f hashtab)
-    (write table)))
+    (hash-for-each
+     (lambda (key value)
+       (set! table
+         (cons (cons key (record-fields->list value)) table)))
+     hashtab)
+    (write table port)))
 
 (define (qif-import:read-map tablist tab-sep)
   (let* ((table (make-hash-table 20))
@@ -255,34 +256,29 @@
 ;;  GnuCash commodity namespaces and mnemonics (symbols).
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(define (qif-import:write-securities security-hash security-prefs)
+(define (qif-import:write-securities security-hash security-prefs port)
   (let ((table '()))
     ;; For each security that has been paired with an existing
     ;; GnuCash commodity, create a list containing the QIF name
     ;; and the commodity's namespace and mnemonic (symbol).
-    (hash-fold
-      (lambda (key value p)
-        ;;FIXME: we used to type-check the values, like:
-        ;; (gw:wcp-is-of-type? <gnc:commodity*> value)
-        (if (and value #t)
-            (set! table (cons (list key
-                                   (gnc-commodity-get-namespace value)
-                                   (gnc-commodity-get-mnemonic value))
-                              table))
-            (gnc:warn "qif-import:write-securities:"
-                      " something funny in hash table."))
-        #f)
-      #f security-hash)
+    (hash-for-each
+     (lambda (key value)
+       (set! table
+         (cons (list key
+                     (gnc-commodity-get-namespace value)
+                     (gnc-commodity-get-mnemonic value))
+               table)))
+     security-hash)
 
     ;; Add on the rest of the saved security mapping preferences.
     (for-each
-      (lambda (m)
-        (if (not (hash-ref security-hash (car m)))
-            (set! table (cons m table))))
-      security-prefs)
+     (lambda (m)
+       (if (not (hash-ref security-hash (car m)))
+           (set! table (cons m table))))
+     security-prefs)
 
     ;; Write out the mappings.
-    (write table)))
+    (write table port)))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -301,38 +297,38 @@
 
   ;; This procedure does all the work. We'll define it, then call it safely.
   (define (private-save)
-    (with-output-to-file (gnc-build-userdata-path "qif-accounts-map")
-      (lambda ()
-        (display ";;; qif-accounts-map")
-        (newline)
-        (display ";;; Automatically generated by GnuCash. DO NOT EDIT.")
-        (newline)
-        (display ";;; (Unless you really, really want to.)")
-        (newline)
-        (display ";;; Map QIF accounts to GnuCash accounts")
-        (newline)
-        (qif-import:write-map acct-map)
-        (newline)
-
-        (display ";;; Map QIF categories to GnuCash accounts")
-        (newline)
-        (qif-import:write-map cat-map)
-        (newline)
-
-        (display ";;; Map QIF payee/memo to GnuCash accounts")
-        (newline)
-        (qif-import:write-map memo-map)
-        (newline)
-
-        (display ";;; Map QIF security names to GnuCash commodities")
-        (newline)
-        (qif-import:write-securities security-map security-prefs)
-        (newline)
-
-        (display ";;; GnuCash separator used in these mappings")
-        (newline)
-        (write (gnc-get-account-separator-string))
-        (newline)))
+    (call-with-output-file (gnc-build-userdata-path "qif-accounts-map")
+      (lambda (port)
+        (display ";;; qif-accounts-map" port)
+        (newline port)
+        (display ";;; Automatically generated by GnuCash. DO NOT EDIT." port)
+        (newline port)
+        (display ";;; (Unless you really, really want to.)" port)
+        (newline port)
+        (display ";;; Map QIF accounts to GnuCash accounts" port)
+        (newline port)
+        (qif-import:write-map acct-map port)
+        (newline port)
+
+        (display ";;; Map QIF categories to GnuCash accounts" port)
+        (newline port)
+        (qif-import:write-map cat-map port)
+        (newline port)
+
+        (display ";;; Map QIF payee/memo to GnuCash accounts" port)
+        (newline port)
+        (qif-import:write-map memo-map port)
+        (newline port)
+
+        (display ";;; Map QIF security names to GnuCash commodities" port)
+        (newline port)
+        (qif-import:write-securities security-map security-prefs port)
+        (newline port)
+
+        (display ";;; GnuCash separator used in these mappings" port)
+        (newline port)
+        (write (gnc-get-account-separator-string) port)
+        (newline port)))
     #t)
 
   ;; Safely save the file.



Summary of changes:
 gnucash/gnome/dialog-payment.c                     |   8 ++
 gnucash/gnome/gnc-plugin-page-register.c           |  75 ++++++++++++++
 gnucash/import-export/qif-imp/qif-guess-map.scm    | 110 ++++++++++-----------
 gnucash/report/report-system/test/test-extras.scm  |   6 +-
 .../report/report-system/test/test-report-html.scm |   6 +-
 gnucash/report/report-system/trep-engine.scm       |   6 +-
 gnucash/ui/gnc-plugin-page-register-ui.xml         |   4 +
 7 files changed, 149 insertions(+), 66 deletions(-)



More information about the gnucash-changes mailing list