-
Notifications
You must be signed in to change notification settings - Fork 1
/
entryt.py
129 lines (102 loc) · 3.47 KB
/
entryt.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import amountt
import datet
# An enum for the entry elements
TID = 0
TYPE = 1
NUMBER = 2
NAME = 3
DATE = 4
DEBIT = 5
CREDIT = 6
COMMENTS = 7
DETAIL = 8
POSTED = 9
# Enum elements
ELEMENTS = [TID, TYPE, NUMBER, NAME, DATE, DEBIT, CREDIT,
COMMENTS, DETAIL, POSTED]
# The transaction types
BILL = "BILL"
DONA = "DONA"
INCM = "INCM"
JRNL = "JRNL"
PYMT = "PYMT"
TYPES = [BILL, DONA, INCM, JRNL, PYMT]
################################################################
class Entry(object):
def __init__(self, line, element_to_column):
self.elements = []
for element in ELEMENTS:
column = element_to_column[element]
value = None if column is None else line[column]
self.elements.append(value)
self.elements[DEBIT] = amountt.from_string(self.elements[DEBIT])
self.elements[CREDIT] = amountt.from_string(self.elements[CREDIT])
self.elements[DATE] = datet.from_string(self.elements[DATE])
self.elements[POSTED] = datet.from_string(self.elements[POSTED])
if self.elements[NUMBER] == '-A/P Vendor-':
self.elements[NUMBER] = self.elements[NAME]
################################################################
def id(self):
# pylint: disable=invalid-name
return self.elements[TID]
def type(self):
return self.elements[TYPE]
def date(self):
return self.elements[DATE]
def posted(self):
return self.elements[POSTED]
def number(self):
return self.elements[NUMBER]
def name(self):
return self.elements[NAME]
def comment(self):
return self.elements[COMMENTS]
def debit(self):
return self.elements[DEBIT]
def credit(self):
return self.elements[CREDIT]
################################################################
def type_is(self, values):
return self.type() in values
def number_is(self, numbers):
return self.number() in numbers
def date_is(self, low=None, high=None):
val = self.date()
if val is None:
return False
low_match = low is None or low <= val
high_match = high is None or val <= high
return low_match and high_match
def posted_is(self, low=None, high=None):
val = self.posted()
if val is None:
return False
low_match = low is None or low <= val
high_match = high is None or val <= high
return low_match and high_match
def debit_is(self, low=None, high=None):
val = self.debit()
if val is None:
return False
low_match = low is None or low <= val
high_match = high is None or val <= high
return low_match and high_match
def credit_is(self, low=None, high=None):
val = self.credit()
if val is None:
return False
low_match = low is None or low <= val
high_match = high is None or val <= high
return low_match and high_match
def amount_is(self, low=None, high=None):
return self.debit_is(low, high) or self.credit_is(low, high)
################################################################
def dump(self):
elt = self.elements
elt[DEBIT] = amountt.to_string(elt[DEBIT])
elt[CREDIT] = amountt.to_string(elt[CREDIT])
elt[DATE] = datet.to_string(elt[DATE])
elt[POSTED] = datet.to_string(elt[POSTED])
return elt
def string(self):
return "{}".format(self.elements)