dev/core#1367 - Incorrect line items recorded with contribution repeattransaction api
authorJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 5 Nov 2019 12:17:08 +0000 (17:47 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 5 Nov 2019 12:17:08 +0000 (17:47 +0530)
CRM/Contribute/BAO/ContributionRecur.php
tests/phpunit/api/v3/ContributionTest.php

index 38e7cb999a7ffd7af59106bc7da63afd3120338d..b9ea712716757c3d7a1bf23a1e21f3cc129851a6 100644 (file)
@@ -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;
index c71b7159a7c70b55913ae4ed8a59407847495768..0983069bbf89b07cddfe4d22c15764928b3012e8 100644 (file)
@@ -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() {