Fix metadata on cancel_reason so it is an exportable field
authoreileen <emcnaughton@wikimedia.org>
Wed, 5 Sep 2018 05:38:23 +0000 (17:38 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 5 Nov 2018 18:09:23 +0000 (07:09 +1300)
This means it is available for searching

CRM/Contribute/BAO/Query.php
CRM/Contribute/DAO/Contribution.php
CRM/Contribute/Form/Search.php
templates/CRM/Contribute/Form/Search/Common.tpl
tests/phpunit/CRM/Contribute/Form/SearchTest.php
tests/phpunit/CRM/Export/BAO/ExportTest.php
tests/phpunit/api/v3/ContributionTest.php
xml/schema/Contribute/Contribution.xml

index abf05f7e7151b8f3e2a7018aab47d34487259fc6..7d23de39b09d4c35e596e4bf5665106a44df141c 100644 (file)
@@ -506,7 +506,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
           return;
         }
         $whereTable = $fields[$fldName];
-        $value = trim($value);
+        if (!is_array($value)) {
+          $value = trim($value);
+        }
 
         $dataType = "String";
         if (!empty($whereTable['type'])) {
@@ -929,8 +931,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
     $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
     $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
 
-    // Adding Cancelled Contribution fields -- CRM-21343
-    $form->add('text', 'contribution_cancel_reason', ts('Cancellation / Refund Reason'), array('size' => 40));
+    $form->addField('cancel_reason');
     CRM_Core_Form_Date::buildDateRange($form, 'contribution_cancel_date', 1, '_low', '_high', ts('From:'), FALSE);
     $form->addElement('hidden', 'contribution_cancel_date_range_error');
 
index faa6a8c9db4d1ba57b5bde4bde04d785474b24de..299ef839a49ae50d56b2c274c68af6a3ee227a52 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Contribute/Contribution.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:45a20d00d01766a61687cbac5cef1482)
+ * (GenCodeChecksum:eec525df6c3c6151861750217f3ebe5d)
  */
 
 /**
@@ -584,7 +584,7 @@ class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO {
         'cancel_reason' => [
           'name' => 'cancel_reason',
           'type' => CRM_Utils_Type::T_TEXT,
-          'title' => ts('Cancel Reason'),
+          'title' => ts('Cancellation / Refund Reason'),
           'import' => TRUE,
           'where' => 'civicrm_contribution.cancel_reason',
           'headerPattern' => '/(cancel.?)?reason/i',
index 035b9523e822dd4b7e568e8f37ab062a09eadefa..c31c0733f05e8f860b2ee1ded418e6b3e265fd61 100644 (file)
@@ -62,6 +62,14 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
    */
   protected $_prefix = "contribute_";
 
+
+  /**
+   * Explicitly declare the entity api name.
+   */
+  public function getDefaultEntity() {
+    return 'Contribution';
+  }
+
   /**
    * Processing needed for buildForm and later.
    */
index 4412dac0a4cf33a8fa7b3df03770a8c517c2cbd9..add2f855631e8ee361bb43816de019a414085235 100644 (file)
     {include file="CRM/Contribute/Form/PCP.js.tpl"}
   </td>
   <td>
-    {$form.contribution_cancel_reason.label}<br />
-    {$form.contribution_cancel_reason.html}
+    {$form.cancel_reason.label}<br />
+    {$form.cancel_reason.html}
   </td>
 </tr>
 <tr>
index a409cf53b3996ecaf41135de3249c9d1767bdd75..311576a4ade5ed8c78edde899cc8f93215889a82 100644 (file)
@@ -542,14 +542,14 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase {
         'form_value' => array('cancel_reason' => 'Invalid Credit Card Number'),
         'expected_count' => 1,
         'expected_contribution' => array($Contribution3['id']),
-        'expected_qill' => "Cancel Reason Like '%Invalid Credit Card Number%'",
+        'expected_qill' => "Cancellation / Refund Reason Like '%Invalid Credit Card Number%'",
       ),
       // Case 3: Search for Cancelled Date and Cancelled Reason
       array(
         'form_value' => array('cancel_date' => date('Y-m-d'), 'cancel_reason' => 'Insufficient funds'),
         'expected_count' => 1,
         'expected_contribution' => array($Contribution1['id']),
-        'expected_qill' => "Cancel Date Like '%" . date('Y-m-d') . "%'ANDCancel Reason Like '%Insufficient funds%'",
+        'expected_qill' => "Cancel Date Like '%" . date('Y-m-d') . "%'ANDCancellation / Refund Reason Like '%Insufficient funds%'",
       ),
     );
 
index ff368a31d79d12a4765ff5000dbd20bb51d68769..cbdd374827108f165d536f85a85a794a5ba95925 100644 (file)
@@ -2065,7 +2065,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
       95 => 'Invoice Reference',
       96 => 'Invoice Number',
       97 => 'Currency',
-      98 => 'Cancel Reason',
+      98 => 'Cancellation / Refund Reason',
       99 => 'Receipt Date',
       100 => 'Product Name',
       101 => 'SKU',
index 3f7294e023ad56563c01077e5f4c2a290fc3d499..73540669e1c07ade5d54496ae08b7c1b834a595b 100644 (file)
@@ -302,6 +302,21 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * Test cancel reason works as a filter.
+   */
+  public function testFilterCancelReason() {
+    $params = $this->_params;
+    $params['cancel_date'] = 'yesterday';
+    $params['cancel_reason'] = 'You lose sucker';
+    $this->callAPISuccess('Contribution', 'create', $params);
+    $params = $this->_params;
+    $params['cancel_date'] = 'yesterday';
+    $params['cancel_reason'] = 'You are a winner';
+    $this->callAPISuccess('Contribution', 'create', $params);
+    $this->callAPISuccessGetCount('Contribution', ['cancel_reason' => 'You are a winner'], 1);
+  }
+
   /**
    * We need to ensure previous tested behaviour still works as part of the api contract.
    */
index edcb3befa4114113cf03630ef1f12b4830c9bf6c..5ea0ccc0fd8a2e0216253007e3440b9e2fd42253 100644 (file)
   <field>
     <name>cancel_reason</name>
     <type>text</type>
+    <title>Cancellation / Refund Reason</title>
     <import>true</import>
+    <export>true</export>
     <headerPattern>/(cancel.?)?reason/i</headerPattern>
     <html>
       <type>Text</type>
+      <size>40</size>
     </html>
     <add>1.3</add>
   </field>