-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Brought the paypal script up to date again
- Loading branch information
Showing
1 changed file
with
15 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,6 @@ | |
import csv | ||
from decimal import Decimal, InvalidOperation | ||
|
||
# header | ||
|
||
# "Date","Time","TimeZone","Name","Type","Status","Currency","Gross","Fee","Net","From Email Address","To Email Address","Transaction ID","Shipping Address","Address Status","Item Title","Item ID","Shipping and Handling Amount","Insurance Amount","Sales Tax","Option 1 Name","Option 1 Value","Option 2 Name","Option 2 Value","Reference Txn ID","Invoice Number","Custom Number","Quantity","Receipt ID","Balance","Address Line 1","Address Line 2/District/Neighborhood","Town/City","State/Province/Region/County/Territory/Prefecture/Republic","Zip/Postal Code","Country","Contact Phone Number","Subject","Note","Country Code","Balance Impact" | ||
|
||
# conversion line | ||
# "12/31/2017","14:50:41","PST","Mathias Kunter","General Payment","Completed","EUR","200.00","-7.75","192.25","[email protected]","[email protected]","3LW066840A4238521","Mathias, Kunter","Non-Confirmed","","","","","","","","","","","","","","","192.25","","","","","","","","","Magic MP3 Tagger November","","Credit" | ||
|
||
def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs): | ||
csv_reader = csv.reader(utf8_data, dialect=dialect, **kwargs) | ||
for row in csv_reader: | ||
|
@@ -48,6 +41,11 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs): | |
lines = [] | ||
reader = unicode_csv_reader(fp) | ||
for line in reader: | ||
|
||
# Filter out lines that complicate everything | ||
if line[4] == "General Card Deposit": | ||
continue | ||
|
||
lines.append(line) | ||
|
||
index = 1 | ||
|
@@ -80,51 +78,31 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs): | |
amount = gross | ||
|
||
elif currency != 'USD': | ||
print("transaction foreign") | ||
# Received money in foreign currency | ||
native = float(lines[index + 2][7].replace(",", "")) | ||
foreign = -float(lines[index + 1][7].replace(",", "")) | ||
|
||
#print "native %f, foreign %f" % (native, foreign) | ||
|
||
ratio = native / foreign | ||
#print "conversion rate: %f" % ratio | ||
|
||
fee = float(fee) * ratio | ||
fee = float(int(fee * 100)) / 100 | ||
|
||
amount = native - fee | ||
#print "amount %f fee: %f" % (amount, fee) | ||
foreign = float(lines[index + 2][7].replace(",", "")) | ||
native = float(lines[index + 1][7].replace(",", "")) | ||
|
||
index += 2 | ||
elif typ == "General Currency Conversion": | ||
#print lines[index] | ||
#print lines[index + 1] | ||
#print lines[index + 2] | ||
|
||
native = float(lines[index][7].replace(",", "")) | ||
foreign = -float(lines[index + 1][7].replace(",", "")) | ||
desc = lines[index + 2][3] | ||
|
||
#print "native %f, foreign %f" % (native, foreign) | ||
print("native %f, foreign %f" % (native, foreign)) | ||
|
||
ratio = native / foreign | ||
#print "conversion rate: %f" % ratio | ||
print("conversion rate: %f" % ratio) | ||
|
||
fee = float(fee) * ratio | ||
fee = float(fee) / ratio | ||
fee = float(int(fee * 100)) / 100 | ||
net = native - fee | ||
|
||
amount = native - fee | ||
#print "amount %f fee: %f" % (amount, fee) | ||
amount = native | ||
print("amount %f fee: %f" % (amount, fee)) | ||
|
||
index += 2 | ||
|
||
|
||
desc = desc.replace(",", " ") | ||
out.writerow([dat, desc, amount]) | ||
|
||
if balance is not None: | ||
balance = balance + Decimal(str(net).replace(",", "")) | ||
register.append("%s %-40s %10s %10s" % (dat, desc, str(net), str(balance))) | ||
register.append("%s %-40s %10s %10s %10s" % (dat, desc, str(amount), str(fee), str(balance))) | ||
|
||
desc = "PayPal Fee" | ||
dat = fields[0] | ||
|