fix(report): entity columns read only the ownership window (#161)
Open-source Excel-native EPM and consolidation for SAP & Dynamics
Brought to you by:
konsolid-at
Originally created by: grynn-in
scripts/build_consolidation_report.py: fetch_entity_pnl and fetch_entity_bs now read only the entity-periods the group consolidates. Both add one predicate, built by the new ownership_window_filter(cfg):
(data_area_id, fiscal_year, fiscal_period) IN (
SELECT data_area_id, fiscal_year, fiscal_period
FROM epm_gold.gold_entity_ownership
WHERE consolidation_group = '<group>' AND fiscal_year = <year>
AND outside_ownership_window = 0
AND has_complete_chain = 1
AND consolidation_method NOT IN ('equity', 'none'))
New tests/test_consolidation_report.py tests three things:
gold_consolidated_trial_balance.sql still filters on consolidation_method not in ('equity', 'none') and has_complete_chain = 1;gold_consolidated_trial_balance)gold_entity_ownership) and uses the same predicates the consolidated model applies (gold_consolidated_trial_balance.sql:338-339). The equity/none exclusion is included because the consolidated model drops those periods too. has_complete_chain = 1 already implies outside_ownership_window = 0; both are written out for the reader.gold_trial_balance / gold_balance_sheet in local currency. Only the periods shown change.python3 -m py_compile on the script and the test: OK.pytest tests/test_consolidation_report.py tests/test_docs.py tests/test_stack_cleanup.py: 21 passed. CI runs no pytest; the new test skips without openpyxl.ZZOP (USD);ZZGRP (USD);full, effective 2099-07-01 (P07);dbt_project (unchanged from main) with dbt run --select +gold_consolidated_trial_balance+ gold_balance_sheet --exclude gold_spread_budget+ gold_ic_eliminations gold_ic_reconciliation. It printed OK created for silver_gl_entries, silver_entity_currencies, gold_trial_balance, gold_balance_sheet, gold_entity_ownership, gold_consolidated_trial_balance and gold_fully_consolidated_tb. PASS=39 ERROR=0.gold_entity_ownership for ZZGRP: P1–P6 outside_ownership_window = 1, P7–P12 in window. The consolidated trial balance holds P7–P12 only.| (4010 revenue, sheet values) | Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|---|
| main — P&L Entity | 6,000 | 15,000 | 24,000 | 33,000 |
| main — P&L Consolidated (Entity layer) | 0 | 0 | 24,000 | 33,000 |
| branch — P&L Entity | 0 | 0 | 24,000 | 33,000 |
| branch — P&L Consolidated (Entity layer) | 0 | 0 | 24,000 | 33,000 |
| (1010 cash, BS Entity sheet) | Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|---|
| main | -6,000 | -21,000 | -45,000 | -78,000 |
| branch | 0 | 0 | -45,000 | -78,000 |
reconcile_all() was run.gold_trial_balance, gold_balance_sheet, gold_entity_ownership, gold_consolidated_trial_balance, gold_fully_consolidated_tb and silver_entity_currencies.fetch_consolidated_bs) cumulates the consolidated trial balance's period movements from P1 of the year. For ZZOP at Q3 that gives 24,000 (the P7–P9 movements), while the entity's balance at P9 is 45,000. The report has no acquisition-date balance sheet or opening balance, so the BS entity and BS consolidated columns still differ for an acquired entity. Should an acquisition opening balance land in the consolidated layer (gold_acquisition_adjustments), or should the report cumulate differently?--include-epm / --include-delta sheets use K.EPM formulas over the unwindowed entity measures. For an out-of-window quarter they will now differ from the hardcoded sheet.staging scope builds triggered during the test failed on assert_spread_has_12_periods (4 results).Closes [#161]
🤖 Generated with Claude Code
Ticket changed by: grynn-in