"""Static Finance application catalogue. The six entries below are navigation/application contracts, not data stores. Every fact key resolves through :mod:`modules.finance_spine`, which keeps one governed definition of scope, freshness, lineage, drill-through, and reconciliation for every consumer. """ from copy import deepcopy from modules import financial, health, inventory, management, o2c, procurement FINANCE_GROUP = { "key": "finance", "label": "Finance", "description": "Receivables, spend, cash, margin, inventory, and planning.", "routePrefix": "/finance", } # Workflow ownership lives here, at the application layer. Source modules describe only the # governed-data requirement and its read-only validation seam; they do not create queue state. _OWNED_WORK = { "open_purchase_orders": ("Buyer", "Chase the late purchase order"), "lead_time_coverage": ("Buyer", "Confirm the replenishment lead time"), "replenishment": ("Buyer", "Create the replenishment plan"), "inventory_value": ("Inventory manager", "Reconcile the inventory valuation"), "excess_stock": ("Inventory manager", "Disposition the excess stock"), "dead_stock": ("Inventory manager", "Choose the dead-stock disposition"), } def _owned_work_signals(): """Compose non-executable owned-work requirements without manufacturing queue records.""" signals = procurement.finance_workflow_contract() + inventory.finance_workflow_contract() for signal in signals: signal["state"] = signal.pop("availability") signal["ownerRole"], signal["nextAction"] = _OWNED_WORK[signal["key"]] signal["status"] = "unavailable" return signals FINANCE_APPLICATIONS = ( { "key": "ar-collections", "label": "Collection", "navLabel": "Collection", "description": "Prioritize customer balances that need collection action.", "mode": "workflow", "permissionKey": "ar", "composes": ["ar", "collections"], "factKeys": ["ar_outstanding"], "kpiKeys": ["ar_outstanding"], "worklist": { "title": "Priority queue", "cadence": "Daily, 15 min", "sourceFact": "ar_outstanding", "pageSize": 500, "maxRows": 10000, "displayLimit": 50, "entityField": "partner", "documentField": "move", "amountField": "ar_outstanding", "overdueAmountField": "ar_overdue", "dueDateField": "due_date", "ownerField": "collection_owner", "statusField": "payment_state", "promiseDateField": "promise_date", "promiseAmountField": "promise_amount", "nextAction": "Preview outreach", "previewOnly": True, }, "question": "Which customer balances need an owner and a next action?", "deepLink": "/finance/ar-collections", }, { "key": "ap-spend", "label": "AP & Spend", "navLabel": "AP & Spend", "description": "Review supplier obligations before payment.", "mode": "workflow", "permissionKey": "spend", "composes": ["spend", "vendor_bills"], "factKeys": ["ap_outstanding"], "kpiKeys": ["ap_outstanding"], "worklist": { "title": "Payment queue", "cadence": "Daily, 15 min", "sourceFact": "ap_outstanding", "pageSize": 500, "maxRows": 10000, "displayLimit": 50, "entityField": "vendor", "documentField": "move", "amountField": "ap_outstanding", "dueDateField": "due_date", "ownerField": "ap_owner", "statusField": "payment_state", "nextAction": "Review payable", "previewOnly": False, "concentration": True, }, "question": "Which supplier obligations need review or payment action?", "deepLink": "/finance/ap-spend", }, { "key": "cash-o2c", "label": "Cash & O2C", "navLabel": "Cash & O2C", "description": "Track how invoiced demand converts into cash.", "mode": "dashboard", "permissionKey": "o2c", "composes": ["o2c", "ar"], "factKeys": ["invoiced_sales", "ar_outstanding"], "kpiKeys": ["invoiced_sales", "ar_outstanding"], "dashboard": { "basisNotice": "Mirror facts use the selected window. Cycle measures name their own LTM or point-in-time basis.", "sections": [ o2c.dashboard_contract(), financial.cash_cycle_dashboard_contract(), ], }, "question": "How is invoiced demand converting into collectible cash?", "deepLink": "/finance/cash-o2c", }, { "key": "pnl-gross-margin", "label": "Management P&L & Gross Margin", "navLabel": "P&L & Margin", "description": "Understand what drives operating performance.", "mode": "dashboard", "permissionKey": "financial", "composes": ["financial", "sales"], "factKeys": ["revenue", "opex", "commission_accrued"], "kpiKeys": ["revenue", "opex", "commission_accrued"], "dashboard": { "basisNotice": "Order, posted-GL, and commission actuals retain separate source bases and are never silently summed.", "sections": [ management.comparison_dashboard_contract(), financial.margin_dashboard_contract(), ], }, "question": "Where are revenue, operating expense, and selling cost moving?", "deepLink": "/finance/pnl-gross-margin", }, { "key": "procurement-inventory", "label": "Procurement & Inventory", "navLabel": "Procurement & Inventory", "description": "Prioritize buying and warehouse work from stock movements.", "mode": "workflow", "permissionKey": "procurement", "composes": ["procurement", "inventory"], "factKeys": ["stock_in", "stock_out", "stock_net"], "kpiKeys": [], "worklist": { "kind": "unavailable_requirements", "title": "Owned work requirements", "cadence": "Daily, 15 min", "basisNotice": ("Inventory and demand use one physical all-channel warehouse basis. " "Open purchase orders stay company-wide."), "signals": _owned_work_signals(), }, "question": "Which physical stock movements require a buying or warehouse action?", "deepLink": "/finance/procurement-inventory", }, { "key": "planning-data-health", "label": "Planning & Data Health", "navLabel": "Planning & Data Health", "description": "Assess whether planning inputs are ready to use.", "mode": "dashboard", "permissionKey": "health", "composes": ["planning", "health"], "factKeys": ["revenue", "invoiced_sales", "commission_accrued"], "kpiKeys": ["revenue", "invoiced_sales", "commission_accrued"], "dashboard": { "basisNotice": ("Actuals come only from governed Finance facts. Planning and close " "exceptions remain named gaps until their canonical mirror facts exist."), "sections": [ health.planning_dashboard_contract(), *health.data_health_dashboard_contracts(), ], }, "question": "Are planning inputs fresh, traceable, and reconciled?", "deepLink": "/finance/planning-data-health", }, ) def finance_group(): """Return a caller-owned copy of the one Finance navigation group.""" return deepcopy(FINANCE_GROUP) # Finance descriptors retain permission keys and fact composition after App retirement. def finance_applications(may_open=None): """Return immutable descriptors, optionally filtered through the request permission wall.""" rows = FINANCE_APPLICATIONS if may_open is not None: rows = tuple(app for app in rows if may_open(app["permissionKey"])) return deepcopy(list(rows)) def finance_application(key, may_open=None): """Resolve a direct-link descriptor without introducing a Finance-home aggregate.""" for app in FINANCE_APPLICATIONS: if app["key"] == key: if may_open is not None and not may_open(app["permissionKey"]): raise PermissionError(f"access to {key} is not granted") return deepcopy(app) raise KeyError(key) def finance_templates(may_open=None): """Keep the retired Finance template provider empty for legacy callers.""" return []