-
Notifications
You must be signed in to change notification settings - Fork 0
/
zonda_tax_calculator_PL.py
49 lines (39 loc) · 1.73 KB
/
zonda_tax_calculator_PL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Parse transaction logs from Zonda exchange (CSV format) and calculate values needed for PIT-38.
"""
import csv
import argparse
import locale
from decimal import *
INCOME_TYPE='Otrzymanie środków z transakcji na rachunek'
EXPENSE_TYPE='Pobranie środków z transakcji z rachunku'
CURRENCY='PLN'
def zonda_calculate_tax():
decimal_context = getcontext()
decimal_context.traps[FloatOperation] = True
parser = argparse.ArgumentParser()
parser.add_argument('--csv', type=str, action='append', required=True)
args = parser.parse_args()
income = Decimal()
expense = Decimal()
for csv_file_name in args.csv:
with open(csv_file_name, newline='', encoding='utf-8') as csvfile:
reader = csv.reader(csvfile, delimiter=';', quotechar='"')
# Skip first line
next(reader)
for row in reader:
transaction_type = str(row[1])
# TODO better way to handle comma
transaction_amount = Decimal(row[2].replace(",", "."))
transaction_currency = str(row[3])
if transaction_type.startswith(INCOME_TYPE) and transaction_currency == CURRENCY:
assert(transaction_amount > 0)
print(f"Found income with amount {transaction_amount}")
income = income + transaction_amount
elif transaction_type.startswith(EXPENSE_TYPE) and transaction_currency == CURRENCY:
assert(transaction_amount < 0)
print(f"Found expense with amount {transaction_amount}")
expense = expense + transaction_amount
print(f"Income/przychód: { income }")
print(f"Koszt/expense: { expense }")
zonda_calculate_tax()