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)
This commit is contained in:
Geert Janssens 2017-11-18 18:53:55 +01:00
parent 949f2db473
commit 75fb4e7a0c
2 changed files with 29 additions and 15 deletions

View File

@ -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,11 +1476,18 @@ 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;
GtkWidget *dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
if (xaccTransGetTxnType(txn) == TXN_TYPE_LINK)
return NULL;
dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
@ -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));
if (payment_split)
gnc_ui_payment_window_set_xferaccount(pw, xaccSplitGetAccount(payment_split));
return pw;
}

View File

@ -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);
}