Beispiel #1
0
 def hierarchy(self, account_name, begin=None, end=None):
     """An account tree."""
     if begin:
         tree = Tree(iter_entry_dates(self.ledger.entries, begin, end))
     else:
         tree = self.ledger.root_tree
     return _serialize_account_node(tree.get(account_name), end)
Beispiel #2
0
 def hierarchy(self, account_name, begin=None, end=None):
     """An account tree."""
     if begin:
         tree = Tree(iter_entry_dates(self.ledger.entries, begin, end))
     else:
         tree = self.ledger.root_tree
     return tree.get(account_name).serialise(end)
Beispiel #3
0
 def hierarchy(self, account_name, begin=None, end=None):
     """An account tree."""
     if begin:
         entries = iter_entry_dates(self.ledger.entries, begin, end)
         tree = Tree(entries)
     else:
         tree = self.ledger.root_tree
     return _serialize_account_node(tree.get(account_name), end)
Beispiel #4
0
 def hierarchy(
     self,
     account_name: str,
     begin: Optional[datetime.date] = None,
     end: Optional[datetime.date] = None,
 ):
     """An account tree."""
     if begin is not None:
         tree = Tree(iter_entry_dates(self.ledger.entries, begin, end))
     else:
         tree = self.ledger.root_tree
     return tree.get(account_name).serialise(end)
Beispiel #5
0
 def hierarchy(
     self,
     account_name: str,
     conversion: str,
     begin: Optional[date] = None,
     end: Optional[date] = None,
 ) -> SerialisedTreeNode:
     """An account tree."""
     if begin is not None and end is not None:
         tree = Tree(iter_entry_dates(self.ledger.entries, begin, end))
     else:
         tree = self.ledger.root_tree
     return tree.get(account_name).serialise(conversion, self.ledger,
                                             end - ONE_DAY if end else None)
Beispiel #6
0
 def hierarchy(
     self,
     filtered: FilteredLedger,
     account_name: str,
     conversion: str,
     begin: date | None = None,
     end: date | None = None,
 ) -> SerialisedTreeNode:
     """An account tree."""
     if begin is not None and end is not None:
         tree = Tree(iter_entry_dates(filtered.entries, begin, end))
     else:
         tree = filtered.root_tree
     return tree.get(account_name).serialise(conversion,
                                             self.ledger.price_map,
                                             end - ONE_DAY if end else None)
Beispiel #7
0
def test_tree():
    tree = Tree()
    assert len(tree) == 1
    tree.get('account:name:a:b:c')
    assert len(tree) == 1
    node = tree.get('account:name:a:b:c', insert=True)
    assert len(tree) == 6
    tree.get('account:name', insert=True)
    assert len(tree) == 6
    assert node is tree.get('account:name:a:b:c', insert=True)

    assert list(tree.ancestors('account:name:a:b:c')) == [
        tree.get('account:name:a:b'),
        tree.get('account:name:a'),
        tree.get('account:name'),
        tree.get('account'),
        tree.get(''),
    ]

    assert len(list(tree.ancestors('not:account:name:a:b:c'))) == 6
Beispiel #8
0
def test_tree():
    tree = Tree()
    assert len(tree) == 1
    tree.get("account:name:a:b:c")
    assert len(tree) == 1
    node = tree.get("account:name:a:b:c", insert=True)
    assert len(tree) == 6
    tree.get("account:name", insert=True)
    assert len(tree) == 6
    assert node is tree.get("account:name:a:b:c", insert=True)

    assert list(tree.ancestors("account:name:a:b:c")) == [
        tree.get("account:name:a:b"),
        tree.get("account:name:a"),
        tree.get("account:name"),
        tree.get("account"),
        tree.get(""),
    ]

    assert len(list(tree.ancestors("not:account:name:a:b:c"))) == 6