ledger: Formatting modernizations.
* Equity sheet(s) report project. * Headers include account classification. * Bottom lines are formatted in the usual accounting way.
This commit is contained in:
parent
58954aab23
commit
e8a754c387
2 changed files with 30 additions and 9 deletions
|
@ -101,7 +101,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]):
|
|||
ACCOUNT_COLUMNS: Dict[str, Sequence[str]] = collections.OrderedDict([
|
||||
('Income', ['project', 'rt-id', 'receipt', 'income-type', 'memo']),
|
||||
('Expenses', ['project', 'rt-id', 'receipt', 'approval', 'expense-type']),
|
||||
('Equity', ['rt-id']),
|
||||
('Equity', ['project', 'rt-id']),
|
||||
('Assets:Receivable', ['project', 'rt-id', 'invoice', 'approval', 'contract', 'purchase-order']),
|
||||
('Liabilities:Payable', ['project', 'rt-id', 'invoice', 'approval', 'contract', 'purchase-order']),
|
||||
('Assets:PayPal', ['rt-id', 'paypal-id', 'receipt', 'approval']),
|
||||
|
@ -178,6 +178,10 @@ 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]] = {
|
||||
|
@ -309,6 +313,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]):
|
|||
date: datetime.date,
|
||||
description: str,
|
||||
balance: core.Balance,
|
||||
bal_style: Union[None, str, odf.style.Style]=None,
|
||||
) -> None:
|
||||
cells: List[odf.table.TableCell] = []
|
||||
for column in self.CORE_COLUMNS:
|
||||
|
@ -319,7 +324,7 @@ class LedgerODS(core.BaseODS[data.Posting, None]):
|
|||
elif column == 'Description':
|
||||
cell = self.string_cell(description, stylename=self.style_bold)
|
||||
elif column == 'Booked Amount':
|
||||
cell = self.balance_cell(self.norm_func(balance), stylename=self.style_bold)
|
||||
cell = self.balance_cell(self.norm_func(balance), stylename=bal_style)
|
||||
else:
|
||||
cell = odf.table.TableCell()
|
||||
cells.append(cell)
|
||||
|
@ -333,27 +338,39 @@ class LedgerODS(core.BaseODS[data.Posting, None]):
|
|||
date = self.date_range.start
|
||||
balance = related.start_bal
|
||||
description = "Opening Balance"
|
||||
stylename: Optional[odf.style.Style] = None
|
||||
else:
|
||||
date = self.date_range.stop
|
||||
stylename = self.style_bottomline
|
||||
if key.keeps_balance():
|
||||
balance = related.stop_bal
|
||||
description = "Ending Balance"
|
||||
else:
|
||||
balance = related.period_bal
|
||||
description = "Period Total"
|
||||
self._write_total_row(date, description, balance)
|
||||
self._write_total_row(date, description, balance, stylename)
|
||||
|
||||
def write_header(self, key: data.Account) -> None:
|
||||
self.add_row()
|
||||
core_count = len(self.CORE_COLUMNS)
|
||||
try:
|
||||
classification = key.meta['classification']
|
||||
except KeyError:
|
||||
classification_cell = odf.table.TableCell()
|
||||
else:
|
||||
classification_cell = self.string_cell(
|
||||
classification,
|
||||
numbercolumnsspanned=len(self.sheet_columns) - core_count,
|
||||
)
|
||||
self.add_row(
|
||||
odf.table.TableCell(),
|
||||
self.string_cell(
|
||||
f"{key} {self.report_name}"
|
||||
f" From {self.date_range.start.isoformat()}"
|
||||
f" To {self.date_range.stop.isoformat()}",
|
||||
key,
|
||||
stylename=self.style_bold,
|
||||
numbercolumnsspanned=len(self.sheet_columns) - 1,
|
||||
numbercolumnsspanned=core_count - 1,
|
||||
),
|
||||
*(odf.table.TableCell() for _ in range(2, core_count)),
|
||||
classification_cell,
|
||||
)
|
||||
|
||||
def write_balance_sheet(self) -> None:
|
||||
|
@ -379,7 +396,9 @@ class LedgerODS(core.BaseODS[data.Posting, None]):
|
|||
style = self.merge_styles(self.style_bold, self.style_endtext)
|
||||
elif account is core.ENDING_BALANCE_NAME:
|
||||
text = f"Balance as of {self.date_range.stop.isoformat()}"
|
||||
style = self.merge_styles(self.style_bold, self.style_endtext)
|
||||
style = self.merge_styles(
|
||||
self.style_bottomline, self.style_bold, self.style_endtext,
|
||||
)
|
||||
else:
|
||||
text = account
|
||||
style = self.style_endtext
|
||||
|
|
|
@ -95,7 +95,9 @@ class ExpectedPostings(core.RelatedPostings):
|
|||
rows = iter(sheet.getElementsByType(odf.table.TableRow))
|
||||
for row in rows:
|
||||
cells = row.childNodes
|
||||
if len(cells) == 2 and cells[-1].text.startswith(f'{account} '):
|
||||
if (len(cells) >= 3
|
||||
and cells[1].text == account
|
||||
and not cells[0].text):
|
||||
break
|
||||
else:
|
||||
raise NoHeader(account)
|
||||
|
|
Loading…
Reference in a new issue