From 5081c8934cf3f1e68ba738d2c6a37dad1df56259 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 3 Sep 2020 14:45:06 -0400 Subject: [PATCH] ledger: Put account classification on each row in a hidden column. This makes it easier to build formulas based on classification. Hiding it keeps the presentation neat for human readers. --- conservancy_beancount/reports/ledger.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conservancy_beancount/reports/ledger.py b/conservancy_beancount/reports/ledger.py index 619948c..d78d66c 100644 --- a/conservancy_beancount/reports/ledger.py +++ b/conservancy_beancount/reports/ledger.py @@ -109,6 +109,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]): ('Assets', ['rt-id', 'receipt', 'approval', 'bank-statement']), ('Liabilities', ['rt-id', 'receipt', 'approval', 'bank-statement']), ]) + CLASSIFICATION_COLUMN = "Account Classification" # Excel 2003 was limited to 65,536 rows per worksheet. # While we can probably count on all our users supporting more modern # formats (Excel 2007 supports over 1 million rows per worksheet), @@ -189,6 +190,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]): 'Booked Amount': self.amount_column, data.Metadata.human_name('project'): self.amount_column, data.Metadata.human_name('rt-id'): self.amount_column, + self.CLASSIFICATION_COLUMN: self.column_style(3), } @classmethod @@ -295,11 +297,13 @@ class LedgerODS(core.BaseODS[data.Posting, None]): self.sheet_columns: Sequence[str] = [ *self.CORE_COLUMNS, *(data.Metadata.human_name(meta_key) for meta_key in self.metadata_columns), + self.CLASSIFICATION_COLUMN, ] for col_name in self.sheet_columns: self.sheet.addElement(odf.table.TableColumn( stylename=self.column_styles.get(col_name, self.default_column), )) + self.sheet.lastChild.setAttribute('visibility', 'collapse') self.add_row(*( self.string_cell(col_name, stylename=self.style_bold) for col_name in self.sheet_columns @@ -408,6 +412,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]): return len(self.account_groups[account]) def write_entries(self, account: data.Account, rows: Iterable[data.Posting]) -> None: + classification = account.meta.get('classification', '') for row in rows: if row.cost is None: amount_cell = odf.table.TableCell() @@ -423,6 +428,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]): if key in data.LINK_METADATA else self.string_cell(row.meta.get(key, '')) for key in self.metadata_columns), + self.string_cell(classification), ) def write(self, rows: Iterable[data.Posting]) -> None: