"""Enumerations and the seed line/KPI catalog for the finance-flux domain. The flux portal compares one accounting period against a baseline (month-over-month and year-over-year) for two statements — Balance Sheet and P&L — flagging line variances that breach configurable thresholds. ``SEED_LINE_DEFS`` mirrors the legacy portal's statement layout 1:1 so a fresh install reaches parity immediately; finance can then edit the catalog (labels / order / owners / per-line thresholds) and the account→line mapping in-app. The NS account→line mapping itself is NOT seeded here — it is auto-derived from the NetSuite chart of accounts by the sync engine (PR2) and adjusted by finance. """ from __future__ import annotations # ── Statements ────────────────────────────────────────────────────── STATEMENT_BS = "BS" STATEMENT_PL = "PL" STATEMENTS = (STATEMENT_BS, STATEMENT_PL) # ── Row types (display semantics within a statement) ──────────────── ROW_LINE = "line" # a pulled figure (sum of mapped accounts) ROW_SUBTOTAL = "subtotal" # computed section subtotal ROW_TOTAL = "total" # computed statement total / key total ROW_TYPES = (ROW_LINE, ROW_SUBTOTAL, ROW_TOTAL) # ── Period sync status ────────────────────────────────────────────── SYNC_PENDING = "pending" SYNC_SYNCING = "syncing" SYNC_SYNCED = "synced" SYNC_ERROR = "error" # ── Comparison modes ──────────────────────────────────────────────── COMPARE_MOM = "mom" # vs. prior accounting period COMPARE_YOY = "yoy" # vs. same period last year COMPARE_MODES = (COMPARE_MOM, COMPARE_YOY) # ── Follow-up priority ────────────────────────────────────────────── PRIORITY_HIGH = "high" PRIORITY_MEDIUM = "medium" PRIORITY_LOW = "low" PRIORITIES = (PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW) # ── Editorial card types ──────────────────────────────────────────── CARD_HIGHLIGHT = "highlight" # Summary page "Key Highlights" CARD_INSIGHT = "insight" # Insights page narrative cards CARD_TYPES = (CARD_HIGHLIGHT, CARD_INSIGHT) # ── Default thresholds (finance-configurable in finance_flux_config) ─ DEFAULT_AMOUNT_THRESHOLD = 10_000 # |Δ| > $10K DEFAULT_PCT_THRESHOLD = 20 # |Δ%| > 20% DEFAULT_CURRENCY = "USD" # ── Seed statement layout (line_key, label, section, row_type) ────── # sort_order is the list index * 10 (assigned in the migration). SEED_LINE_DEFS: list[dict] = [ # ===== Balance Sheet ===== # Current assets {"s": STATEMENT_BS, "k": "cash_and_equivalents", "l": "Cash and cash equivalents", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "short_term_investments", "l": "Short-term investments", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "accounts_receivable", "l": "Accounts receivable, net", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "deferred_commissions_current", "l": "Deferred commissions, current", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "prepaid_expenses", "l": "Prepaid expenses", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "other_receivable", "l": "Other receivable, net", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "other_current_assets", "l": "Other current assets", "sec": "CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "total_current_assets", "l": "Total Current Assets", "sec": "CURRENT ASSETS", "t": ROW_SUBTOTAL}, # Non-current assets {"s": STATEMENT_BS, "k": "property_equipment", "l": "Property and equipment, net", "sec": "NON-CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "rou_assets", "l": "Operating lease right-of-use assets", "sec": "NON-CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "long_term_prepaid", "l": "Long-term prepaid expenses", "sec": "NON-CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "deferred_commissions_noncurrent", "l": "Deferred commissions, non-current", "sec": "NON-CURRENT ASSETS", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "total_noncurrent_assets", "l": "Total Non-current Assets", "sec": "NON-CURRENT ASSETS", "t": ROW_SUBTOTAL}, {"s": STATEMENT_BS, "k": "total_assets", "l": "TOTAL ASSETS", "sec": "ASSETS", "t": ROW_TOTAL}, # Current liabilities {"s": STATEMENT_BS, "k": "accounts_payable", "l": "Accounts payable", "sec": "CURRENT LIABILITIES", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "accrued_compensation", "l": "Accrued compensation and benefits", "sec": "CURRENT LIABILITIES", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "taxes_payable", "l": "Taxes Payable", "sec": "CURRENT LIABILITIES", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "accrued_expenses_other", "l": "Accrued expenses and other payables", "sec": "CURRENT LIABILITIES", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "deferred_revenue_current", "l": "Deferred revenue, current", "sec": "CURRENT LIABILITIES", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "total_current_liabilities", "l": "Total Current Liabilities", "sec": "CURRENT LIABILITIES", "t": ROW_SUBTOTAL}, # Non-current liabilities {"s": STATEMENT_BS, "k": "operating_lease_liabilities_noncurrent", "l": "Operating lease liabilities, non-current", "sec": "NON-CURRENT LIABILITIES", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "total_noncurrent_liabilities", "l": "Total Non-current Liabilities", "sec": "NON-CURRENT LIABILITIES", "t": ROW_SUBTOTAL}, # Equity {"s": STATEMENT_BS, "k": "accumulated_deficit", "l": "Accumulated deficit", "sec": "STOCKHOLDERS' EQUITY", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "aoci", "l": "Accumulated other comprehensive loss", "sec": "STOCKHOLDERS' EQUITY", "t": ROW_LINE}, {"s": STATEMENT_BS, "k": "total_stockholders_equity", "l": "Total Stockholders' Equity", "sec": "STOCKHOLDERS' EQUITY", "t": ROW_SUBTOTAL}, {"s": STATEMENT_BS, "k": "total_liabilities_and_equity", "l": "TOTAL LIABILITIES AND EQUITY", "sec": "LIABILITIES AND EQUITY", "t": ROW_TOTAL}, # ===== P&L ===== {"s": STATEMENT_PL, "k": "revenue_license_subscription", "l": "Revenue — License and Subscription", "sec": "REVENUE", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "revenue_tidb_cloud", "l": "Revenue — TiDB Cloud", "sec": "REVENUE", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "revenue_professional_services", "l": "Revenue — Professional Services", "sec": "REVENUE", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "total_revenue", "l": "Total Revenue", "sec": "REVENUE", "t": ROW_SUBTOTAL}, {"s": STATEMENT_PL, "k": "infrastructure_hosting", "l": "Infrastructure and hosting costs", "sec": "COST OF REVENUE", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "support_customer_success", "l": "Support and customer success", "sec": "COST OF REVENUE", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "total_cost_of_revenue", "l": "Total Cost of Revenue", "sec": "COST OF REVENUE", "t": ROW_SUBTOTAL}, {"s": STATEMENT_PL, "k": "gross_profit", "l": "GROSS PROFIT", "sec": "GROSS PROFIT", "t": ROW_TOTAL}, {"s": STATEMENT_PL, "k": "research_development", "l": "Research and development", "sec": "OPERATING EXPENSES", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "sales_marketing", "l": "Sales and marketing", "sec": "OPERATING EXPENSES", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "general_administrative", "l": "General and administrative", "sec": "OPERATING EXPENSES", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "total_operating_expenses", "l": "Total Operating Expenses", "sec": "OPERATING EXPENSES", "t": ROW_SUBTOTAL}, {"s": STATEMENT_PL, "k": "operating_income", "l": "OPERATING INCOME / (LOSS)", "sec": "OPERATING INCOME", "t": ROW_TOTAL}, {"s": STATEMENT_PL, "k": "interest_investment_income", "l": "Interest and investment income", "sec": "OTHER INCOME / (EXPENSE)", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "fx_gain_loss", "l": "Foreign exchange gain / (loss)", "sec": "OTHER INCOME / (EXPENSE)", "t": ROW_LINE}, {"s": STATEMENT_PL, "k": "total_other_income", "l": "Total Other Income", "sec": "OTHER INCOME / (EXPENSE)", "t": ROW_SUBTOTAL}, {"s": STATEMENT_PL, "k": "net_income", "l": "NET INCOME / (LOSS)", "sec": "NET INCOME", "t": ROW_TOTAL}, ] # ── Seed KPI catalog (Summary page cards) ─────────────────────────── # ``source`` is the line_key whose computed total feeds the card. # higher_is_better drives the good/bad tone of the variance. SEED_KPI_DEFS: list[dict] = [ {"k": "total_assets", "l": "Total Assets", "s": STATEMENT_BS, "src": "total_assets", "hib": True}, {"k": "total_revenue", "l": "Total Revenue", "s": STATEMENT_PL, "src": "total_revenue", "hib": True}, {"k": "gross_profit", "l": "Gross Profit", "s": STATEMENT_PL, "src": "gross_profit", "hib": True}, {"k": "operating_income", "l": "Operating Income / (Loss)", "s": STATEMENT_PL, "src": "operating_income", "hib": True}, {"k": "net_income", "l": "Net Income / (Loss)", "s": STATEMENT_PL, "src": "net_income", "hib": True}, ]