-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
[REF] Fix financial item allocation of negative payments against completed payments #17810
Conversation
(Standard links)
|
@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? |
@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 |
test this please |
@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 |
@seamuslee001 so the remaining edge case is if you refund more than was actually paid - that overpayment would not have items. |
@seamuslee001 test fail relates |
Note failure is Stacktrace /home/jenkins/bknix-dfl/build/core-17810-4zcyi/web/sites/all/modules/civicrm/tests/phpunit/CRM/Event/Form/ParticipantTest.php:187 |
@seamuslee001 this still has test failures |
dc3d089
to
d55ff32
Compare
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
d55ff32
to
a0e872f
Compare
Thanks @seamuslee001 - I think it's covered then |
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