-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchartt.py
80 lines (58 loc) · 2.34 KB
/
chartt.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
#!/usr/bin/env python
# pylint: disable=missing-docstring
# Unlike other data dumped from Church Windows, we assume a fixed layout
# to the chart of accounts since Church Windows gives no option to change
# the layout of the chart of accounts.
import json
import accountt
################################################################
class Chart(object):
# pylint: disable=too-many-public-methods
def __init__(self, chart=None):
# map account number to account description
self.chart_ = {}
# map account name to account number
self.number_ = {}
self.vendor_name_ = None
self.vendor_number_ = None
if chart is not None:
with open(chart) as handle:
coa = json.load(handle)
self.chart_ = coa['account']
self.number_ = coa['number']
self.vendor_name_ = coa['vendor name']
self.vendor_number_ = coa['vendor number']
for number in self.chart_:
self.chart_[number] = accountt.Account(self.chart_[number])
def accounts(self):
return self.chart_.keys()
def account(self, number):
return self.chart_[number]
def number(self, name):
return self.number_[name]
def vendor_name(self):
return self.vendor_name_
def vendor_number(self):
return self.vendor_number_
################################################################
def account_dictionary(self):
dictionary = {}
for number in self.accounts():
dictionary[number] = self.account(number).dictionary()
return dictionary
def account_string(self):
return json.dumps(self.account_dictionary(), indent=2, sort_keys=True)
def number_dictionary(self):
return self.number_
def number_string(self):
return json.dumps(self.number_dictionary(), indent=2, sort_keys=True)
def dictionary(self):
dictionary = {'account': self.account_dictionary(),
'number': self.number_dictionary(),
'vendor name': self.vendor_name_,
'vendor number': self.vendor_number_
}
return dictionary
def string(self):
return json.dumps(self.dictionary(), indent=2, sort_keys=True)
################################################################