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,
GncEventData *ed);
static GncInvoice * invoice_from_trans (Transaction *trans);
static GncInvoice * invoice_from_split (Split *split);
/************************************************************/
/* Actions */
@ -1025,7 +1025,7 @@ gnc_plugin_page_register_ui_update (gpointer various, GncPluginPageRegister *pag
gtk_action_set_sensitive (GTK_ACTION(action), (uri && *uri));
/* 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),
"JumpAssociatedInvoiceAction");
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;
SplitList *splits;
GNCLot *lot;
g_return_val_if_fail (GNC_IS_TRANSACTION(trans), NULL);
invoice = gncInvoiceGetInvoiceFromTxn(trans);
if (!split)
return NULL;
if (invoice)
return invoice;
lot = xaccSplitGetLot (split);
if (!lot)
return NULL;
for (splits = xaccTransGetSplitList (trans); splits; splits = splits->next)
{
Split *split = splits->data;
GNCLot *lot;
invoice = gncInvoiceGetInvoiceFromLot (lot);
if (!invoice)
return NULL;
if (!split)
continue;
lot = xaccSplitGetLot (split);
if (!lot)
continue;
invoice = gncInvoiceGetInvoiceFromLot (lot);
if (!invoice)
continue;
return invoice;
}
return NULL;
return invoice;
}
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));
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)));
invoice = invoice_from_split (gnc_split_register_get_current_split (reg));
if (invoice)
gnc_ui_invoice_edit (NULL, invoice);