r21401 - gnucash/trunk/src/business/business-gnome - Let the "assign payment" feature choose customer or vendor payment, depending on whether the amount is positive or negative.
Christian Stimming
cstim at code.gnucash.org
Sat Oct 8 16:30:28 EDT 2011
Author: cstim
Date: 2011-10-08 16:30:28 -0400 (Sat, 08 Oct 2011)
New Revision: 21401
Trac: http://svn.gnucash.org/trac/changeset/21401
Modified:
gnucash/trunk/src/business/business-gnome/dialog-payment.c
gnucash/trunk/src/business/business-gnome/dialog-payment.h
gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
Log:
Let the "assign payment" feature choose customer or vendor payment, depending on whether the amount is positive or negative.
Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.c 2011-10-08 19:19:16 UTC (rev 21400)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.c 2011-10-08 20:30:28 UTC (rev 21401)
@@ -826,6 +826,37 @@
// ///////////////
+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)
{
SplitList *slist;
@@ -853,6 +884,7 @@
PaymentWindow *pw = gnc_ui_payment_new(owner,
qof_instance_get_book(QOF_INSTANCE(txn)));
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
pw->pre_existing_txn = txn;
Modified: gnucash/trunk/src/business/business-gnome/dialog-payment.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-payment.h 2011-10-08 19:19:16 UTC (rev 21400)
+++ gnucash/trunk/src/business/business-gnome/dialog-payment.h 2011-10-08 20:30:28 UTC (rev 21401)
@@ -36,6 +36,10 @@
GncInvoice *invoice);
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 */
void gnc_ui_payment_window_destroy (PaymentWindow *pw);
Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c 2011-10-08 19:19:16 UTC (rev 21400)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-business.c 2011-10-08 20:30:28 UTC (rev 21401)
@@ -896,6 +896,7 @@
SplitRegister *reg;
Split *split;
Transaction *trans;
+ gboolean is_customer;
g_return_if_fail (mw != NULL);
g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
@@ -919,13 +920,16 @@
trans = xaccSplitGetParent(split);
g_return_if_fail(trans);
+ is_customer = gnc_ui_payment_is_customer_payment(trans);
plugin_business = GNC_PLUGIN_BUSINESS (mw->data);
plugin_business_priv = GNC_PLUGIN_BUSINESS_GET_PRIVATE (plugin_business);
gnc_business_assign_payment (gnc_plugin_page_get_window(plugin_page),
trans,
- plugin_business_priv->last_customer);
+ is_customer
+ ? plugin_business_priv->last_customer
+ : plugin_business_priv->last_vendor);
}
static const gchar *register_txn_actions[] =
More information about the gnucash-changes
mailing list