-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransaction.py
70 lines (60 loc) · 2.41 KB
/
transaction.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from datetime import datetime
from typing import List
import categories
class Transaction:
"""Transactions are single entries in my credit/debit account
Not all fields are currently used. However, it's easier to add that info
now and future proof for later, so here we go.
Fields:
date: datestamp of transaction
vendor: what vendor issued the transaction
amount: transaction amount
debit: True if debit else False [credit]
category: transaction category [usually Mint generated]
label: transaction label [usually Mint generated]
source: where did this expenditure come from in my budget
"""
def __init__(self,
date: datetime = None,
amount: float = None,
debit: bool = None,
vendor: str = None,
input_category: str = None,
account: str = None,
label: str = None,
source: 'Transaction' = None):
self.date = date
self.vendor = vendor
self.amount = amount
self.debit = debit
self.input_category = input_category
self.category, self.sub_category = categories.get_categories(input_category)
self.account = account
self.label = label
self.source = source
def __str__(self):
return f"<Transaction {self.vendor} {self.amount} {self.category} {self.sub_category} {self.input_category}>"
def load_from_csv(self, data: List):
"""Store a csv-row of data in the object
Args:
data: list form of a transaction csv row
"""
self.date = datetime.strptime(data[0], "%m/%d/%Y")
self.vendor = data[1]
self.amount = int(float(data[3]))
self.debit = True if data[4] == 'debit' else False
self.input_category = data[5]
self.account = data[6]
self.label = data[7]
if 'GUSTO' in self.vendor:
self.input_category = 'Paycheck'
self.category, self.sub_category = categories.get_categories(self.input_category)
def make_sakey_string(self) -> str:
"""Create a string with the relevant SakeyMatic formatting
The format is:
{Source} [{Amount}] {Type}
"""
if self.source:
return f"{self.source.category} [{self.amount}] {self.category}"
else:
return f"NULL [{self.amount}] {self.category}"