From 5d8c94bc00abee887d4305778b4f51f4853081ad Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Tue, 5 Nov 2019 17:47:08 +0530 Subject: [PATCH] dev/core#1367 - Incorrect line items recorded with contribution repeattransaction api --- CRM/Contribute/BAO/ContributionRecur.php | 6 +++++- tests/phpunit/api/v3/ContributionTest.php | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 38e7cb999a..b9ea712716 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -932,7 +932,11 @@ INNER JOIN civicrm_contribution con ON ( con.id = mp.contribution_id ) // CRM-17718 allow for possibility of changed financial type ID having been set prior to calling this. $lineItem['financial_type_id'] = $financial_type_id; } - if ($lineItem['line_total'] != $total_amount) { + $taxAmountMatches = FALSE; + if ((!empty($lineItem['tax_amount']) && ($lineItem['line_total'] + $lineItem['tax_amount']) == $total_amount)) { + $taxAmountMatches = TRUE; + } + if ($lineItem['line_total'] != $total_amount && !$taxAmountMatches) { // We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these // if there is only one line item, and the UI should prevent this situation for those with more than one. $lineItem['line_total'] = $total_amount; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index c71b7159a7..0983069bbf 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -4380,6 +4380,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase { //Assert if first payment and repeated payment has the same contribution amount. $this->assertEquals($payments[0]['total_amount'], $payments[1]['total_amount']); $this->callAPISuccessGetCount('Contribution', [], 2); + + //Assert line item records. + $lineItems = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1])['values']; + foreach ($lineItems as $lineItem) { + $this->assertEquals($lineItem['unit_price'], $this->_params['total_amount']); + $this->assertEquals($lineItem['line_total'], $this->_params['total_amount']); + } + $this->callAPISuccessGetCount('Contribution', [], 2); } public function testGetCurrencyOptions() { -- 2.25.1