Changeset - 0f7a154ff4eb
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-06-18 14:07:10
brettcsmith@brettcsmith.org
reports: Balance cells try to retain currency on zero balance.
2 files changed with 5 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/core.py
Show inline comments
...
 
@@ -914,27 +914,29 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta):
 
            setattr(self, f'style_{textalign}text', aligned_style)
 

	
 
    ### Rows and cells
 

	
 
    def add_row(self, *cells: odf.table.TableCell, **attrs: Any) -> odf.table.TableRow:
 
        row = odf.table.TableRow(**attrs)
 
        for cell in cells:
 
            row.addElement(cell)
 
        self.sheet.addElement(row)
 
        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),
 
            )
 
            return self.currency_cell(amount, **attrs)
 
        else:
 
            lines = [babel.numbers.format_currency(
 
                number, currency, locale=self.locale, format_type=self.currency_fmt_key,
 
            ) for number, currency in balance.values()]
 
            attrs['stylename'] = self.merge_styles(
 
                attrs.get('stylename'), self.style_endtext,
 
            )
tests/test_reports_ledger.py
Show inline comments
...
 
@@ -119,25 +119,25 @@ class ExpectedPostings(core.RelatedPostings):
 
            cells = iter(testutil.ODSCell.from_row(next(rows)))
 
            assert next(cells).value == expected.meta.date
 
            assert next(cells).text == (expected.meta.get('entity') or '')
 
            assert next(cells).text == (expected.meta.txn.narration or '')
 
            if expected.cost is None:
 
                assert not next(cells).text
 
                assert next(cells).value == norm_func(expected.units.number)
 
            else:
 
                assert next(cells).value == norm_func(expected.units.number)
 
                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):
 
    return [sheet.getAttribute('name').replace(' ', ':')
 
            for sheet in ods.getElementsByType(odf.table.Table)]
 

	
 
def check_oversize_logs(caplog, accounts, sheet_size):
 
    actual = {}
 
    for log in caplog.records:
 
        match = OVERSIZE_RE.match(log.message)
 
        if match:
 
            assert int(match.group(3).replace(',', '')) == sheet_size
0 comments (0 inline, 0 general)