jenkins-bot has submitted this change and it was merged.

Change subject: Filter refunds out of donation history
......................................................................


Filter refunds out of donation history

Apply the same filters as for the latest_donation logic.

Bug: T148062
Change-Id: If78471c395110016c0d95a2094cbb7b32d6c032f
---
M silverpop_export/tests/test_update.py
M silverpop_export/update_table.sql
2 files changed, 30 insertions(+), 1 deletion(-)

Approvals:
  XenoRyet: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/silverpop_export/tests/test_update.py 
b/silverpop_export/tests/test_update.py
index 4c71249..122cf0e 100644
--- a/silverpop_export/tests/test_update.py
+++ b/silverpop_export/tests/test_update.py
@@ -1,3 +1,5 @@
+import datetime
+from decimal import Decimal
 import mock
 import MySQLdb
 import os
@@ -61,6 +63,31 @@
     cursor.execute("select count(*) from silverpop_export")
     assert cursor.fetchone() == (1,)
 
+def test_refund_history():
+    '''
+    Test that we don't include refunded donations in a donor's history
+    '''
+
+    run_update_with_fixtures(fixture_queries=["""
+    insert into civicrm_email (contact_id, email, is_primary, on_hold) values
+        (1, 'person1@localhost', 1, 0);
+    """, """
+    insert into civicrm_contact (id) values
+        (1);
+    """, """
+    insert into civicrm_contribution (id, contact_id, receive_date, 
total_amount, trxn_id, contribution_status_id) values
+        (1, 1, '2015-01-03', 15.25, 'xyz123', 1),
+        (2, 1, '2016-05-05', 25.25, 'abc456', 9);
+    """, """
+    insert into wmf_contribution_extra (entity_id, original_amount, 
original_currency) values
+        (1, 20.15, 'CAD'),
+        (2, 35.15, 'CAD');
+    """])
+
+    cursor = conn.db_conn.cursor()
+    cursor.execute("select highest_usd_amount, lifetime_usd_total, 
donation_count, latest_currency, latest_native_amount, latest_usd_amount, 
latest_donation  from silverpop_export")
+    expected = (Decimal('15.25'), Decimal('15.25'), 1, 'CAD', 
Decimal('20.15'), Decimal('15.25'), datetime.datetime(2015, 1, 3))
+    assert cursor.fetchone() == expected
 
 def run_update_with_fixtures(fixture_path=None, fixture_queries=None):
     with mock.patch("database.db.Connection") as MockConnection:
diff --git a/silverpop_export/update_table.sql 
b/silverpop_export/update_table.sql
index eed1b26..a306bdc 100755
--- a/silverpop_export/update_table.sql
+++ b/silverpop_export/update_table.sql
@@ -189,7 +189,9 @@
   FROM civicrm.civicrm_email e FORCE INDEX(UI_email)
   JOIN silverpop_export_staging ex ON e.email=ex.email
   JOIN civicrm.civicrm_contribution ct ON e.contact_id=ct.contact_id
-  WHERE ct.total_amount IS NOT NULL
+  WHERE ct.receive_date IS NOT NULL AND
+    ct.total_amount > 0 AND -- Refunds don't count
+    ct.contribution_status_id = 1 -- Only completed status
   GROUP BY e.email;
 
 -- (10 minutes)

-- 
To view, visit https://gerrit.wikimedia.org/r/316716
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If78471c395110016c0d95a2094cbb7b32d6c032f
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/tools
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>
Gerrit-Reviewer: Awight <awi...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to