From 0408b3c2cf65167c0fc70e1b99d3b56caa71984f Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 24 Dec 2020 14:47:29 +1300 Subject: [PATCH] [REF] Fix tax_amount to be consistent & load from the templateContribution This leverages the work done in https://github.com/civicrm/civicrm-core/pull/15517/files (the test in particular) but alters it to be more consistent. The original fix relied on the tax_amount on the contribution object passed in - this fixes it to get the amount from the templateContribution (which is more consistent now than when the patch was likely written --- CRM/Contribute/BAO/Contribution.php | 5 +---- tests/phpunit/api/v3/ContributionTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index f535d6487d..2f83383206 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -2442,7 +2442,7 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ else { $contributionParams['financial_type_id'] = $templateContribution['financial_type_id']; } - foreach (['contact_id', 'currency', 'source', 'amount_level', 'address_id', 'on_behalf', 'source_contact_id'] as $fieldName) { + foreach (['contact_id', 'currency', 'source', 'amount_level', 'address_id', 'on_behalf', 'source_contact_id', 'tax_amount'] as $fieldName) { if (isset($templateContribution[$fieldName])) { $contributionParams[$fieldName] = $templateContribution[$fieldName]; } @@ -2465,9 +2465,6 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ if (isset($contribution->contribution_page_id) && is_numeric($contribution->contribution_page_id)) { $contributionParams['contribution_page_id'] = $contribution->contribution_page_id; } - if (!empty($contribution->tax_amount)) { - $contributionParams['tax_amount'] = $contribution->tax_amount; - } $createContribution = civicrm_api3('Contribution', 'create', $contributionParams); $contribution->id = $createContribution['id']; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 22da640db6..c8886af5b3 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -4721,8 +4721,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { /** * Test Repeat Transaction Contribution with Tax amount. * https://lab.civicrm.org/dev/core/issues/806 + * + * @throws \CRM_Core_Exception */ - public function testRepeatContributionWithTaxAmount() { + public function testRepeatContributionWithTaxAmount(): void { $this->enableTaxAndInvoicing(); $financialType = $this->callAPISuccess('financial_type', 'create', [ 'name' => 'Test taxable financial Type', @@ -4740,7 +4742,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->callAPISuccess('contribution', 'repeattransaction', [ 'original_contribution_id' => $contribution['id'], 'contribution_status_id' => 'Completed', - 'trxn_id' => uniqid(), + 'trxn_id' => 'test', ]); $payments = $this->callAPISuccess('Contribution', 'get', ['sequential' => 1])['values']; //Assert if first payment and repeated payment has the same contribution amount. -- 2.25.1