Originally created by: grynn-in
scripts/build_consolidation_report.py (around lines 163-167, 186-187 and 225) chooses the expense sub-sections (COGS, operating expenses, other) from D365 account-number prefixes (5, 6, 7/8). An ERPNext expense account id such as "Cost of Goods Sold - XX" matches none of them. It falls back to an "Expense" section that isn't in section_order.
With ERPNext enabled, those accounts land outside COGS, OpEx and every subtotal in the consolidation report. Gross profit and operating profit come out wrong, and nothing fails. konsolidat [#184] fixed the same problem for revenue.
Classify the sub-section from the chart rather than from account-number prefixes. Once konsol [#182] (a group chart governed in konsol) lands, use its declared statement_section/sub_section. Until then, add a fallback that maps any unmatched expense account into operating expenses and lists it in the report's diagnostics.
Found in the review of [#184].
Tickets: #169
Tickets: #170
Tickets: #182
Tickets: #184
Tickets: #210
Originally posted by: grynn-in
Verdict: LIVE, confirmed.
scripts/build_consolidation_report.py:163still selects the expense sub-section by D365 account-number prefix:so a non-numeric ERPNext account id still falls through, exactly as described.
Worth re-scoping rather than patching the prefixes. Since konsol#182 the chart declares
statement_sectionandsub_sectionper account, and the warehouse already classifies from the declaration rather than from code shapes โsilver_main_accountsderivesis_pnl/is_balance_sheetfromstatement_section. This script is now the only place left that infers meaning from account-number prefixes. Reading the declared sub-section fixes it for every chart, not just ERPNext's.๐ค Triage against
mainโ Claude Code ยท https://claude.ai/code/session_01P3Pf9835FeLeXjRrYTTZ1MOriginally posted by: grynn-in
Re-scoped โ read the declaration rather than patching the prefixes
Still reproducible.
scripts/build_consolidation_report.py:163:so a non-numeric ERPNext account id still falls through to a section that is not in
section_order.The fix should not be more prefixes. Since konsol#182 the chart declares
statement_sectionandsub_sectionper account, and the rest of the stack already classifies from the declaration โsilver_main_accountsderivesis_pnlandis_balance_sheetfromstatement_section, and there is no prefix or range logic on account codes anywhere in the 106 dbt models.This script is now the only place left in either repo that infers meaning from account-number shapes. Reading
sub_sectionfixes it for every chart, not just ERPNext's, and removes the last instance of the pattern.Check konsolidat#169 and [#170] first, though โ all three are open against this same script, and the project notes record it as broken since F2. Decide whether it is still the delivery path before fixing three bugs in it.
๐ค Re-scoped 15 Sep 2026 against
mainโ Claude Code ยท https://claude.ai/code/session_01P3Pf9835FeLeXjRrYTTZ1MRelated
Tickets: #170
Originally posted by: grynn-in
Note on framing โ this issue survives the ERP removal, but its premise needs rewording.
The ERP staging tree is being removed (konsolidat#221). This issue is framed as an ERPNext problem: "With ERPNext enabled, the expense accounts fall outside COGS/OpEx."
The defect is not about ERPNext.
scripts/build_consolidation_report.py:163chooses expense sub-sections from D365 account-number prefixes โ so it misclassifies any chart whose account codes are not D365-shaped, which after this decision is every chart, since konsol's governed chart is the only source.So it becomes more relevant, not less. The fix is unchanged and already noted: read the chart's declared
sub_section, which every account carries since konsol#182. This is the last place in either repo inferring meaning from account-number shapes.๐ค Claude Code ยท https://claude.ai/code/session_01P3Pf9835FeLeXjRrYTTZ1M