Changeset - 90ae343a1ade
[Not reviewed]
0 1 0
Brett Smith - 4 years ago 2020-08-18 06:02:54
brettcsmith@brettcsmith.org
balance_sheet: Refactor out Report.start_sheet method.
1 file changed with 43 insertions and 78 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/balance_sheet.py
Show inline comments
...
 
@@ -200,2 +200,3 @@ class Report(core.BaseODS[Sequence[None], None]):
 
        self.balances = balances
 
        self.date_fmt = date_fmt
 
        one_day = datetime.timedelta(days=1)
...
 
@@ -250,19 +251,33 @@ class Report(core.BaseODS[Sequence[None], None]):
 

	
 
    def write_financial_position(self) -> None:
 
        self.use_sheet("Financial Position")
 
        for width in [3, 1.5, 1.5]:
 
            col_style = self.column_style(width)
 
    def start_sheet(self,
 
                    sheet_name: str,
 
                    *headers: Iterable[str],
 
                    totals_prefix: Sequence[str]=(),
 
                    first_width: Union[float, str]=3,
 
                    width: Union[float, str]=1.5,
 
    ) -> None:
 
        header_cells: Sequence[odf.table.TableCell] = [
 
            odf.table.TableCell(),
 
            *(self.multiline_cell(header_lines, stylename=self.style_huline)
 
              for header_lines in headers),
 
            *(self.multiline_cell([*totals_prefix, date_s], stylename=self.style_huline)
 
              for date_s in [self.period_name, self.opening_name]),
 
        ]
 
        self.col_count = len(header_cells)
 
        self.use_sheet(sheet_name)
 
        for index in range(self.col_count):
 
            col_style = self.column_style(width if index else first_width)
 
            self.sheet.addElement(odf.table.TableColumn(stylename=col_style))
 
        start_date = self.balances.period_range.start.strftime(self.date_fmt)
 
        self.add_row(
 
            self.multiline_cell([
 
                "DRAFT Statement of Financial Position",
 
                self.period_name,
 
            ], numbercolumnsspanned=3, stylename=self.style_header)
 
                f"DRAFT Statement of {sheet_name}",
 
                f"{start_date}—{self.period_name}",
 
            ], numbercolumnsspanned=self.col_count, stylename=self.style_header)
 
        )
 
        self.add_row()
 
        self.add_row(
 
            odf.table.TableCell(),
 
            self.string_cell(self.period_name, stylename=self.style_huline),
 
            self.string_cell(self.opening_name, stylename=self.style_huline),
 
        )
 
        self.add_row(*header_cells)
 

	
 
    def write_financial_position(self) -> None:
 
        self.start_sheet("Financial Position")
 

	
...
 
@@ -360,3 +375,8 @@ class Report(core.BaseODS[Sequence[None], None]):
 
    def write_activities(self) -> None:
 
        self.use_sheet("Activities")
 
        self.start_sheet(
 
            "Activities",
 
            ["Without Donor", "Restrictions"],
 
            ["With Donor", "Restrictions"],
 
            totals_prefix=["Total Year Ended"],
 
        )
 
        bal_kwargs: Sequence[Dict[str, Any]] = [
...
 
@@ -367,24 +387,2 @@ class Report(core.BaseODS[Sequence[None], None]):
 
        ]
 
        col_count = len(bal_kwargs) + 1
 
        for index in range(col_count):
 
            col_style = self.column_style(1.5 if index else 3)
 
            self.sheet.addElement(odf.table.TableColumn(stylename=col_style))
 
        self.add_row(
 
            self.multiline_cell([
 
                "DRAFT Statement of Activities",
 
                self.period_name,
 
            ], numbercolumnsspanned=col_count, stylename=self.style_header)
 
        )
 
        self.add_row()
 
        self.add_row(
 
            odf.table.TableCell(),
 
            self.multiline_cell(["Without Donor", "Restrictions"],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["With Donor", "Restrictions"],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["Total Year Ended", self.period_name],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["Total Year Ended", self.opening_name],
 
                                stylename=self.style_huline),
 
        )
 

	
...
 
@@ -515,3 +513,9 @@ class Report(core.BaseODS[Sequence[None], None]):
 
    def write_functional_expenses(self) -> None:
 
        self.use_sheet("Functional Expenses")
 
        self.start_sheet(
 
            "Functional Expenses",
 
            ["Program", "Services"],
 
            ["Management and", "Administrative"],
 
            ["Fundraising"],
 
            totals_prefix=["Total Year Ended"],
 
        )
 
        bal_kwargs: Sequence[Dict[str, Any]] = [
...
 
@@ -523,26 +527,2 @@ class Report(core.BaseODS[Sequence[None], None]):
 
        ]
 
        col_count = len(bal_kwargs) + 1
 
        for index in range(col_count):
 
            col_style = self.column_style(1.5 if index else 3)
 
            self.sheet.addElement(odf.table.TableColumn(stylename=col_style))
 
        self.add_row(
 
            self.multiline_cell([
 
                "DRAFT Statement of Functional Expenses",
 
                self.period_name,
 
            ], numbercolumnsspanned=col_count, stylename=self.style_header)
 
        )
 
        self.add_row()
 
        self.add_row(
 
            odf.table.TableCell(),
 
            self.multiline_cell(["Program", "Services"],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["Management and", "Administrative"],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["Fundraising"],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["Total Year Ended", self.period_name],
 
                                stylename=self.style_huline),
 
            self.multiline_cell(["Total Year Ended", self.opening_name],
 
                                stylename=self.style_huline),
 
        )
 

	
...
 
@@ -568,3 +548,3 @@ class Report(core.BaseODS[Sequence[None], None]):
 
                        "Functional expenses breakdown does not match total on row %s",
 
                        len(self.sheet.childNodes) - col_count,
 
                        len(self.sheet.childNodes) - self.col_count,
 
                    )
...
 
@@ -580,3 +560,3 @@ class Report(core.BaseODS[Sequence[None], None]):
 
    def write_cash_flows(self) -> None:
 
        self.use_sheet("Cash Flows")
 
        self.start_sheet("Cash Flows")
 
        bal_kwargs: Sequence[Dict[str, Any]] = [
...
 
@@ -585,18 +565,3 @@ class Report(core.BaseODS[Sequence[None], None]):
 
        ]
 
        col_count = len(bal_kwargs) + 1
 
        for index in range(col_count):
 
            col_style = self.column_style(1.5 if index else 3)
 
            self.sheet.addElement(odf.table.TableColumn(stylename=col_style))
 
        self.add_row(
 
            self.multiline_cell([
 
                "DRAFT Statement of Cash Flows",
 
                self.period_name,
 
            ], numbercolumnsspanned=col_count, stylename=self.style_header)
 
        )
 
        self.add_row()
 
        self.add_row(
 
            odf.table.TableCell(),
 
            self.string_cell(self.period_name, stylename=self.style_huline),
 
            self.string_cell(self.opening_name, stylename=self.style_huline),
 
        )
 

	
 
        self.add_row(self.string_cell(
0 comments (0 inline, 0 general)