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

Fix double loop on lineItems #15686

Closed
wants to merge 1 commit into from

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Nov 1, 2019

Overview

Removes unwanted complexity from code

Before

Calling

civicrm_api3('Payment', 'create', ['total_amount' => 500])

passes through different code than

civicrm_api3('Payment', 'create', ['total_amount' => 500, 'line_item' => [[4 => 50], [10 => 450]])

After

Information from the line_item array is 'lifted' early on and then the same loop is used.

Technical Details

Historically the code followed 2 loops - one for the (very rare) situation when an array of
'line_item' was passed in - in fact this array is an array of arrays where each array represents
the id of a line item and the amount to allocate.

The other loop is the main loop that allocates according to a calculation.

This fixes it so that the allocation is correctly merged in if passed in in
getPayableLineItems and from that point we only need one loop.

This simplification is tested via the testCreatePaymentLineItems
which I cleaned up and made more robust. I was able to step through it in #15685 and identify how
it was working

Comments

@kcristiano @monishdeb @pradpnayak can one of you look at this ? We merged one PR in this area relating to allocations but in our digging found other breakage - notably in the refund handling.

I want to get a few preliminary PRs merged - this one
#15640 & #15687 but I want all these fixes to hit 5.20

Historically the code followed 2 loops - one for the (very rare) situation when an array of
'line_item' was passed in - in fact this array is an array of arrays where each array represents
the id of a line item and the amount to allocate.

The other loop is the main loop that allocates according to a calculation.

This fixes it so that the allocation is correctly merged in if passed in in
getPayableLineItems and from that point we only need one loop.

This simplification is tested via the testCreatePaymentLineItems
which I cleaned up and made more robust. I was able to step through it and identify how
it was working
@civibot
Copy link

civibot bot commented Nov 1, 2019

(Standard links)

@civibot civibot bot added the master label Nov 1, 2019
@eileenmcnaughton
Copy link
Contributor Author

test this please

1 similar comment
@eileenmcnaughton
Copy link
Contributor Author

test this please

@colemanw
Copy link
Member

colemanw commented Nov 4, 2019

Code certainly looks better. How's the test coverage?

@eileenmcnaughton
Copy link
Contributor Author

Test coverage is good on this

@kcristiano
Copy link
Member

@eileenmcnaughton It appears that this is also in #15705

@seamuslee001
Copy link
Contributor

@kcristiano i think @eileenmcnaughton is treating that as the "complete package" so to speak but this is a part that can be packaged up separately and merged if you think its ok

@eileenmcnaughton eileenmcnaughton deleted the pay_loop branch November 5, 2019 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants