Addendum to UI Jump to Invoice at 535632b02

Previous trans->invoice strategy was flawed. A payment for multiple
invoices would always return the first invoice found.

A safer approach is to find split->invoice -- this enables a split
from a payment for multiple invoices to retrieve the corresponding
invoice.

The disadvantage is that we cannot jump from bank split to invoice
split anymore; this is acceptable because a payment which covers
multiple invoices would lead to ambiguity and would require UI to
select the invoice for jump.
This commit is contained in:
Christopher Lam 2019-11-04 20:12:36 +08:00
parent e991fe853c
commit 21d608038e

View File

@ -199,7 +199,7 @@ static void gnc_plugin_page_register_event_handler (QofInstance *entity,
GncPluginPageRegister *page, GncPluginPageRegister *page,
GncEventData *ed); GncEventData *ed);
static GncInvoice * invoice_from_trans (Transaction *trans); static GncInvoice * invoice_from_split (Split *split);
/************************************************************/ /************************************************************/
/* Actions */ /* Actions */
@ -1025,7 +1025,7 @@ gnc_plugin_page_register_ui_update (gpointer various, GncPluginPageRegister *pag
gtk_action_set_sensitive (GTK_ACTION(action), (uri && *uri)); gtk_action_set_sensitive (GTK_ACTION(action), (uri && *uri));
/* Set 'ExecAssociatedInvoice' */ /* Set 'ExecAssociatedInvoice' */
inv = invoice_from_trans(trans); inv = invoice_from_split (gnc_split_register_get_current_split (reg));
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page),
"JumpAssociatedInvoiceAction"); "JumpAssociatedInvoiceAction");
gtk_action_set_sensitive (GTK_ACTION(action), inv != NULL); gtk_action_set_sensitive (GTK_ACTION(action), inv != NULL);
@ -4328,37 +4328,23 @@ gnc_plugin_page_register_cmd_execassociated_transaction (GtkAction *action,
} }
static GncInvoice * invoice_from_trans (Transaction *trans) static GncInvoice * invoice_from_split (Split *split)
{ {
GncInvoice *invoice; GncInvoice *invoice;
SplitList *splits; GNCLot *lot;
g_return_val_if_fail (GNC_IS_TRANSACTION(trans), NULL); if (!split)
invoice = gncInvoiceGetInvoiceFromTxn(trans); return NULL;
if (invoice) lot = xaccSplitGetLot (split);
return invoice; if (!lot)
return NULL;
for (splits = xaccTransGetSplitList (trans); splits; splits = splits->next) invoice = gncInvoiceGetInvoiceFromLot (lot);
{ if (!invoice)
Split *split = splits->data; return NULL;
GNCLot *lot;
if (!split) return invoice;
continue;
lot = xaccSplitGetLot (split);
if (!lot)
continue;
invoice = gncInvoiceGetInvoiceFromLot (lot);
if (!invoice)
continue;
return invoice;
}
return NULL;
} }
static void static void
@ -4374,8 +4360,7 @@ gnc_plugin_page_register_cmd_jump_associated_invoice (GtkAction *action,
g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page)); g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page));
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page); priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(plugin_page);
reg = gnc_ledger_display_get_split_register (priv->gsr->ledger); reg = gnc_ledger_display_get_split_register (priv->gsr->ledger);
invoice = invoice_from_trans (xaccSplitGetParent invoice = invoice_from_split (gnc_split_register_get_current_split (reg));
(gnc_split_register_get_current_split (reg)));
if (invoice) if (invoice)
gnc_ui_invoice_edit (NULL, invoice); gnc_ui_invoice_edit (NULL, invoice);