Consolidation Upstream NciBusiness & Domain Workflows
Task prompt
# Consolidation Upstream NCI You are given a consolidation accounting engine in `/app/consolidation/engine.py`. The engine combines a parent and subsidiary and attempts to eliminate intercompany inventory sales and unrealized profit. The engine passes the example scenarios in the repository, but it does not produce correct consolidated balances for every valid scenario. The verifier will test it against a broader set of cases, including intercompany inventory sales in both directions, non-controlling interests at various ownership percentages, and prior-period intercompany inventory profits that are realized in the current period. ## Your task Inspect the engine and the scenario format, fix the consolidation logic so that it handles all valid scenarios correctly, and write the corrected, self-contained `engine.py` to `/logs/artifacts/engine.py`. The verifier will import it as a Python module and call `engine.consolidate(scenario)`. ## Scenario format ```python { 'parent': { 'revenue': float, 'cogs': float, 'inventory': float, 'retained_earnings': float, }, 'subsidiary': { 'revenue': float, 'cogs': float, 'inventory': float, 'retained_earnings': float, }, 'ownership': float, # 0.0 to 1.0 'intercompany_sales': [ { 'direction': 'downstream' | 'upstream', 'sale_amount': float, 'gross_profit': float, 'remaining_in_inventory': float, # 0.0 to 1.0 }, ... ], 'beginning_unrealized_profits': [ # optional { 'direction': 'downstream' | 'upstream', 'amount': float, # profit deferred in prior periods and realized now }, ... ], } ``` ## Return value `consolidate(scenario)` must return a dict with exactly these keys: ```python { 'retained_earnings': float, 'nci': float, 'inventory': float, 'revenue': float, 'cogs': float, } ``` All values are consolidated balances. The verifier checks them against the correct accounting rules with a small tolerance.