@davoodmehraban89 / Aram / commits / 2ce2908
Fork 0

Implement Phase 4A accounting rule engine foundation

Scaffold backend/app/accounting module containing AccountingRule config, AccountingCalculator, StatementGenerator (Trial Balance, Balance Sheet, Income Statement foundations), and service layer. Add 10 automated unit tests in test_accounting.py (44/44 total tests passing). Co-authored-by: davoodmehraban89 <57283229+davoodmehraban89@users.noreply.github.com>

google-labs-jules[bot] committed Aug 23, 2026 at 05:12 UTC 2ce290898490faa29cf2b1924e081647496d42f5
7 files changed +429 -14
backend/README.md
+19 -14
@@ -1,6 +1,6 @@
1 -# Financial Reporting Platform - Backend Foundation, Ingestion & Normalization Engine (Phase 2A, 2B & 3)
1 +# Financial Reporting Platform - Backend Architecture (Phase 2A - Phase 4A)
2
3 -This backend application implements the persistent relational data model foundation, controlled financial source ingestion engine, and financial data normalization framework for the Financial Reporting Platform using Python, FastAPI, SQLAlchemy, and Pydantic.
3 +This backend application implements the persistent relational data model, source document ingestion, financial data normalization, and accounting rule engine foundation for the Financial Reporting Platform using Python, FastAPI, SQLAlchemy, and Pydantic.
4
5 ## Prerequisites
6
@@ -42,21 +42,26 @@ Environment variables can be overridden via system environment or a `.env` file:
42
43 The ingestion module under `backend/app/ingestion/` provides controlled financial source document importing:
44
45 -- **Parsers (`backend/app/ingestion/parsers.py`)**: Supports format validation and SHA256 checksum computation for `.xlsx`, `.csv`, and `.pdf` files without mutating raw source files.
46 -- **Service Layer (`backend/app/ingestion/service.py`)**:
47 - - `validate_source(file_path)`: Validates file existence, format support, and computes file hash.
48 - - `register_source_document(db, year_id, file_path, doc_type)`: Verifies fiscal year mutability, checks for duplicate document hashes, and records a `SourceDocument`.
49 - - `process_import(db, year_id, file_path, doc_type)`: Orchestrates document registration, status tracking (`REGISTERED` -> `PROCESSED`), and metadata extraction.
45 +- **Parsers (`backend/app/ingestion/parsers.py`)**: Format validation and SHA256 checksum computation for `.xlsx`, `.csv`, and `.pdf` files without mutating raw source files.
46 +- **Service Layer (`backend/app/ingestion/service.py`)**: `validate_source()`, `register_source_document()`, and `process_import()`.
47
48 ## Normalization Engine (Phase 3)
49
50 The normalization module under `backend/app/normalization/` converts ingested source data into standardized financial records:
51
52 - **Analyzer (`backend/app/normalization/analyzer.py`)**: Detects column headers and analyzes tabular file structure.
56 -- **Mapper (`backend/app/normalization/mapper.py`)**: Applies column mapping templates to translate raw row key-value pairs into normalized fields (`account_code`, `account_name`, `debit`, `credit`, `net_amount`, `t1`-`t4`).
57 -- **Validator (`backend/app/normalization/validator.py`)**: Enforces required field validation, non-negative monetary constraints, and generates structured `ValidationErrorLog` records.
58 -- **Service Layer (`backend/app/normalization/service.py`)**:
59 - - `normalize_and_persist_records(db, year_id, source_document_id, raw_rows, template_name)`: Orchestrates row mapping, validation, error logging, and persistence of `NormalizedFinancialRecord` and `ValidationErrorLog` entities while enforcing fiscal-year immutability.
53 +- **Mapper (`backend/app/normalization/mapper.py`)**: Translates raw row data into normalized attributes (`account_code`, `account_name`, `debit`, `credit`, `net_amount`, `t1`-`t4`).
54 +- **Validator (`backend/app/normalization/validator.py`)**: Enforces required field validation, non-negative monetary constraints, and generates `ValidationErrorLog` records.
55 +- **Service Layer (`backend/app/normalization/service.py`)**: `normalize_and_persist_records()`.
56 +
57 +## Accounting Rule Engine Foundation (Phase 4A)
58 +
59 +The accounting module under `backend/app/accounting/` performs rule-based calculations on normalized financial records:
60 +
61 +- **Rules (`backend/app/accounting/rules.py`)**: Configurable account grouping rules (`AccountGroupRule`, `AccountingRuleConfig`).
62 +- **Calculator (`backend/app/accounting/calculator.py`)**: Debit/credit aggregation and account classification logic.
63 +- **Statements (`backend/app/accounting/statements.py`)**: Foundation generators for Trial Balance (TB), Balance Sheet (BS), and Income Statement (IS).
64 +- **Service (`backend/app/accounting/service.py`)**: `generate_financial_statements()`.
65
66 ## Running Tests
67
@@ -70,11 +75,11 @@ PYTHONPATH=. pytest -v backend/tests
75
76 - **Company**: Corporate entity metadata (`code`, `name`).
77 - **FiscalYear**: Year context (`year`, `status`: `Draft`, `Approved`, `Locked`).
73 -- **SourceDocument**: Metadata for imported ledger/statement files (`file_hash`, `processing_status`, `version`).
78 +- **SourceDocument**: Metadata for imported ledger/statement files.
79 - **AccountVersion**: Fiscal-year isolated Chart of Accounts.
80 - **MappingRule**: Mapping rules linking accounts to note definitions.
81 - **NoteDefinition** & **NoteRow**: Financial note definitions and structural line items.
82 - **FinancialStatement** & **StatementLine**: Primary financial statement headers and line items.
78 -- **MappingTemplate**: Custom column header mapping definitions per fiscal year.
83 +- **MappingTemplate**: Custom column header mapping definitions.
84 - **NormalizedFinancialRecord**: Standardized financial transaction/account row records.
80 -- **ValidationErrorLog**: Log of data validation errors and warnings (`INFO`, `WARNING`, `ERROR`).
85 +- **ValidationErrorLog**: Log of data validation errors and warnings.
backend/app/accounting/__init__.py
backend/app/accounting/calculator.py new
+50
@@ -0,0 +1,50 @@
1 +from typing import List, Dict, Any
2 +from backend.app.models.entities import NormalizedFinancialRecord
3 +from backend.app.accounting.rules import AccountingRuleConfig, DEFAULT_ACCOUNTING_RULES
4 +
5 +
6 +class AccountingCalculator:
7 + """Calculates aggregates and group totals from normalized financial records."""
8 + def __init__(self, rule_config: AccountingRuleConfig = None):
9 + self.config = rule_config or DEFAULT_ACCOUNTING_RULES
10 +
11 + def aggregate_records(self, records: List[NormalizedFinancialRecord]) -> Dict[str, Dict[str, Any]]:
12 + """Aggregates debit/credit and net totals grouped by unique account_code."""
13 + aggregated: Dict[str, Dict[str, Any]] = {}
14 +
15 + for rec in records:
16 + code = rec.account_code or "UNKNOWN"
17 + if code not in aggregated:
18 + aggregated[code] = {
19 + "account_code": code,
20 + "account_name": rec.account_name or "",
21 + "total_debit": 0.0,
22 + "total_credit": 0.0,
23 + "net_balance": 0.0,
24 + "t1": rec.t1,
25 + "t2": rec.t2,
26 + "t3": rec.t3,
27 + "t4": rec.t4,
28 + "record_count": 0,
29 + }
30 +
31 + debit_val = float(rec.debit) if rec.debit is not None else 0.0
32 + credit_val = float(rec.credit) if rec.credit is not None else 0.0
33 + net_val = float(rec.net_amount) if rec.net_amount is not None else (debit_val - credit_val)
34 +
35 + aggregated[code]["total_debit"] += debit_val
36 + aggregated[code]["total_credit"] += credit_val
37 + aggregated[code]["net_balance"] += net_val
38 + aggregated[code]["record_count"] += 1
39 +
40 + return aggregated
41 +
42 + def classify_account(self, account_code: str, target_statement: str) -> Dict[str, str]:
43 + """Classifies an account code into a statement section using rules config."""
44 + for rule in self.config.group_rules:
45 + if rule.target_statement == target_statement:
46 + if rule.account_codes and account_code in rule.account_codes:
47 + return {"group_name": rule.group_name, "section": rule.statement_section}
48 + if rule.code_prefix and account_code.startswith(rule.code_prefix):
49 + return {"group_name": rule.group_name, "section": rule.statement_section}
50 + return {"group_name": "Unclassified", "section": "Other"}
backend/app/accounting/rules.py new
+37
@@ -0,0 +1,37 @@
1 +from typing import Dict, Any, List, Optional
2 +from pydantic import BaseModel
3 +
4 +
5 +class AccountGroupRule(BaseModel):
6 + group_name: str
7 + code_prefix: Optional[str] = None
8 + account_codes: Optional[List[str]] = None
9 + target_statement: str # TB, BS, IS
10 + statement_section: str # e.g., Current Assets, Non-Current Assets, Revenues, Expenses
11 +
12 +
13 +class AccountingRuleConfig(BaseModel):
14 + version: str = "1.0"
15 + group_rules: List[AccountGroupRule] = []
16 +
17 +
18 +DEFAULT_ACCOUNTING_RULES = AccountingRuleConfig(
19 + group_rules=[
20 + # Balance Sheet - Assets
21 + AccountGroupRule(group_name="Cash and Cash Equivalents", code_prefix="11", target_statement="BS", statement_section="Current Assets"),
22 + AccountGroupRule(group_name="Trade Receivables", code_prefix="12", target_statement="BS", statement_section="Current Assets"),
23 + AccountGroupRule(group_name="Inventories", code_prefix="13", target_statement="BS", statement_section="Current Assets"),
24 + AccountGroupRule(group_name="Property, Plant & Equipment", code_prefix="21", target_statement="BS", statement_section="Non-Current Assets"),
25 + # Balance Sheet - Liabilities & Equity
26 + AccountGroupRule(group_name="Trade Payables", code_prefix="31", target_statement="BS", statement_section="Current Liabilities"),
27 + AccountGroupRule(group_name="Short-term Loans", code_prefix="32", target_statement="BS", statement_section="Current Liabilities"),
28 + AccountGroupRule(group_name="Long-term Debt", code_prefix="41", target_statement="BS", statement_section="Non-Current Liabilities"),
29 + AccountGroupRule(group_name="Share Capital", code_prefix="51", target_statement="BS", statement_section="Equity"),
30 + AccountGroupRule(group_name="Retained Earnings", code_prefix="52", target_statement="BS", statement_section="Equity"),
31 + # Income Statement
32 + AccountGroupRule(group_name="Operating Revenue", code_prefix="61", target_statement="IS", statement_section="Revenues"),
33 + AccountGroupRule(group_name="Cost of Goods Sold", code_prefix="71", target_statement="IS", statement_section="Cost of Sales"),
34 + AccountGroupRule(group_name="Administrative Expenses", code_prefix="81", target_statement="IS", statement_section="Operating Expenses"),
35 + AccountGroupRule(group_name="Finance Costs", code_prefix="91", target_statement="IS", statement_section="Finance Expenses"),
36 + ]
37 +)
backend/app/accounting/service.py new
+36
@@ -0,0 +1,36 @@
1 +from typing import Dict, Any, List
2 +from sqlalchemy.orm import Session
3 +
4 +from backend.app.models.entities import NormalizedFinancialRecord
5 +from backend.app.services.protection import check_fiscal_year_mutable
6 +from backend.app.accounting.calculator import AccountingCalculator
7 +from backend.app.accounting.statements import StatementGenerator
8 +from backend.app.accounting.rules import AccountingRuleConfig
9 +
10 +
11 +def generate_financial_statements(
12 + db: Session,
13 + year_id: int,
14 + rule_config: AccountingRuleConfig = None,
15 +) -> Dict[str, Any]:
16 + """
17 + Fetches NormalizedFinancialRecord rows for the specified year_id,
18 + and calculates Trial Balance, Balance Sheet, and Income Statement foundations.
19 + Enforces fiscal year lookup and returns isolated statement calculations.
20 + """
21 + records = db.query(NormalizedFinancialRecord).filter(NormalizedFinancialRecord.year_id == year_id).all()
22 +
23 + calculator = AccountingCalculator(rule_config)
24 + generator = StatementGenerator(calculator)
25 +
26 + tb = generator.generate_trial_balance(records)
27 + bs = generator.generate_balance_sheet(records)
28 + statement_is = generator.generate_income_statement(records)
29 +
30 + return {
31 + "year_id": year_id,
32 + "record_count": len(records),
33 + "trial_balance": tb,
34 + "balance_sheet": bs,
35 + "income_statement": statement_is,
36 + }
backend/app/accounting/statements.py new
+115
@@ -0,0 +1,115 @@
1 +from typing import List, Dict, Any
2 +from backend.app.models.entities import NormalizedFinancialRecord
3 +from backend.app.accounting.calculator import AccountingCalculator
4 +from backend.app.accounting.rules import AccountingRuleConfig
5 +
6 +
7 +class StatementGenerator:
8 + """Generates Trial Balance, Balance Sheet, and Income Statement structures."""
9 + def __init__(self, calculator: AccountingCalculator = None):
10 + self.calculator = calculator or AccountingCalculator()
11 +
12 + def generate_trial_balance(self, records: List[NormalizedFinancialRecord]) -> Dict[str, Any]:
13 + """Generates Trial Balance foundation."""
14 + aggregated = self.calculator.aggregate_records(records)
15 + rows = list(aggregated.values())
16 +
17 + total_debit = sum(r["total_debit"] for r in rows)
18 + total_credit = sum(r["total_credit"] for r in rows)
19 + net_difference = total_debit - total_credit
20 +
21 + return {
22 + "statement_type": "TB",
23 + "title": "Trial Balance",
24 + "rows": rows,
25 + "total_debit": round(total_debit, 2),
26 + "total_credit": round(total_credit, 2),
27 + "is_balanced": abs(net_difference) < 0.01,
28 + "net_difference": round(net_difference, 2),
29 + }
30 +
31 + def generate_balance_sheet(self, records: List[NormalizedFinancialRecord]) -> Dict[str, Any]:
32 + """Generates Balance Sheet foundation."""
33 + aggregated = self.calculator.aggregate_records(records)
34 + sections: Dict[str, Dict[str, float]] = {
35 + "Current Assets": {},
36 + "Non-Current Assets": {},
37 + "Current Liabilities": {},
38 + "Non-Current Liabilities": {},
39 + "Equity": {},
40 + "Other": {},
41 + }
42 +
43 + for code, data in aggregated.items():
44 + classification = self.calculator.classify_account(code, target_statement="BS")
45 + sec = classification["section"]
46 + group = classification["group_name"]
47 +
48 + if sec not in sections:
49 + sections[sec] = {}
50 + if group not in sections[sec]:
51 + sections[sec][group] = 0.0
52 +
53 + sections[sec][group] += data["net_balance"]
54 +
55 + total_assets = (
56 + sum(sections["Current Assets"].values()) +
57 + sum(sections["Non-Current Assets"].values())
58 + )
59 + total_liabilities = (
60 + sum(sections["Current Liabilities"].values()) +
61 + sum(sections["Non-Current Liabilities"].values())
62 + )
63 + total_equity = sum(sections["Equity"].values())
64 +
65 + return {
66 + "statement_type": "BS",
67 + "title": "Balance Sheet Foundation",
68 + "sections": sections,
69 + "total_assets": round(total_assets, 2),
70 + "total_liabilities": round(total_liabilities, 2),
71 + "total_equity": round(total_equity, 2),
72 + "is_balanced": abs(total_assets - (total_liabilities + total_equity)) < 0.01,
73 + }
74 +
75 + def generate_income_statement(self, records: List[NormalizedFinancialRecord]) -> Dict[str, Any]:
76 + """Generates Income Statement foundation."""
77 + aggregated = self.calculator.aggregate_records(records)
78 + sections: Dict[str, Dict[str, float]] = {
79 + "Revenues": {},
80 + "Cost of Sales": {},
81 + "Operating Expenses": {},
82 + "Finance Expenses": {},
83 + "Other": {},
84 + }
85 +
86 + for code, data in aggregated.items():
87 + classification = self.calculator.classify_account(code, target_statement="IS")
88 + sec = classification["section"]
89 + group = classification["group_name"]
90 +
91 + if sec not in sections:
92 + sections[sec] = {}
93 + if group not in sections[sec]:
94 + sections[sec][group] = 0.0
95 +
96 + sections[sec][group] += data["net_balance"]
97 +
98 + total_revenues = sum(sections["Revenues"].values())
99 + total_cos = sum(sections["Cost of Sales"].values())
100 + gross_profit = total_revenues - total_cos
101 + total_opex = sum(sections["Operating Expenses"].values())
102 + operating_profit = gross_profit - total_opex
103 + total_finance = sum(sections["Finance Expenses"].values())
104 + net_profit = operating_profit - total_finance
105 +
106 + return {
107 + "statement_type": "IS",
108 + "title": "Income Statement Foundation",
109 + "sections": sections,
110 + "total_revenues": round(total_revenues, 2),
111 + "total_cost_of_sales": round(total_cos, 2),
112 + "gross_profit": round(gross_profit, 2),
113 + "operating_profit": round(operating_profit, 2),
114 + "net_profit": round(net_profit, 2),
115 + }
backend/tests/test_accounting.py new
+172
@@ -0,0 +1,172 @@
1 +import pytest
2 +from backend.app.models import (
3 + Company,
4 + FiscalYear,
5 + FiscalYearStatus,
6 + SourceDocument,
7 + NormalizedFinancialRecord,
8 +)
9 +from backend.app.accounting.rules import AccountingRuleConfig, AccountGroupRule
10 +from backend.app.accounting.calculator import AccountingCalculator
11 +from backend.app.accounting.statements import StatementGenerator
12 +from backend.app.accounting.service import generate_financial_statements
13 +
14 +
15 +def test_debit_credit_aggregation():
16 + records = [
17 + NormalizedFinancialRecord(account_code="1101", account_name="Cash", debit=500.0, credit=0.0, net_amount=500.0),
18 + NormalizedFinancialRecord(account_code="1101", account_name="Cash", debit=300.0, credit=100.0, net_amount=200.0),
19 + ]
20 + calc = AccountingCalculator()
21 + aggregated = calc.aggregate_records(records)
22 +
23 + assert "1101" in aggregated
24 + assert aggregated["1101"]["total_debit"] == 800.0
25 + assert aggregated["1101"]["total_credit"] == 100.0
26 + assert aggregated["1101"]["net_balance"] == 700.0
27 +
28 +
29 +def test_account_grouping():
30 + calc = AccountingCalculator()
31 + classification = calc.classify_account("1101", target_statement="BS")
32 + assert classification["group_name"] == "Cash and Cash Equivalents"
33 + assert classification["section"] == "Current Assets"
34 +
35 +
36 +def test_trial_balance_generation():
37 + records = [
38 + NormalizedFinancialRecord(account_code="1101", account_name="Cash", debit=1000.0, credit=0.0, net_amount=1000.0),
39 + NormalizedFinancialRecord(account_code="3101", account_name="Payables", debit=0.0, credit=1000.0, net_amount=-1000.0),
40 + ]
41 + generator = StatementGenerator()
42 + tb = generator.generate_trial_balance(records)
43 +
44 + assert tb["statement_type"] == "TB"
45 + assert tb["total_debit"] == 1000.0
46 + assert tb["total_credit"] == 1000.0
47 + assert tb["is_balanced"] is True
48 +
49 +
50 +def test_balance_sheet_generation():
51 + records = [
52 + NormalizedFinancialRecord(account_code="1101", account_name="Cash", debit=500.0, credit=0.0, net_amount=500.0),
53 + NormalizedFinancialRecord(account_code="3101", account_name="Payables", debit=0.0, credit=300.0, net_amount=300.0),
54 + NormalizedFinancialRecord(account_code="5101", account_name="Capital", debit=0.0, credit=200.0, net_amount=200.0),
55 + ]
56 + generator = StatementGenerator()
57 + bs = generator.generate_balance_sheet(records)
58 +
59 + assert bs["statement_type"] == "BS"
60 + assert bs["total_assets"] == 500.0
61 + assert bs["total_liabilities"] == 300.0
62 + assert bs["total_equity"] == 200.0
63 + assert bs["is_balanced"] is True
64 +
65 +
66 +def test_income_statement_generation():
67 + records = [
68 + NormalizedFinancialRecord(account_code="6101", account_name="Sales", debit=0.0, credit=1000.0, net_amount=1000.0),
69 + NormalizedFinancialRecord(account_code="7101", account_name="COGS", debit=400.0, credit=0.0, net_amount=400.0),
70 + NormalizedFinancialRecord(account_code="8101", account_name="Rent", debit=100.0, credit=0.0, net_amount=100.0),
71 + ]
72 + generator = StatementGenerator()
73 + is_stmt = generator.generate_income_statement(records)
74 +
75 + assert is_stmt["statement_type"] == "IS"
76 + assert is_stmt["total_revenues"] == 1000.0
77 + assert is_stmt["total_cost_of_sales"] == 400.0
78 + assert is_stmt["gross_profit"] == 600.0
79 + assert is_stmt["operating_profit"] == 500.0
80 +
81 +
82 +def test_invalid_data_handling():
83 + records = [
84 + NormalizedFinancialRecord(account_code=None, account_name=None, debit=None, credit=None, net_amount=None),
85 + ]
86 + calc = AccountingCalculator()
87 + aggregated = calc.aggregate_records(records)
88 +
89 + assert "UNKNOWN" in aggregated
90 + assert aggregated["UNKNOWN"]["total_debit"] == 0.0
91 + assert aggregated["UNKNOWN"]["total_credit"] == 0.0
92 +
93 +
94 +def test_fiscal_year_isolation_in_accounting_service(db_session):
95 + comp = Company(code="ACC1", name="Accounting Corp 1")
96 + db_session.add(comp)
97 + db_session.commit()
98 +
99 + fy1402 = FiscalYear(company_id=comp.id, year=1402, status=FiscalYearStatus.DRAFT)
100 + fy1403 = FiscalYear(company_id=comp.id, year=1403, status=FiscalYearStatus.DRAFT)
101 + db_session.add_all([fy1402, fy1403])
102 + db_session.commit()
103 +
104 + doc1402 = SourceDocument(year_id=fy1402.id, filename="ledger1402.csv", file_hash="h1402", doc_type="ledger")
105 + doc1403 = SourceDocument(year_id=fy1403.id, filename="ledger1403.csv", file_hash="h1403", doc_type="ledger")
106 + db_session.add_all([doc1402, doc1403])
107 + db_session.commit()
108 +
109 + rec1402 = NormalizedFinancialRecord(
110 + year_id=fy1402.id,
111 + source_document_id=doc1402.id,
112 + row_index=1,
113 + account_code="1101",
114 + account_name="Cash 1402",
115 + debit=100.0,
116 + credit=0.0,
117 + net_amount=100.0,
118 + )
119 + rec1403 = NormalizedFinancialRecord(
120 + year_id=fy1403.id,
121 + source_document_id=doc1403.id,
122 + row_index=1,
123 + account_code="1101",
124 + account_name="Cash 1403",
125 + debit=500.0,
126 + credit=0.0,
127 + net_amount=500.0,
128 + )
129 + db_session.add_all([rec1402, rec1403])
130 + db_session.commit()
131 +
132 + res1402 = generate_financial_statements(db_session, year_id=fy1402.id)
133 + res1403 = generate_financial_statements(db_session, year_id=fy1403.id)
134 +
135 + assert res1402["record_count"] == 1
136 + assert res1402["trial_balance"]["total_debit"] == 100.0
137 +
138 + assert res1403["record_count"] == 1
139 + assert res1403["trial_balance"]["total_debit"] == 500.0
140 +
141 +
142 +def test_custom_accounting_rules():
143 + custom_rules = AccountingRuleConfig(
144 + group_rules=[
145 + AccountGroupRule(
146 + group_name="Custom Group",
147 + account_codes=["SPECIAL_CODE"],
148 + target_statement="BS",
149 + statement_section="Current Assets",
150 + )
151 + ]
152 + )
153 + calc = AccountingCalculator(custom_rules)
154 + classification = calc.classify_account("SPECIAL_CODE", target_statement="BS")
155 + assert classification["group_name"] == "Custom Group"
156 +
157 +
158 +def test_unclassified_account_fallback():
159 + calc = AccountingCalculator()
160 + classification = calc.classify_account("999999", target_statement="BS")
161 + assert classification["group_name"] == "Unclassified"
162 + assert classification["section"] == "Other"
163 +
164 +
165 +def test_balanced_statement_tolerances():
166 + records = [
167 + NormalizedFinancialRecord(account_code="1101", account_name="Cash", debit=100.004, credit=0.0, net_amount=100.004),
168 + NormalizedFinancialRecord(account_code="3101", account_name="Payable", debit=0.0, credit=100.001, net_amount=-100.001),
169 + ]
170 + generator = StatementGenerator()
171 + tb = generator.generate_trial_balance(records)
172 + assert tb["is_balanced"] is True