jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/381351 )
Change subject: Add lastet_currency_symbol to export ...................................................................... Add lastet_currency_symbol to export Bug: T156410 Change-Id: I697e07d2d36184c976f43037d664c03c2bc45262 --- M silverpop_export/tests/minimal_schema.sql M silverpop_export/tests/test_update.py M silverpop_export/update_table.sql 3 files changed, 63 insertions(+), 10 deletions(-) Approvals: XenoRyet: Looks good to me, approved jenkins-bot: Verified diff --git a/silverpop_export/tests/minimal_schema.sql b/silverpop_export/tests/minimal_schema.sql index c2e35a4..8d904bf 100644 --- a/silverpop_export/tests/minimal_schema.sql +++ b/silverpop_export/tests/minimal_schema.sql @@ -26,6 +26,20 @@ is_deleted tinyint(4) default '0' ); +drop table if exists civicrm_currency; +create table civicrm_currency ( + id int(10) unsigned auto_increment primary key, + name varchar(64) COLLATE utf8_unicode_ci, + symbol varchar(8) COLLATE utf8_unicode_ci, + key UI_name (name) +); +insert into civicrm_currency (name, symbol) +values + ('USD', '$'), + ('CAD', '$'), + ('GBP', '£'), + ('DZD', NULL); + drop table if exists wmf_donor; create table wmf_donor ( id int(10) unsigned, diff --git a/silverpop_export/tests/test_update.py b/silverpop_export/tests/test_update.py index 8d951a7..d9f9c19 100644 --- a/silverpop_export/tests/test_update.py +++ b/silverpop_export/tests/test_update.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import datetime from decimal import Decimal import mock @@ -26,7 +27,7 @@ db_name = "test" db_user = "test" - db_params = {"user": db_user, "host": db_host} + db_params = {"user": db_user, "host": db_host, "charset": "utf8"} if db_pass: db_params['passwd'] = db_pass @@ -219,6 +220,36 @@ assert actual == expected +def test_currency_symbol(): + ''' + Test that we correctly pull in the currency symbol for the latest donation + ''' + + 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', 9.50, 'xyz123', 1), + (2, 1, '2017-07-07', 10.95, 'nnn777', 1), + (3, 1, '2016-05-05', 10.00, 'abc456', 1); + """, """ + insert into wmf_contribution_extra (entity_id, original_amount, original_currency) values + (1, 1000, 'JPY'), + (2, 9.00, 'GBP'), + (3, 10.00, 'USD'); + """]) + + cursor = conn.db_conn.cursor() + cursor.execute("select latest_currency, latest_currency_symbol from silverpop_export") + expected = ('GBP', u'£') + actual = cursor.fetchone() + assert actual == 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 9ae49bd..61e5ca5 100755 --- a/silverpop_export/update_table.sql +++ b/silverpop_export/update_table.sql @@ -35,6 +35,7 @@ -- Latest contribution statistics latest_currency varchar(3) not null default '', + latest_currency_symbol varchar(8) not null default '', latest_native_amount decimal(20,2) not null default 0, latest_usd_amount decimal(20,2) not null default 0, latest_donation datetime null, @@ -57,6 +58,7 @@ CREATE TABLE IF NOT EXISTS silverpop_export_latest( email varchar(255) PRIMARY KEY, latest_currency varchar(3), + latest_currency_symbol varchar(8), latest_native_amount decimal(20,2), latest_usd_amount decimal(20,2), latest_donation datetime @@ -91,16 +93,19 @@ SELECT e.email, ex.original_currency, + COALESCE(cur.symbol, ex.original_currency), ex.original_amount, ct.total_amount, ct.receive_date FROM - silverpop_export_staging e, - civicrm.civicrm_contribution ct, - civicrm.wmf_contribution_extra ex + silverpop_export_staging e + INNER JOIN civicrm.civicrm_contribution ct + ON ct.contact_id = e.contact_id + INNER JOIN civicrm.wmf_contribution_extra ex + ON ex.entity_id = ct.id + LEFT JOIN civicrm.civicrm_currency cur + ON cur.name = ex.original_currency WHERE - e.contact_id = ct.contact_id AND - ex.entity_id = ct.id AND ct.receive_date IS NOT NULL AND ct.total_amount > 0 AND -- Refunds don't count ct.contribution_status_id = 1 -- 'Completed' @@ -269,6 +274,7 @@ ex.has_recurred_donation = exs.has_recurred_donation, ex.first_donation_date = exs.first_donation_date, ex.latest_currency = lt.latest_currency, + ex.latest_currency_symbol = lt.latest_currency_symbol, ex.latest_native_amount = lt.latest_native_amount, ex.latest_usd_amount = lt.latest_usd_amount, ex.latest_donation = lt.latest_donation, @@ -356,6 +362,7 @@ -- Latest contribution statistics latest_currency varchar(3), + latest_currency_symbol varchar(8), latest_native_amount decimal(20,2), latest_usd_amount decimal(20,2), latest_donation datetime, @@ -382,13 +389,13 @@ id,contact_id,first_name,last_name,preferred_language,email, has_recurred_donation,highest_usd_amount,highest_native_amount, highest_native_currency,highest_donation_date,lifetime_usd_total,donation_count, - latest_currency,latest_native_amount,latest_usd_amount,latest_donation, - first_donation_date,city,country,state,postal_code,timezone ) + latest_currency,latest_currency_symbol,latest_native_amount,latest_usd_amount, + latest_donation, first_donation_date,city,country,state,postal_code,timezone ) SELECT id,contact_id,first_name,last_name,preferred_language,email, has_recurred_donation,highest_usd_amount,highest_native_amount, highest_native_currency,highest_donation_date,lifetime_usd_total,donation_count, - latest_currency,latest_native_amount,latest_usd_amount,latest_donation, - first_donation_date,city,country,state,postal_code,timezone + latest_currency,latest_currency_symbol,latest_native_amount,latest_usd_amount, + latest_donation,first_donation_date,city,country,state,postal_code,timezone FROM silverpop_export_staging WHERE opted_out=0; @@ -413,6 +420,7 @@ IFNULL(DATE_FORMAT(latest_donation, '%m/%d/%Y'), '') latest_donation_date, latest_usd_amount, latest_currency, + latest_currency_symbol, latest_native_amount, donation_count, IFNULL(DATE_FORMAT(first_donation_date, '%m/%d/%Y'), '') first_donation_date -- To view, visit https://gerrit.wikimedia.org/r/381351 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I697e07d2d36184c976f43037d664c03c2bc45262 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/tools Gerrit-Branch: master Gerrit-Owner: Ejegg <ej...@ejegg.com> 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