-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.py
47 lines (40 loc) · 1.52 KB
/
Account.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
from Utils import *
class Account:
def __init__(self, name, guid, commodity, description, parent):
self.name = name
self.guid = guid
self.commodity = commodity
self.description = description
self.parent = parent
self.fullname = None
def display(self):
tree_print("Account", self, 0)
# Create an Account object from an XML account tag
def parse_account(xml_account):
return Account(safety_text(xml_account.find('act:name', ns)),
safety_text(xml_account.find('act:id', ns)),
safety_text(xml_account.find('act:commodity/cmdty:id', ns)),
safety_text(xml_account.find('act:description', ns)),
safety_text(xml_account.find('act:parent', ns)))
# Given the guid and a list of accounts return the account that matches the guid or None if no account is found
def lookup_account(guid, accounts):
for account in accounts:
if account.guid == guid:
return account
return None
# Recursively build a full name for the account using the name of its parent
def get_fullname(account, accounts):
if account.parent is None:
return None
else:
parent_account = lookup_account(account.parent, accounts)
# Check to see if parent already has a fullname and simply append to that
if parent_account.fullname is None:
parent_fullname = get_fullname(parent_account, accounts)
# If the parent's fullname is None, then the parent is the root account
if parent_fullname is None:
return account.name
else:
return (parent_fullname + ":" + account.name)
else:
return (parent_account.fullname + ":" + account.name)