Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions beanquery/query_execute_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,34 @@ def test_aggregated_group_by_invisible_order_by_aggregate_invisible(self):
(2,),
])

def test_aggregated_group_by_links(self):
self.check_query(
"""
2010-02-21 * "doctor" "appointment" ^2010-reimbursement-doc1
Assets:Bank:Checking -1000.00 USD
Assets:AccountsReceivable:Pending 1000.00 USD

2010-02-22 * "insurance" "partial reimbursement" ^2010-reimbursement-doc1
Assets:Bank:Checking 100.00 USD
Assets:AccountsReceivable:Pending -100.00 USD
""",
"""
SELECT FIRST(date) as date, FIRST(payee) AS payee, FIRST(narration) AS narration, links, SUM(position) AS balance
WHERE account ~ 'Assets:AccountsReceivable:Pending'
GROUP BY links
ORDER BY balance DESC
""",
[
('date', datetime.date),
('payee', str),
('narration', str),
('links', frozenset),
('balance', inventory.Inventory),
],
[
(datetime.date(2010, 2, 21), 'doctor', 'appointment', {'2010-reimbursement-doc1'}, I('900.00 USD')),
])

def test_aggregated_group_by_with_having(self):
self.check_query(
"""
Expand Down
4 changes: 4 additions & 0 deletions beanquery/query_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def format(self, value):
return self.sep.join(str(x) for x in sorted(value))


class FrozensetRenderer(SetRenderer):
dtype = frozenset


class DateRenderer(ColumnRenderer):
dtype = datetime.date

Expand Down
7 changes: 7 additions & 0 deletions beanquery/query_render_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def test_set_str(self):
'bb ccc',
])

def test_frozenset_str(self):
self.assertEqual(self.render(frozenset, [frozenset({}), frozenset({'aaaa'}), frozenset({'bb', 'ccc'})]), [
' ',
'aaaa ',
'bb ccc',
])

def test_date(self):
self.assertEqual(self.render(datetime.date, [datetime.date(2014, 10, 3)]), [
'2014-10-03'
Expand Down
8 changes: 4 additions & 4 deletions beanquery/sources/beancount.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ def description(entry):
return None
return ' | '.join(filter(None, [entry.payee, entry.narration]))

@columns.register(set)
@columns.register(frozenset)
def tags(entry):
"""The set of tags of the transaction."""
return getattr(entry, 'tags', None)

@columns.register(set)
@columns.register(frozenset)
def links(entry):
"""The set of links of the transaction."""
return getattr(entry, 'links', None)
Expand Down Expand Up @@ -493,12 +493,12 @@ def description(context):
"""A combination of the payee + narration for the transaction of this posting."""
return ' | '.join(filter(None, [context.entry.payee, context.entry.narration]))

@columns.register(set)
@columns.register(frozenset)
def tags(context):
"""The set of tags of the parent transaction for this posting."""
return context.entry.tags

@columns.register(set)
@columns.register(frozenset)
def links(context):
"""The set of links of the parent transaction for this posting."""
return context.entry.links
Expand Down