feat(demo): add opt-in synthetic XLSX and JSON bundle generator shared with tests
davoodmehraban89 committed
Oct 31, 2026 at 19:01 UTC
e07d3d4b7fa23d159e1ba090d388cd9e6d28ce4b
1 file changed
+271
backend/src/aram_backend/synthetic_five_statement_demo.py
new
+271
@@ -0,0 +1,271 @@
1
+"""Clearly synthetic demo data; NEVER company data or an official report.
2
+
3
+This is intentionally shared with integration tests to prevent fixture drift.
4
+Writing to disk is opt-in, exclusively inside a brand-new user-specified
5
+directory; no existing files are overwritten.
6
+"""
7
+from __future__ import annotations
8
+
9
+import argparse
10
+from dataclasses import asdict
11
+from io import BytesIO
12
+import json
13
+from pathlib import Path
14
+
15
+from openpyxl import Workbook
16
+
17
+from aram_backend.cash_flow_direct_candidate import CashFlowEntry
18
+from aram_backend.pilot_workbook import SHEET_HEADERS
19
+from aram_backend.reconciliation_review import NoteReference
20
+
21
+COMPANY = "001"
22
+YEAR = 1404
23
+DEMO_WORKBOOK = "ARAM-SYNTHETIC-ONLY.xlsx"
24
+DEMO_MANIFEST = "ARAM-SYNTHETIC-ONLY.json"
25
+DEMO_NOTICE = "READ-ME-SYNTHETIC-ONLY.txt"
26
+
27
+
28
+def source_workbook() -> bytes:
29
+ """One debit-net balanced ledger shared by every candidate builder."""
30
+ book = Workbook()
31
+ book.remove(book.active)
32
+ for name, headers in SHEET_HEADERS.items():
33
+ book.create_sheet(name).append(list(headers))
34
+
35
+ def add(sheet: str, **values: object) -> None:
36
+ book[sheet].append([values.get(column) for column in SHEET_HEADERS[sheet]])
37
+
38
+ add(
39
+ "Company", company_code=COMPANY, company_name="Synthetic integration only",
40
+ fiscal_year=YEAR, currency="IRR", unit="Rial", prepared_by="Test fixture",
41
+ status="Draft",
42
+ )
43
+ ledger = (
44
+ # code, name, opening, debit, credit, closing
45
+ ("CASH", "Cash", "40", "30", "20", "50"),
46
+ ("AR", "Receivables", "50", "0", "0", "50"),
47
+ ("AP", "Payables", "-20", "10", "0", "-10"),
48
+ ("CAP", "Share capital", "-70", "0", "0", "-70"),
49
+ ("REV", "Revenue", "0", "0", "40", "-40"),
50
+ ("EXP", "Cost of revenue", "0", "20", "0", "20"),
51
+ )
52
+ for index, (code, name, opening, debit, credit, closing) in enumerate(ledger, 101):
53
+ add(
54
+ "Accounts", company_code=COMPANY, fiscal_year=YEAR,
55
+ general_code=code, general_name=name, account_full_code=code,
56
+ account_name=name, opening=opening, debit=debit, credit=credit,
57
+ closing=closing, source_row=index, row_status="Draft",
58
+ closing_delta="0",
59
+ )
60
+
61
+ notes = (
62
+ ("BS", "Current assets", "C01", "Cash"),
63
+ ("BS", "Current assets", "A01", "Receivables"),
64
+ ("BS", "Current liabilities", "L01", "Payables"),
65
+ ("BS", "Equity", "E01", "Equity"),
66
+ ("IS", "Revenue", "R01", "Revenue"),
67
+ ("IS", "Cost of revenue", "X01", "Cost of revenue"),
68
+ ("EQ", "Share capital", "E01", "Share capital"),
69
+ ("EQ", "Current year result", "P01", "Current year result"),
70
+ )
71
+ for statement, section, note, title in notes:
72
+ add(
73
+ "Notes", company_code=COMPANY, fiscal_year=YEAR,
74
+ statement=statement, statement_section=section,
75
+ note_number=note, note_title=title, subnote_code="",
76
+ subnote_title="",
77
+ )
78
+
79
+ mappings = (
80
+ ("CASH", "BS", "Current assets", "C01"),
81
+ ("AR", "BS", "Current assets", "A01"),
82
+ ("AP", "BS", "Current liabilities", "L01"),
83
+ ("CAP", "BS", "Equity", "E01"),
84
+ ("CAP", "EQ", "Share capital", "E01"),
85
+ ("REV", "IS", "Revenue", "R01"),
86
+ ("REV", "BS", "Equity", "E01"),
87
+ ("REV", "EQ", "Current year result", "P01"),
88
+ ("EXP", "IS", "Cost of revenue", "X01"),
89
+ ("EXP", "BS", "Equity", "E01"),
90
+ ("EXP", "EQ", "Current year result", "P01"),
91
+ )
92
+ for index, (account, statement, section, note) in enumerate(mappings, 1):
93
+ add(
94
+ "Mapping", mapping_id=f"SYNTH-M-{index:02d}",
95
+ company_code=COMPANY, fiscal_year=YEAR,
96
+ account_full_code=account, account_level="General",
97
+ general_code=account, target_statement=statement,
98
+ statement_section=section, note_number=note, subnote_code="",
99
+ mapping_version=1, approval_status="Approved",
100
+ reviewer="Synthetic fixture only", review_date="2026-10-31",
101
+ source="Synthetic test", notes="Not an authenticated approval",
102
+ validation_status="Valid",
103
+ )
104
+
105
+ output = BytesIO()
106
+ book.save(output)
107
+ book.close()
108
+ return output.getvalue()
109
+
110
+
111
+def references() -> tuple[NoteReference, ...]:
112
+ return (
113
+ NoteReference("BS", "Current assets", "C01", "", "50", "SYNTH-BS-CASH"),
114
+ NoteReference("BS", "Current assets", "A01", "", "50", "SYNTH-BS-AR"),
115
+ NoteReference("BS", "Current liabilities", "L01", "", "-10", "SYNTH-BS-AP"),
116
+ NoteReference("BS", "Equity", "E01", "", "-90", "SYNTH-BS-EQ"),
117
+ NoteReference("IS", "Revenue", "R01", "", "-40", "SYNTH-IS-REV"),
118
+ NoteReference("IS", "Cost of revenue", "X01", "", "20", "SYNTH-IS-COST"),
119
+ NoteReference("EQ", "Share capital", "E01", "", "-70", "SYNTH-EQ-CAP"),
120
+ NoteReference("EQ", "Current year result", "P01", "", "-20", "SYNTH-EQ-PROFIT"),
121
+ )
122
+
123
+
124
+def cash_transactions() -> tuple[CashFlowEntry, ...]:
125
+ return (
126
+ CashFlowEntry(
127
+ company_code=COMPANY, fiscal_year=YEAR, line_id="CF-L1",
128
+ transaction_id="CF-V1", posting_date="1404-01-01",
129
+ cash_account_code="CASH", counterpart_account_code="REV",
130
+ cash_debit="30", cash_credit="0", counterpart_debit="0",
131
+ counterpart_credit="30", evidence_ref="SYNTH-TXN-1",
132
+ ),
133
+ CashFlowEntry(
134
+ company_code=COMPANY, fiscal_year=YEAR, line_id="CF-L2",
135
+ transaction_id="CF-V2", posting_date="1404-01-02",
136
+ cash_account_code="CASH", counterpart_account_code="EXP",
137
+ cash_debit="0", cash_credit="20", counterpart_debit="20",
138
+ counterpart_credit="0", evidence_ref="SYNTH-TXN-2",
139
+ ),
140
+ )
141
+
142
+
143
+def pipeline_manifest(*, transactions=None):
144
+ return {
145
+ "schema_version": 1,
146
+ "company_code": COMPANY,
147
+ "fiscal_year": YEAR,
148
+ "currency": "IRR",
149
+ "unit": "Rial",
150
+ "references": [asdict(item) for item in references()],
151
+ "balance_sheet_policies": [
152
+ {
153
+ "statement_section": "Current assets", "note_number": "C01",
154
+ "subnote_code": "", "category": "ASSETS", "sign_multiplier": 1,
155
+ "line_label": "Cash and cash equivalents",
156
+ "policy_evidence_ref": "SYNTH-POL-BS-CASH",
157
+ },
158
+ {
159
+ "statement_section": "Current assets", "note_number": "A01",
160
+ "subnote_code": "", "category": "ASSETS", "sign_multiplier": 1,
161
+ "line_label": "Trade receivables", "policy_evidence_ref": "SYNTH-POL-BS-AR",
162
+ },
163
+ {
164
+ "statement_section": "Current liabilities", "note_number": "L01",
165
+ "subnote_code": "", "category": "LIABILITIES", "sign_multiplier": -1,
166
+ "line_label": "Trade payables", "policy_evidence_ref": "SYNTH-POL-BS-AP",
167
+ },
168
+ {
169
+ "statement_section": "Equity", "note_number": "E01",
170
+ "subnote_code": "", "category": "EQUITY", "sign_multiplier": -1,
171
+ "line_label": "Total equity", "policy_evidence_ref": "SYNTH-POL-BS-EQ",
172
+ },
173
+ ],
174
+ "income_statement_policies": [
175
+ {
176
+ "statement_section": "Revenue", "note_number": "R01",
177
+ "subnote_code": "", "category": "REVENUE", "sign_multiplier": -1,
178
+ "line_label": "Revenue", "policy_evidence_ref": "SYNTH-POL-IS-REV",
179
+ },
180
+ {
181
+ "statement_section": "Cost of revenue", "note_number": "X01",
182
+ "subnote_code": "", "category": "COST_OF_REVENUE", "sign_multiplier": 1,
183
+ "line_label": "Cost of revenue", "policy_evidence_ref": "SYNTH-POL-IS-COST",
184
+ },
185
+ ],
186
+ "equity_movement_policies": [
187
+ {
188
+ "statement_section": "Share capital", "note_number": "E01",
189
+ "subnote_code": "", "equity_component": "SHARE_CAPITAL",
190
+ "movement_category": "CAPITAL_CONTRIBUTION", "sign_multiplier": -1,
191
+ "line_label": "Share capital", "policy_evidence_ref": "SYNTH-POL-EQ-CAP",
192
+ },
193
+ {
194
+ "statement_section": "Current year result", "note_number": "P01",
195
+ "subnote_code": "", "equity_component": "RETAINED_EARNINGS",
196
+ "movement_category": "NET_PROFIT_LOSS", "sign_multiplier": -1,
197
+ "line_label": "Current year profit", "policy_evidence_ref": "SYNTH-POL-EQ-PROFIT",
198
+ },
199
+ ],
200
+ "cash_accounts": [
201
+ {"account_code": "CASH", "evidence_ref": "SYNTH-CASH-SCOPE"},
202
+ ],
203
+ "counterpart_policies": [
204
+ {"account_code": "REV", "activity": "OPERATING", "evidence_ref": "SYNTH-REV-CLASS"},
205
+ {"account_code": "EXP", "activity": "OPERATING", "evidence_ref": "SYNTH-EXP-CLASS"},
206
+ ],
207
+ "transactions": [
208
+ asdict(item) for item in (
209
+ cash_transactions() if transactions is None else transactions
210
+ )
211
+ ],
212
+ "cash_balance_notes": [
213
+ {
214
+ "statement_section": "Current assets", "note_number": "C01",
215
+ "subnote_code": "", "evidence_ref": "SYNTH-CASH-NOTE-SELECTION",
216
+ },
217
+ ],
218
+ }
219
+
220
+
221
+def write_demo_bundle(output_dir: str | Path) -> tuple[Path, Path]:
222
+ """Write labeled, entirely artificial files into one NEW directory only.
223
+
224
+ Do not silently replace or modify an existing location, including a
225
+ symlink. The caller must specify the directory and opt in explicitly.
226
+ """
227
+ directory = Path(output_dir)
228
+ if directory.exists() or directory.is_symlink():
229
+ raise FileExistsError("DEMO_OUTPUT_DIRECTORY_MUST_NOT_EXIST")
230
+ directory.mkdir(parents=True, exist_ok=False)
231
+ workbook_path = directory / DEMO_WORKBOOK
232
+ manifest_path = directory / DEMO_MANIFEST
233
+ workbook_path.write_bytes(source_workbook())
234
+ manifest_path.write_text(
235
+ json.dumps(
236
+ pipeline_manifest(), sort_keys=True, ensure_ascii=True, indent=2,
237
+ ) + "\n",
238
+ encoding="utf-8",
239
+ )
240
+ (directory / DEMO_NOTICE).write_text(
241
+ "ARAM SYNTHETIC TEST DATA ONLY.\n"
242
+ "NOT A REAL COMPANY, FINANCIAL STATEMENT, APPROVAL OR SOURCE LEDGER.\n"
243
+ "All accounts, amounts, policy references and journal lines are artificial.\n"
244
+ "The demo result may show eligible_for_analyst_review=true only for\n"
245
+ "software arithmetic testing. Never use it for accounting decisions.\n",
246
+ encoding="utf-8",
247
+ )
248
+ return workbook_path, manifest_path
249
+
250
+
251
+def main(argv: list[str] | None = None) -> int:
252
+ parser = argparse.ArgumentParser(
253
+ description="Generate an ARAM entirely synthetic Windows inspection demo"
254
+ )
255
+ parser.add_argument(
256
+ "--output-dir", required=True,
257
+ help="New directory for synthetic XLSX, JSON and warning notice",
258
+ )
259
+ args = parser.parse_args(argv)
260
+ try:
261
+ workbook, manifest = write_demo_bundle(args.output_dir)
262
+ except (OSError, ValueError) as exc:
263
+ parser.exit(2, "ARAM_SYNTHETIC_DEMO_REFUSED: " + str(exc) + "\n")
264
+ print("SYNTHETIC ONLY; not company data, financial approval or release.")
265
+ print("Workbook:", workbook)
266
+ print("Manifest:", manifest)
267
+ return 0
268
+
269
+
270
+if __name__ == "__main__":
271
+ raise SystemExit(main())