gnucash unstable: Bug 736765 - Assign as payment... should re-populate the payment represented by the selected transaction if any

Geert Janssens gjanssens at code.gnucash.org
Sat Nov 18 12:54:32 EST 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/75fb4e7a (commit)
	from  https://github.com/Gnucash/gnucash/commit/949f2db4 (commit)



commit 75fb4e7a0ceda8ac5ba21866fc13cf39f79cc11c
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Sat Nov 18 18:53:55 2017 +0100

    Bug 736765 - Assign as payment... should re-populate the payment represented by the selected transaction if any
    
    The main topic of this bug was already fixed in earlier commits. This commit
    handles the minor improvements also mentioned here:
    - don't show the menu option for invoice/bill transactions as that doesn't make sense
    - don't show the pre-payment line if the selected transaction was one, in this case only set the amount
    - allow users to edit lot link transactions via this mechanism as well (which essentially are payments without an explicit payment split)

diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index d45a946..62b8ca0 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -541,7 +541,10 @@ gnc_payment_window_fill_docs_list (PaymentWindow *pw)
                                     GNC_HOW_RND_ROUND_HALF_UP);
         }
 
-        if (gnc_numeric_positive_p (value))
+        if (gnc_numeric_zero_p (value))
+        /* If the lot's balance is 0 after the above compensation, skip this lot */
+            continue;
+        else if (gnc_numeric_positive_p (value))
             debit = value;
         else
             credit = gnc_numeric_neg (value);
@@ -1473,16 +1476,23 @@ static char *gen_split_desc (Transaction *txn, Split *split)
 
 static Split *select_payment_split (GtkWidget *parent, Transaction *txn)
 {
+    /* We require the txn to have one split in an Asset account.
+     * The only exception would be a lot link transaction
+     */
     GList *payment_splits = xaccTransGetPaymentAcctSplitList (txn);
     if (!payment_splits)
     {
+        GtkWidget *dialog;
+
+        if (xaccTransGetTxnType(txn) == TXN_TYPE_LINK)
+            return NULL;
 
-        GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
-                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                    GTK_MESSAGE_INFO,
-                                                    GTK_BUTTONS_CLOSE,
-                                                    "%s",
-                                                    _("The selected transaction doesn't have splits that can be assigned as a payment"));
+        dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
+                                         GTK_DIALOG_DESTROY_WITH_PARENT,
+                                         GTK_MESSAGE_INFO,
+                                         GTK_BUTTONS_CLOSE,
+                                         "%s",
+                                         _("The selected transaction doesn't have splits that can be assigned as a payment"));
         gtk_dialog_run (GTK_DIALOG(dialog));
         gtk_widget_destroy (dialog);
         g_message("No asset splits in txn \"%s\"; cannot use this for assigning a payment.",
@@ -1647,12 +1657,14 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GtkWidget* parent, GncOwner *owner,
     if (!txn)
         return NULL;
 
-    // We require the txn to have one split in an Asset account.
     if (!xaccTransGetSplitList(txn))
         return NULL;
 
+    /* We require the txn to have one split in an Asset account.
+     * The only exception would be a lot link transaction
+     */
     payment_split = select_payment_split (parent, txn);
-    if (!payment_split)
+    if (!payment_split && (xaccTransGetTxnType(txn) != TXN_TYPE_LINK))
         return NULL;
 
     /* Get all APAR related lots. Watch out: there might be none */
@@ -1678,6 +1690,7 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GtkWidget* parent, GncOwner *owner,
         gnc_ui_payment_window_set_date(pw, &txn_date);
     }
     gnc_ui_payment_window_set_amount(pw, xaccSplitGetValue(payment_split));
-    gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(payment_split));
+    if (payment_split)
+        gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(payment_split));
     return pw;
 }
diff --git a/gnucash/gnome/gnc-plugin-business.c b/gnucash/gnome/gnc-plugin-business.c
index 5b1efca..366574b 100644
--- a/gnucash/gnome/gnc-plugin-business.c
+++ b/gnucash/gnome/gnc-plugin-business.c
@@ -904,7 +904,7 @@ gnc_plugin_business_update_menus (GncPluginPage *plugin_page)
 {
     GncMainWindow  *window;
     GtkActionGroup *action_group;
-    gboolean is_txn_register, is_bus_txn = FALSE;
+    gboolean is_txn_register, is_bus_txn = FALSE, is_bus_doc = FALSE;
 
     // We continue only if the current page is a plugin page
     if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
@@ -921,16 +921,17 @@ gnc_plugin_business_update_menus (GncPluginPage *plugin_page)
         Transaction *trans = gnc_plugin_page_register_get_current_txn (GNC_PLUGIN_PAGE_REGISTER(plugin_page));
         if (xaccTransCountSplits(trans) > 0)
             is_bus_txn = (xaccTransGetFirstAPARAcctSplit(trans, TRUE) != NULL);
+        is_bus_doc = (xaccTransGetTxnType (trans) == TXN_TYPE_INVOICE);
     }
     // Change visibility and also sensitivity according to whether we are in a txn register
     gnc_plugin_update_actions (action_group, register_txn_actions,
-                               "sensitive", is_txn_register && !is_bus_txn);
+                               "sensitive", is_txn_register && !is_bus_txn && !is_bus_doc);
     gnc_plugin_update_actions (action_group, register_txn_actions,
-                               "visible", is_txn_register && !is_bus_txn);
+                               "visible", is_txn_register && !is_bus_txn && !is_bus_doc);
     gnc_plugin_update_actions (action_group, register_bus_txn_actions,
-                               "sensitive", is_txn_register && is_bus_txn);
+                               "sensitive", is_txn_register && is_bus_txn && !is_bus_doc);
     gnc_plugin_update_actions (action_group, register_bus_txn_actions,
-                               "visible", is_txn_register && is_bus_txn);
+                               "visible", is_txn_register && is_bus_txn && !is_bus_doc);
 }
 
 



Summary of changes:
 gnucash/gnome/dialog-payment.c      | 33 +++++++++++++++++++++++----------
 gnucash/gnome/gnc-plugin-business.c | 11 ++++++-----
 2 files changed, 29 insertions(+), 15 deletions(-)



More information about the gnucash-changes mailing list