From 0f7a154ff4ebe6a1d6b8dfbfcaed03e7af8f98f3 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 18 Jun 2020 10:07:10 -0400 Subject: [PATCH] reports: Balance cells try to retain currency on zero balance. --- conservancy_beancount/reports/core.py | 6 ++++-- tests/test_reports_ledger.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/conservancy_beancount/reports/core.py b/conservancy_beancount/reports/core.py index a55d447..1154b4c 100644 --- a/conservancy_beancount/reports/core.py +++ b/conservancy_beancount/reports/core.py @@ -923,9 +923,11 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta): return row def balance_cell(self, balance: Balance, **attrs: Any) -> odf.table.TableCell: - if balance.is_zero(): + balance = balance.clean_copy() or balance + balance_currency_count = len(balance) + if balance_currency_count == 0: return self.float_cell(0, **attrs) - elif len(balance) == 1: + elif balance_currency_count == 1: amount = next(iter(balance.values())) attrs['stylename'] = self.merge_styles( attrs.get('stylename'), self.currency_style(amount.currency), diff --git a/tests/test_reports_ledger.py b/tests/test_reports_ledger.py index db65abd..5b2546f 100644 --- a/tests/test_reports_ledger.py +++ b/tests/test_reports_ledger.py @@ -128,7 +128,7 @@ class ExpectedPostings(core.RelatedPostings): assert next(cells).value == norm_func(expected.at_cost().number) closing_row = testutil.ODSCell.from_row(next(rows)) assert closing_row[0].value == end_date - assert closing_row[4].text == closing_bal.format(None, empty='0', sep='\0') + assert closing_row[4].text == closing_bal.format(None, empty='$0.00', sep='\0') def get_sheet_names(ods):