Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Fix financial item allocation of negative payments against completed payments #17810

Merged
merged 1 commit into from
Sep 1, 2020

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Jul 13, 2020

Overview

This the allocation of negative payments (created by Payment.create) such that pro-rata line items are created for the financial items

Before

Negative payment can be made against contribution but no financial item is created to allocate it against line items

After

Negative payments made using payment.create API create pro-rata line items

Technical Details

This fixes financial item allocation for a negative payment where the current contribution balance is fully paid (via the payment.create API)

ping @mattwire @eileenmcnaughton @monishdeb

@civibot
Copy link

civibot bot commented Jul 13, 2020

(Standard links)

@civibot civibot bot added the master label Jul 13, 2020
@mattwire
Copy link
Contributor

@seamuslee001 I saw the discussion on mattermost around this. Can we get a bit more description about what it currently does and what we are expecting to see in terms of financial transactions/items?

@seamuslee001
Copy link
Contributor Author

@mattwire I was working on the moneris plugin for JMA working on integrating full refund via moneris JMAConsulting/ca.civicrm.moneris@aa7e0a2#diff-61e08438be5781d5849a1554cae3f01eR401 I was finding that when i was calling payment.create on a completed payment with total_amount = - the current total amount and contribution_id = and this only had 1 payment. I was finding that the correct financial trxn was being recorded but no financial item was getting recorded because the allocation for the line items was getting set to 0

@eileenmcnaughton eileenmcnaughton changed the title [REF] permit negative payments to be made against completed payments [REF] Fix financial item allocation of negative payments against completed payments Jul 13, 2020
@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 that test failed without this fix didn't it? This looks good to me. Tests were failing but will likely pass on re-run

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 so the remaining edge case is if you refund more than was actually paid - that overpayment would not have items.

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 test fail relates

@eileenmcnaughton
Copy link
Contributor

Note failure is

Stacktrace
CRM_Event_Form_ParticipantTest::testPaymentAllocationOnMultiLineItemEvent
Failed asserting that actual size 5 matches expected size 4.

/home/jenkins/bknix-dfl/build/core-17810-4zcyi/web/sites/all/modules/civicrm/tests/phpunit/CRM/Event/Form/ParticipantTest.php:187
/home/jenkins/bknix-dfl/build/core-17810-4zcyi/web/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php:209
/home/jenkins/bknix-dfl/extern/phpunit7/phpunit7.phar:615

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 this still has test failures

@seamuslee001 seamuslee001 force-pushed the negative_payment_create branch from dc3d089 to d55ff32 Compare August 3, 2020 00:33
@seamuslee001
Copy link
Contributor Author

ok I think I have fixed the failing test here

@@ -486,6 +486,9 @@ protected static function getPayableLineItems($params): array {
if ($outstandingBalance !== 0.0) {
$ratio = $params['total_amount'] / $outstandingBalance;
}
elseif ($params['total_amount'] < 0) {
$ratio = $params['total_amount'] / (float) CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id'], TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 what if CRM_Core_BAO_FinancialTrxn::getTotalPayments() = 0 or is less than 0

I suspect in the former case you would get a divided by zero error.

I'm trying to get my head around the latter case but negative contributions are somewhat common whereas adding a refund to an already refunded contribution must be getting quite obscure but still possible I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton I have now added in 2 unit tests one for adding an negative payment to an already refunded contribution and another adding another negative payment onto a negative contribution. In Neither case i encountered the fact that this was 0 because the $outstandingBalance was always non 0. Let me know what you think of the tests

Add in unit test for adding additional refund payment to contribution already refunded and also adding a negative payment to a contribution that is negative already
@eileenmcnaughton
Copy link
Contributor

Thanks @seamuslee001 - I think it's covered then

@seamuslee001 seamuslee001 merged commit 355c505 into civicrm:master Sep 1, 2020
@seamuslee001 seamuslee001 deleted the negative_payment_create branch September 1, 2020 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants