Skip to content

Commit a2dac9b

Browse files
committed
Handle rejected / reversed txn in ConCardis importer.
And have a test for it.
1 parent e2a28ad commit a2dac9b

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ check: $(OUTDIR)/gnucash.py test.py gnc-testdata.xml paypal.py bitpay.py concard
3333
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python paypal.py -v -p -s test_paypal_donation -s test_paypal_currency_conversion gnc-testdata.xml testfile.csv $(OUTDIR)/paypalout.xml
3434
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python paypal.py -v -p -s test_paypal_donation -s test_paypal_currency_conversion $(OUTDIR)/paypalout.xml testfile.csv $(OUTDIR)/paypalout2.xml
3535
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python bitpay.py -v -p $(OUTDIR)/paypalout2.xml bitpaytest.csv $(OUTDIR)/paypalout3.xml
36-
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python concardis.py -v -p $(OUTDIR)/paypalout3.xml concardistest.csv $(OUTDIR)/paypalout4.xml
36+
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python concardis.py -v -p -s test_concardis_donation $(OUTDIR)/paypalout3.xml concardistest.csv $(OUTDIR)/paypalout4.xml
3737
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python prune_txn.py -v -p -a PayPal -d 2012-12-01..2013-01-01 -m '.* - ID: (\w+) - .*' \
3838
-d 2010-01-01..2010-12-01 -m 'do_not_match' $(OUTDIR)/paypalout4.xml $(OUTDIR)/prunedout.xml
3939
PYTHONPATH=${PYXB_ROOT}:$(OUTDIR) python prune_txn.py -v -p -a PayPal -d 2012-01-01..2013-01-01 -m '.*Random Name 2.*' \

Diff for: concardis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def default_importer(createTransaction, account1_uuid, account2_uuid,
208208
transaction_ref = line["REF"]
209209
transaction_order_date = dateFromCSV(line["ORDER"])
210210
transaction_payment_date = dateFromCSV(line["PAYDATE"])
211-
transaction_status = line["LIB"]
211+
transaction_status = line["STATUS"]
212212

213213
# remove crap, encode into unicode
214214
transaction_name = re.sub(r"[\x01-\x1F\x7F]", "", line["NAME"])

Diff for: concardistest.csv

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Id;REF;ORDER;STATUS;LIB;ACCEPT;NCID;NCSTER;PAYDATE;CIE;NAME;COUNTRY;TOTAL;CUR;METHOD;BRAND;CARD;UID;STRUCT;FILEID;ACTION;TICKET;;DESC;
22
881031999/0;LIBODONATE-52acef2bb0000;10/10/2013;9;Zahlung beantragt;12456;1234567890;0/0;10/10/2013;;Random Name;;10.10;EUR;CreditCard;VISA;XXXXXXXXXXXX0000;1234567890;124567890;/;VEN;The Document Foundation 10/10/13 11:11 CONCARDIS - VISA XXXXXXXXXXXX0000 0120 - Authorization ==> Successful completion of a sale Ref : 1234567890 ACode : 0123456 Amount : EUR 10,00 STAN123456/AC0123456789;;Donation to The Document Foundation;
3+
881031999/1;LIBODONATE-52acef2bb0000;10/10/2013;7;Zahlung geloescht;;1234567890;0/0;10/10/2013;;Random Name;;10.10;EUR;CreditCard;VISA;XXXXXXXXXXXX0000;1234567890;124567890;/;ANV;The Document Foundation CRLF10/10/13 11:11 CONCARDIS - VISA XXXXXXXXXXXX0000 0120 - Reversal ==> Successful completion of a refund Ref : 1234567890 ACode : 0123456 Amount : EUR 10,00 STAN123456/AC0123456789;;Donation to The Document Foundation;
4+
881031777/0;LIBODONATE-52acef2bb1111;10/10/2013;9;Zahlung beantragt;12456;1234567890;0/0;10/10/2013;;Random Name;;10.10;EUR;CreditCard;VISA;XXXXXXXXXXXX0000;1234567890;124567890;/;VEN;The Document Foundation 10/10/13 11:11 CONCARDIS - VISA XXXXXXXXXXXX0000 0120 - Authorization ==> Successful completion of a sale Ref : 1234567890 ACode : 0123456 Amount : EUR 10,00 STAN123456/AC0123456789;;Donation to The Document Foundation;
5+
881031777/1;LIBODONATE-52acef2bb1111;10/10/2013;8;Gutschrift;;1234567890;0/0;10/10/2013;;Random Name;;10.10;EUR;CreditCard;VISA;XXXXXXXXXXXX0000;1234567890;124567890;/;RFS;The Document Foundation CRLF10/10/13 11:11 CONCARDIS - VISA XXXXXXXXXXXX0000 0120 - Reversal ==> Successful completion of a refund Ref : 1234567890 ACode : 0123456 Amount : EUR 10,00 STAN123456/AC0123456789;;Donation to The Document Foundation;

Diff for: test_concardis_donation.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This file is part of the TDF accounting framework.
2+
#
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
#
7+
8+
# string we act on
9+
desc_method_brand = 'Donation to The Document FoundationCreditCardVISA'
10+
11+
# debit account
12+
account1_name = 'Concardis'
13+
# credit account
14+
account2_name = 'Donations'
15+
16+
def importer(createTransaction, account1_uuid, account2_uuid, transaction_ref, transaction_order_date,
17+
transaction_payment_date, transaction_status, transaction_name, transaction_value, transaction_convertedvalue,
18+
transaction_currency, transaction_defaultcurrency, transaction_method, transaction_brand, transaction_comment,
19+
transaction_description):
20+
if transaction_status == '9':
21+
acc1 = account1_uuid
22+
acc2 = account2_uuid
23+
reversal_comment = ''
24+
elif transaction_status == '8':
25+
acc1 = account2_uuid
26+
acc2 = account1_uuid
27+
reversal_comment = ' reversal'
28+
elif transaction_status == '7':
29+
acc1 = account2_uuid
30+
acc2 = account1_uuid
31+
reversal_comment = ' rejected'
32+
else:
33+
raise RuntimeError('Unhandled transaction status: %s' % transaction_status)
34+
35+
return createTransaction(transaction_payment_date, acc1, transaction_comment,
36+
acc2, "",
37+
transaction_defaultcurrency, transaction_convertedvalue,
38+
"Concardis:Donations%s from %s by %s - %s %s" % (reversal_comment,
39+
transaction_name,
40+
transaction_method,
41+
transaction_currency,
42+
transaction_value))

Diff for: testfile.final

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ AccountUID Date Amount
1010
"71607cde73afae2edaf31c210731aaaa" "2013-10-11" "99.990000" "BitPay ACH/other from by - EUR -99.99"
1111
# Generated by export_csv.py out/prunedout2.xml 71607cde73afae2edaf31c210731bbbb
1212
AccountUID Date Amount
13-
"71607cde73afae2edaf31c210731bbbb" "2013-10-10" "-10.100000" "Concardis Donation to The Document Foundation from Random Name by CreditCard - EUR 10.1"
13+
"71607cde73afae2edaf31c210731bbbb" "2013-10-10" "-10.100000" "Concardis:Donations from Random Name by CreditCard - EUR 10.1"
14+
"71607cde73afae2edaf31c210731bbbb" "2013-10-10" "10.100000" "Concardis:Donations rejected from Random Name by CreditCard - EUR 10.1"
15+
"71607cde73afae2edaf31c210731bbbb" "2013-10-10" "-10.100000" "Concardis:Donations from Random Name by CreditCard - EUR 10.1"
16+
"71607cde73afae2edaf31c210731bbbb" "2013-10-10" "10.100000" "Concardis:Donations reversal from Random Name by CreditCard - EUR 10.1"

0 commit comments

Comments
 (0)