Skip to content

Commit

Permalink
Bug 719904 - Decide payment type only based on the account type involved
Browse files Browse the repository at this point in the history
This commit improves payment type deduction by first checking
whether an AR or AP account is found in the transaction.
If not, fall back to previous heuristic of positive action
means customer payment, negative action means vendor
action. The logic can still go wrong (no means to declare
an employee payment, and credit notes are interpreted as
opposite sign payments). Needs a follow up to fix that.
  • Loading branch information
gjanssens committed Mar 25, 2016
1 parent 6fd3569 commit f5a7aec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
21 changes: 18 additions & 3 deletions src/business/business-gnome/dialog-payment.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,19 +1170,34 @@ gnc_ui_payment_new (GncOwner *owner, QofBook *book)
gboolean gnc_ui_payment_is_customer_payment(const Transaction *txn)
{
gboolean result = TRUE;
Split *assetaccount_split;
Split *assetaccount_split, *aparaccount_split;
gnc_numeric amount;

if (!txn)
return result;

// We require the txn to have one split in an A/R or A/P account.

if (!xaccTransGetSplitList(txn))
return result;

/* First test if one split is in an A/R or A/P account.
* That will give us the best Customer vs Vendor/Employee distinction */
aparaccount_split = xaccTransGetFirstAPARAcctSplit(txn);
if (aparaccount_split)
{
if (xaccAccountGetType (xaccSplitGetAccount (aparaccount_split)) == ACCT_TYPE_RECEIVABLE)
return TRUE; // Type is Customer
else if (xaccAccountGetType (xaccSplitGetAccount (aparaccount_split)) == ACCT_TYPE_PAYABLE)
return FALSE; // Type is Vendor/Employee, there's not enough information to refine more
}

/* For the lack of an A/R or A/P account we'll assume positive changes to an
* Asset/Liability or Equity account are Customer payments the others will be
* considered Vendor payments */
assetaccount_split = xaccTransGetFirstPaymentAcctSplit(txn);
if (!assetaccount_split)
{
/* Transaction isn't valid for a payment, just return the default
* Calling code will have to handle this situation properly */
g_message("No asset splits in txn \"%s\"; cannot use this for assigning a payment.",
xaccTransGetDescription(txn));
return result;
Expand Down
18 changes: 12 additions & 6 deletions src/business/business-gnome/gnc-plugin-business.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,9 @@ static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,
SplitRegister *reg;
Split *split;
Transaction *trans;
gboolean is_customer;
gboolean have_owner;
GncOwner owner;
GncOwner *owner_p;

g_return_if_fail (mw != NULL);
g_return_if_fail (GNC_IS_PLUGIN_BUSINESS (mw->data));
Expand All @@ -846,16 +848,20 @@ static void gnc_plugin_business_cmd_assign_payment (GtkAction *action,

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

have_owner = gncOwnerGetOwnerFromTxn (trans, &owner);
if (have_owner)
owner_p = &owner;
else if (gnc_ui_payment_is_customer_payment(trans))
owner_p = plugin_business_priv->last_customer;
else
owner_p = plugin_business_priv->last_vendor;

gnc_business_assign_payment (gnc_plugin_page_get_window(plugin_page),
trans,
is_customer
? plugin_business_priv->last_customer
: plugin_business_priv->last_vendor);
trans, owner_p);
}

static const gchar *register_txn_actions[] =
Expand Down

0 comments on commit f5a7aec

Please sign in to comment.