Let the "assign payment" feature choose customer or vendor payment, depending on whether the amount is positive or negative.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21401 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-10-08 20:30:28 +00:00
parent 01b4a86888
commit b32a0aa0e7
3 changed files with 41 additions and 1 deletions

View File

@ -826,6 +826,37 @@ static Split *getFirstOtherSplit(SplitList* slist, const Split *postaccount_spli
// /////////////// // ///////////////
gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn)
{
SplitList *slist;
gboolean result = TRUE;
if (!txn)
return result;
// We require the txn to have one split in an A/R or A/P account.
slist = xaccTransGetSplitList(txn);
if (!slist)
return result;
if (countAssetAccounts(slist) == 0)
{
g_message("No asset splits in txn \"%s\"; cannot use this for assigning a payment.",
xaccTransGetDescription(txn));
return result;
}
{
Split *assetaccount_split = getFirstAssetAccountSplit(slist);
gnc_numeric amount = xaccSplitGetValue(assetaccount_split);
gboolean result = gnc_numeric_positive_p(amount); // positive amounts == customer
//g_message("Amount=%s", gnc_numeric_to_string(amount));
return result;
}
}
// ///////////////
PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn) PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)
{ {
SplitList *slist; SplitList *slist;
@ -853,6 +884,7 @@ PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn)
PaymentWindow *pw = gnc_ui_payment_new(owner, PaymentWindow *pw = gnc_ui_payment_new(owner,
qof_instance_get_book(QOF_INSTANCE(txn))); qof_instance_get_book(QOF_INSTANCE(txn)));
g_assert(assetaccount_split); // we can rely on this because of the countAssetAccounts() check above g_assert(assetaccount_split); // we can rely on this because of the countAssetAccounts() check above
//g_message("Amount=%s", gnc_numeric_to_string(amount));
// Fill in the values from the given txn // Fill in the values from the given txn
pw->pre_existing_txn = txn; pw->pre_existing_txn = txn;

View File

@ -36,6 +36,10 @@ PaymentWindow * gnc_ui_payment_new_with_invoice (GncOwner *owner,
GncInvoice *invoice); GncInvoice *invoice);
PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn); PaymentWindow * gnc_ui_payment_new_with_txn (GncOwner *owner, Transaction *txn);
/** Returns TRUE if the given transaction (to be used with gnc_ui_payment_new_with_txn() )
* is for a customer, or FALSE if it's from a vendor or employee voucher. */
gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn);
/* Destroy a payment window */ /* Destroy a payment window */
void gnc_ui_payment_window_destroy (PaymentWindow *pw); void gnc_ui_payment_window_destroy (PaymentWindow *pw);

View File

@ -896,6 +896,7 @@ static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,
SplitRegister *reg; SplitRegister *reg;
Split *split; Split *split;
Transaction *trans; Transaction *trans;
gboolean is_customer;
g_return_if_fail (mw != NULL); g_return_if_fail (mw != NULL);
g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data)); g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
@ -919,13 +920,16 @@ static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,
trans = xaccSplitGetParent(split); trans = xaccSplitGetParent(split);
g_return_if_fail(trans); g_return_if_fail(trans);
is_customer = gnc_ui_payment_is_customer_payment(trans);
plugin_business = GNC_PLUGIN_BUSINESS (mw->data); plugin_business = GNC_PLUGIN_BUSINESS (mw->data);
plugin_business_priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin_business); plugin_business_priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin_business);
gnc_business_assign_payment (gnc_plugin_page_get_window(plugin_page), gnc_business_assign_payment (gnc_plugin_page_get_window(plugin_page),
trans, trans,
plugin_business_priv->last_customer); is_customer
? plugin_business_priv->last_customer
: plugin_business_priv->last_vendor);
} }
static const gchar *register_txn_actions[] = static const gchar *register_txn_actions[] =