Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#212 - Contribution Details report fails when 'Is not one of'… #12406

Merged
merged 1 commit into from
Jul 5, 2018

Conversation

jitendrapurohit
Copy link
Contributor

… condition is used for Groups field

Overview

Fix DB error when contribution detail report is filtered by is not one of Group operator

Before

  • open Report > Contribution Reports > Contribution Details
  • click on Filters tab
  • scroll down to Groups field
  • change condition to "Is not one of"
  • choose at least one group
  • click Refresh results
  • result: DB Error: no such field

image

After

Filtering on is not one of group operator correctly displays all contacts which are not in any selected group.

Technical Details

Contribuiton Detail Report uses a custom from clause to build the soft credit rows. It missed the group join if there is a temp table already created.

Comments

Added a small unit test to check for any DB failure when group by filter is applied.

Gitlab Ticket - https://lab.civicrm.org/dev/core/issues/212

@civibot
Copy link

civibot bot commented Jul 3, 2018

(Standard links)

@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit I want to suggest an alternate unit test approach - this one is an adjusted one that can work in the ReportTemplateTest class

  /**
   * Test the group filter works on the various reports.
   *
   * @dataProvider getMembershipAndContributionReportTemplatesForGroupTests
   *
   * @param string $template
   *   Report template unique identifier.
   */
  public function testReportsWithNoTInSmartGroupFilter($template) {
    $groupID = $this->setUpPopulatedGroup();
    $rows = $this->callAPISuccess('report_template', 'getrows', array(
      'report_id' => $template,
      'gid_value' => array($groupID),
      'gid_op' => 'notin',
      'options' => array('metadata' => array('sql')),
    ));
    $this->assertNumberOfContactsInResult(2, $rows, $template);
  }

@eileenmcnaughton
Copy link
Contributor

I also tried this

  /**
   * Generate the from clause as it relates to the soft credits.
   */
  public function softCreditFrom() {
    $this->setFromBase('civireport_contribution_detail_temp1', 'id', 'temp1_civireport');
    $this->_from .= "
      INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
        ON temp1_civireport.civicrm_contribution_contribution_id = {$this->_aliases['civicrm_contribution']}.id
      INNER JOIN civicrm_contribution_soft contribution_soft_civireport
        ON contribution_soft_civireport.contribution_id = {$this->_aliases['civicrm_contribution']}.id
      INNER JOIN civicrm_contact      {$this->_aliases['civicrm_contact']}
        ON {$this->_aliases['civicrm_contact']}.id = contribution_soft_civireport.contact_id
    ";

    $this->appendAdditionalFromJoins();
  }

It's not quite working - but I think I may have the id field wrong. That setFromBase adds the acl & group join so I feel like that is nearly the same

@jitendrapurohit
Copy link
Contributor Author

Ah, thanks for the above test. It actually found another similar issue with repeat contribution report. I've updated the PR to include the fix for the same 👍

@eileenmcnaughton
Copy link
Contributor

Remaining fail is just about the need to clean up temporary tables. @totten is there any recommendation for doing this differently now that we have some new routines around temp tables - e.g something cleverer than adding to the tearDown

CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS 'civireport_contribution_detail_temp1');

@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit TBH I think the fix might be a bit narrow (one operator only - notin but not in) - I don't need that changed since we have a unit test but maybe a code note to say that line is covered by tests to give people confidence to alter later.

@@ -364,7 +364,7 @@ public function testLybuntReportWithFYData() {
SELECT SQL_CALC_FOUND_ROWS contact_civireport.id as cid FROM civicrm_contact contact_civireport INNER JOIN civicrm_contribution contribution_civireport USE index (received_date) ON contribution_civireport.contact_id = contact_civireport.id
AND contribution_civireport.is_test = 0
AND contribution_civireport.receive_date BETWEEN \'20140701000000\' AND \'20150630235959\'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failing test is due to this whitespace removal by my editor 🤦‍♂️ . Will update the PR with the fix.

@eileenmcnaughton
Copy link
Contributor

OK - I'm happy with this - thanks @jitendrapurohit !

@eileenmcnaughton eileenmcnaughton merged commit dc382d9 into civicrm:master Jul 5, 2018
@jitendrapurohit jitendrapurohit deleted the core-212 branch July 6, 2018 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants