Skip to content

Commit

Permalink
Fix metadata on cancel_reason so it is an exportable field
Browse files Browse the repository at this point in the history
This means it is available for searching
  • Loading branch information
eileenmcnaughton committed Sep 5, 2018
1 parent 0ab5c4c commit 6f180bc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
3 changes: 1 addition & 2 deletions CRM/Contribute/BAO/Query.php
Expand Up @@ -916,8 +916,7 @@ public static function buildSearchForm(&$form) {
$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');

Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/DAO/Contribution.php
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contribute/Contribution.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:45a20d00d01766a61687cbac5cef1482)
* (GenCodeChecksum:eec525df6c3c6151861750217f3ebe5d)
*/

/**
Expand Down Expand Up @@ -584,7 +584,7 @@ public static function &fields() {
'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',
Expand Down
8 changes: 8 additions & 0 deletions CRM/Contribute/Form/Search.php
Expand Up @@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Contribute/Form/Search/Common.tpl
Expand Up @@ -158,8 +158,8 @@
{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>
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Expand Up @@ -302,6 +302,21 @@ public function testGetContributionReturnFunctionality() {
}
}

/**
* 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.
*/
Expand Down
3 changes: 3 additions & 0 deletions xml/schema/Contribute/Contribution.xml
Expand Up @@ -286,10 +286,13 @@
<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>
Expand Down

0 comments on commit 6f180bc

Please sign in to comment.