Skip to content

Commit

Permalink
Update import scripts again
Browse files Browse the repository at this point in the history
  • Loading branch information
mayhem committed Jul 2, 2024
1 parent 6b1532b commit 8e6d98b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
30 changes: 15 additions & 15 deletions misc/parse-paypal-us.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
for line in reader:

# Filter out lines that complicate everything
if line[4] == "General Card Deposit":
if line[4] in ("General Card Deposit", "Account Hold for Open Authorization", "Reversal of General Account Hold"):
continue

if line[5] != 'Completed':
continue

lines.append(line)
Expand All @@ -64,14 +67,6 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
status = fields[5]
typ = fields[4]

if status != 'Completed':
index += 1
continue

if typ in ["Account Hold for Open Authorization", "Reversal of General Account Hold"]:
index += 1
continue

currency = fields[6]
if currency == 'USD' and typ != "General Currency Conversion":
# Normal native currency transactions
Expand All @@ -80,20 +75,25 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):
elif currency != 'USD':
print("transaction foreign")
# Received money in foreign currency
foreign = float(lines[index + 2][7].replace(",", ""))
native = float(lines[index + 1][7].replace(",", ""))
print(lines[index + 1])
print(lines[index + 2])
foreign = Decimal(lines[index + 2][7].replace(",", "")).copy_abs()
native = Decimal(lines[index + 1][7].replace(",", "")).copy_abs()


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
fee = Decimal(fee) / ratio
fee = Decimal(int(fee * 100)) / 100
net = native - fee

amount = native
print("amount %f fee: %f" % (amount, fee))
if typ == "Express Checkout Payment":
amount = -amount
print("amount %f fee: %f\n" % (amount, fee))

index += 2

Expand All @@ -106,7 +106,7 @@ def unicode_csv_reader(utf8_data, dialect=csv.excel, **kwargs):

desc = "PayPal Fee"
dat = fields[0]
if fee and float(fee) != 0.0:
if fee and Decimal(fee) != 0.0:
out.writerow([dat, desc, fee])

index += 1
Expand Down
13 changes: 5 additions & 8 deletions misc/parse-stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from decimal import Decimal
import csv

def toFloat(svalue):
return float(svalue.replace(",", ""))

if len(sys.argv) < 4:
print("Usage parse-stripe.py <stripe csv file> <qbo csv file> [beginning balance]")
sys.exit(-1)
Expand Down Expand Up @@ -62,12 +59,12 @@ def toFloat(svalue):
date = parser.parse(row[1] + " UTC")
date = "%s/%s/%s" % (date.month, date.day, date.year)
gross = Decimal(row[2])
fee = Decimal(row[10])
sender = row[20]
memo = row[9]
fee = Decimal(row[11])
sender = row[22]
memo = row[10]

if row[79] != "":
sender += " (inv #%s)" % row[79]
if row[84] != "":
sender += " (inv #%s)" % row[84]

out.writerow([date, "Stripe fee", "-" + str(fee)])
out.writerow([date, sender, str(gross)])
Expand Down

0 comments on commit 8e6d98b

Please sign in to comment.