From 4f223642ed4b0139bd670e7fdc43a5d65f35209d 2020-08-22 16:33:06 From: Brett Smith Date: 2020-08-22 16:33:06 Subject: [PATCH] reports: Refactor total styles to BaseODS. --- diff --git a/conservancy_beancount/reports/balance_sheet.py b/conservancy_beancount/reports/balance_sheet.py index a6ef0f00155242d9e0e1f296a85597477c000e9f..b4598e3da0de14ec2f94d7d7bf31384c1aac91c0 100644 --- a/conservancy_beancount/reports/balance_sheet.py +++ b/conservancy_beancount/reports/balance_sheet.py @@ -248,12 +248,6 @@ class Report(core.BaseODS[Sequence[None], None]): self.style_header, self.border_style(core.Border.BOTTOM, '1pt'), ) - self.style_subtotline = self.border_style(core.Border.TOP, '1pt') - self.style_totline = self.border_style(core.Border.TOP | core.Border.BOTTOM, '1pt') - self.style_bottomline = self.merge_styles( - self.style_subtotline, - self.border_style(core.Border.BOTTOM, '2pt', 'double'), - ) def write_all(self) -> None: self.write_financial_position() @@ -387,7 +381,7 @@ class Report(core.BaseODS[Sequence[None], None]): liabilities = self.write_classifications_by_account('Liabilities', balance_kwargs) self.write_totals_row( - "Total Liabilities", liabilities, stylename=self.style_totline, + "Total Liabilities", liabilities, stylename=self.style_endtotal, ) self.add_row() self.add_row() @@ -403,7 +397,7 @@ class Report(core.BaseODS[Sequence[None], None]): row.addElement(self.balance_cell(balance)) total_bal += balance self.write_totals_row( - "Total Net Assets", equity_totals, stylename=self.style_subtotline, + "Total Net Assets", equity_totals, stylename=self.style_total, ) self.write_totals_row( "Total Liabilities and Net Assets", @@ -428,7 +422,7 @@ class Report(core.BaseODS[Sequence[None], None]): self.add_row(self.string_cell("Support and Revenue", stylename=self.style_bold)) self.add_row() income_totals = self.write_classifications_by_account('Income', bal_kwargs) - self.write_totals_row("", income_totals, stylename=self.style_subtotline) + self.write_totals_row("", income_totals, stylename=self.style_total) self.add_row() self.add_row( self.string_cell("Net Assets released from restrictions:"), @@ -445,7 +439,7 @@ class Report(core.BaseODS[Sequence[None], None]): self.write_totals_row( "Total Support and Revenue", income_totals, other_totals, - stylename=self.style_totline, + stylename=self.style_endtotal, ) period_expenses = core.MutableBalance() @@ -487,7 +481,7 @@ class Report(core.BaseODS[Sequence[None], None]): self.NO_BALANCE, period_bal, prior_bal, - ], stylename=self.style_totline, leading_rows=0) + ], stylename=self.style_endtotal, leading_rows=0) other_totals[0] -= period_bal other_totals[2] -= period_bal @@ -567,7 +561,7 @@ class Report(core.BaseODS[Sequence[None], None]): self.write_totals_row( "Net cash provided by operating activities", period_totals, - stylename=self.style_totline, + stylename=self.style_endtotal, ) self.write_totals_row("Net Increase in Cash", period_totals) begin_totals = [ diff --git a/conservancy_beancount/reports/core.py b/conservancy_beancount/reports/core.py index 578955da0f32592eda370558040215f706196931..21ed4fa3e578d54925fdbcf818652c484bf03042 100644 --- a/conservancy_beancount/reports/core.py +++ b/conservancy_beancount/reports/core.py @@ -1054,6 +1054,13 @@ class BaseODS(BaseSpreadsheet[RT, ST], metaclass=abc.ABCMeta): aligned_style.addElement(odf.style.ParagraphProperties(textalign=textalign)) setattr(self, f'style_{textalign}text', aligned_style) + self.style_total = self.border_style(Border.TOP, '1pt') + self.style_endtotal = self.border_style(Border.TOP | Border.BOTTOM, '1pt') + self.style_bottomline = self.merge_styles( + self.style_total, + self.border_style(Border.BOTTOM, '2pt', 'double'), + ) + ### Properties def set_common_properties(self, diff --git a/conservancy_beancount/reports/fund.py b/conservancy_beancount/reports/fund.py index b26a7a9d00a42ff36e0bc84add095e476363456b..1e09280db38a785357020998e5e660379244dcc5 100644 --- a/conservancy_beancount/reports/fund.py +++ b/conservancy_beancount/reports/fund.py @@ -168,10 +168,7 @@ class ODSReport(core.BaseODS[FundPosts, None]): self.write_balances(fund, balances) for total, bal in zip(totals, balances): total += bal - self.write_balances('', totals, self.merge_styles( - self.border_style(core.Border.TOP, '.75pt'), - self.border_style(core.Border.BOTTOM, '1.5pt', 'double'), - )) + self.write_balances('', totals, self.style_bottomline) self.document.spreadsheet.childNodes.reverse() self.sheet = start_sheet diff --git a/conservancy_beancount/reports/ledger.py b/conservancy_beancount/reports/ledger.py index 7df5ab63c0a3c9d785191ec936fb1f8d5614e8b0..7e15168975090c4f1e4fa0c2932ad9c3dfead33a 100644 --- a/conservancy_beancount/reports/ledger.py +++ b/conservancy_beancount/reports/ledger.py @@ -178,10 +178,6 @@ class LedgerODS(core.BaseODS[data.Posting, None]): def init_styles(self) -> None: super().init_styles() - self.style_bottomline = self.merge_styles( - self.border_style(core.Border.TOP, '1pt'), - self.border_style(core.Border.BOTTOM, '2pt', 'double'), - ) self.amount_column = self.column_style(1.2) self.default_column = self.column_style(1.5) self.column_styles: Mapping[str, Union[str, odf.style.Style]] = { diff --git a/tests/test_reports_spreadsheet.py b/tests/test_reports_spreadsheet.py index 20394760ce86acda38b3483a6ea419119d4222bb..9f8e7f7a1eb9ef86590967599f7450cd5010035a 100644 --- a/tests/test_reports_spreadsheet.py +++ b/tests/test_reports_spreadsheet.py @@ -305,6 +305,9 @@ def test_ods_currency_style_cache_considers_properties(ods_writer): ('style_centertext', odf.style.ParagraphProperties, 'textalign'), ('style_endtext', odf.style.ParagraphProperties, 'textalign'), ('style_starttext', odf.style.ParagraphProperties, 'textalign'), + ('style_total', odf.style.TableCellProperties, 'bordertop'), + ('style_endtotal', odf.style.TableCellProperties, 'borderbottom'), + ('style_bottomline', odf.style.TableCellProperties, 'borderbottom'), ]) def test_ods_writer_style(ods_writer, attr_name, child_type, checked_attr): root = ods_writer.document.styles