summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchristopherlam <christopher.lck@gmail.com>2017-02-04 23:15:53 +0800
committerGitHub <noreply@github.com>2017-02-04 23:15:53 +0800
commit1aa49402b3d81a2ab6ad978f37abf13998ff33d6 (patch)
tree4859ee3aa23e54cdfe948a1a0179d85f767167b1
parent0527c727c0c5bbd73f3f5940780522ab87e74c1b (diff)
Update gnucashxml.py to improve compatibility with python3 (#1)
* Update gnucashxml.py * Add support for 'double' slot type * Improve __repr__ to be more descriptive Improve Account, Slot, Split repr to become more descriptive Add fullname() support for account names (eg Expenses:Business:Capital)
-rw-r--r--gnucashxml.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/gnucashxml.py b/gnucashxml.py
index 9014d29..0d51300 100644
--- a/gnucashxml.py
+++ b/gnucashxml.py
@@ -88,8 +88,18 @@ class Account(object):
self.splits = []
self.slots = slots or {}
+ def fullname(self):
+ if self.parent:
+ pfn = self.parent.fullname()
+ if pfn:
+ return '{}:{}'.format(pfn, self.name)
+ else:
+ return self.name
+ else:
+ return ''
+
def __repr__(self):
- return "<Account {}>".format(self.guid)
+ return "<Account '{}' {}...>".format(self.name, self.guid[:10])
def walk(self):
"""
@@ -137,7 +147,7 @@ class Transaction(object):
self.slots = slots or {}
def __repr__(self):
- return u"<Transaction {}>".format(self.guid)
+ return "<Transaction on {} '{}' {}...>".format(self.date, self.description, self.guid[:6])
def __lt__(self, other):
# For sorted() only
@@ -167,7 +177,11 @@ class Split(object):
self.slots = slots
def __repr__(self):
- return "<Split {}>".format(self.guid)
+ return "<Split {} '{}' {} {} {}...>".format(self.transaction.date,
+ self.transaction.description,
+ self.transaction.currency,
+ self.value,
+ self.guid[:6])
def __lt__(self, other):
# For sorted() only
@@ -237,7 +251,7 @@ def _book_from_tree(tree):
root_account = acc
accountdict[acc.guid] = acc
parentdict[acc.guid] = parent_guid
- for acc in accountdict.values():
+ for acc in list(accountdict.values()):
if acc.parent is None and acc.actype != 'ROOT':
parent = accountdict[parentdict[acc.guid]]
acc.parent = parent
@@ -411,8 +425,8 @@ def _slots_from_tree(tree):
key = elt.find(slot + "key").text
value = elt.find(slot + "value")
type_ = value.get('type', 'string')
- if type_ == 'integer':
- slots[key] = long(value.text)
+ if type_ in ('integer', 'double'):
+ slots[key] = int(value.text)
elif type_ == 'numeric':
slots[key] = _parse_number(value.text)
elif type_ in ('string', 'guid'):