fsanyoto commited on
Commit
7d8fd31
Β·
verified Β·
1 Parent(s): b96bb76

Deploy Data Management Platform (rename + sales forecast removed)

Browse files
Files changed (3) hide show
  1. app.py +25 -51
  2. core/registry.py +21 -14
  3. ui/session.py +3 -0
app.py CHANGED
@@ -911,7 +911,9 @@ def _process_deeplink():
911
  st.session_state['nav_cur'] = '__settings__'
912
  elif page:
913
  row = registry.BY_KEY.get(page)
914
- if row and row.get('nav', True):
 
 
915
  st.session_state['nav_cur'] = row['label']
916
  if entity:
917
  kind, _, ident = str(entity).partition(':')
@@ -7407,42 +7409,31 @@ def page_settings():
7407
  st.caption(f'Active scope: {pick_bu} Β· {pick_dm}. Dashboards re-pull for a new scope in the '
7408
  'background; the pages keep serving until the fresh data lands.')
7409
 
7410
- # ---- Modules (ex-Library page, folded in β€” owner 2026-07-23): every module with an
7411
  # enable checkbox; a per-user preference layered on the permission gate, never wider.
 
 
7412
  section('Modules', help='Tick a module to show it in your Workflows menu; untick to hide '
7413
  'it. Definitions and data are untouched β€” re-enable anytime.')
7414
  _allowed = allowed_modules()
7415
- rows = [m for m in registry.REGISTRY if m.get('nav', True)
7416
  and (_allowed is None or m['key'] in _allowed)]
7417
  enabled = user_enabled_modules()
7418
- active = [m for m in rows if not m.get('archived')]
7419
- archived = [m for m in rows if m.get('archived')]
7420
- # default (never picked): all ACTIVE modules on, ARCHIVED off β€” ticking an archived module
7421
- # restores it into THIS user's menu only (owner directive 2026-07-23).
7422
- cur = ({m['key'] for m in active} if enabled is None
7423
  else (enabled & {m['key'] for m in rows}))
7424
  picked = set()
7425
  cols = st.columns(3)
7426
- for i, m in enumerate(active):
7427
  with cols[i % 3]:
7428
  if st.checkbox(m['label'], value=m['key'] in cur, key=f"lib_{m['key']}",
7429
  help=m.get('note', '')):
7430
  picked.add(m['key'])
7431
- if archived:
7432
- section('Archived', help='Retired from the default menus (owner 2026-07-23) β€” the code, '
7433
- 'data layer and validations stay live. Tick one to restore it '
7434
- 'into your menu; it stays archived for everyone else.')
7435
- cols = st.columns(3)
7436
- for i, m in enumerate(archived):
7437
- with cols[i % 3]:
7438
- if st.checkbox(m['label'], value=m['key'] in cur, key=f"lib_{m['key']}",
7439
- help=m.get('note', '')):
7440
- picked.add(m['key'])
7441
  if picked != cur:
7442
  set_user_enabled_modules(picked)
7443
  st.rerun() # menus update immediately
7444
- st.caption(f'{len(picked & {m["key"] for m in active})} of {len(active)} active modules '
7445
- f'enabled Β· {len(picked & {m["key"] for m in archived})} archived restored.')
7446
 
7447
 
7448
 
@@ -7752,10 +7743,9 @@ def _digest_ticker():
7752
 
7753
 
7754
  def _prewarm_thunks(tid, dm):
7755
- # NOTE: archived modules' bundles (backorders/pricecomp/o2c/bookings/spend/expenses)
7756
- # are NOT prewarmed β€” a user who restores one waits one cold load instead of every
7757
- # boot paying six Odoo pulls nobody sees (owner archive directive 2026-07-23).
7758
- _hdf, _hdt = next(iter(P.period_options().values())) # Data Health default window
7759
  return [
7760
  ('Sales', lambda: sales_bundle.refresh(tid, dm)),
7761
  ('Customers', lambda: cust_bundle.refresh(tid, None, dm)),
@@ -7763,27 +7753,8 @@ def _prewarm_thunks(tid, dm):
7763
  ('Agents', lambda: agent_rollup_c.refresh(tid, dm)),
7764
  ('Agent list', lambda: agent_options_c.refresh(tid)),
7765
  ('Map', lambda: map_locations_c.refresh(tid, None)),
7766
- ('SKU', lambda: prod_bundle.refresh(tid, dm)),
7767
- ('SKU search', lambda: sku_all_ytd.refresh(tid)),
7768
- ('SKU directory', lambda: prod_directory.refresh(tid)),
7769
- ('SKU coverage', lambda: prod_coverage.refresh(tid)),
7770
- ('Financial', lambda: fin_bundle.refresh(tid)),
7771
- ('Margin bridge', lambda: fin_bridge_c.refresh(tid, 'ytd')),
7772
- ('Margin bridge LTM', lambda: fin_bridge_c.refresh(tid, 'ltm')),
7773
- ('Pricing', lambda: pricing_bundle.refresh(tid, 'cogs')),
7774
- ('Inventory', lambda: inventory_bundle.refresh()),
7775
- ('Reprice toolkit', lambda: reprice_bundle.refresh()),
7776
- ('Price discipline', lambda: discipline_bundle.refresh(tid)),
7777
- ('SKU complexity', lambda: complexity_bundle.refresh()),
7778
- ('Overstock', lambda: overstock_bundle.refresh()),
7779
- ('Overstock cohorts', lambda: overstock_cohort.refresh()),
7780
- ('Inventory analytics', lambda: inv_analytics.refresh(180, 25)),
7781
- ('Procurement / Vendors', lambda: proc_bundle.refresh()),
7782
- ('Warehouse', lambda: wh_bundle.refresh()),
7783
- ('Assortment', lambda: assort_bundle.refresh(tid)),
7784
  ('Collections', lambda: ar_bundle.refresh()),
7785
- ('Returns', lambda: returns_bundle.refresh()),
7786
- ('Data Health', lambda: health_bundle.refresh(_hdf, _hdt)),
7787
  ]
7788
 
7789
 
@@ -8083,16 +8054,19 @@ def main():
8083
  # allowed_modules permission gate).
8084
  _allowed_mods = allowed_modules()
8085
  _lib_enabled = user_enabled_modules()
8086
- # ARCHIVED modules (owner 2026-07-23) are hidden from menus BY DEFAULT; a user's
8087
- # explicit Library selection overrides (ticking an archived module restores it for them).
 
8088
  nav = [m for m in registry.REGISTRY
8089
  if (_allowed_mods is None or m['key'] in _allowed_mods) and m.get('nav', True)
8090
- and not m.get('parent')
8091
- and ((m['key'] in _lib_enabled) if _lib_enabled is not None
8092
- else not m.get('archived'))]
8093
  if not nav:
 
 
8094
  nav = [m for m in registry.REGISTRY
8095
- if m.get('nav', True) and not m.get('parent') and not m.get('archived')]
 
8096
  w_labels = [m['label'] for m in nav]
8097
  # Analyst-spawned dashboards (views.json) join the same dropdown. BU-scoped users
8098
  # don't see them: a saved query carries its own team_id, so a consolidated view would
 
911
  st.session_state['nav_cur'] = '__settings__'
912
  elif page:
913
  row = registry.BY_KEY.get(page)
914
+ # archived modules are invisible to everyone (owner 2026-07-27) β€” a deep link to one
915
+ # falls through to the normal landing instead of resurrecting the page.
916
+ if row and row.get('nav', True) and not row.get('archived'):
917
  st.session_state['nav_cur'] = row['label']
918
  if entity:
919
  kind, _, ident = str(entity).partition(':')
 
7409
  st.caption(f'Active scope: {pick_bu} Β· {pick_dm}. Dashboards re-pull for a new scope in the '
7410
  'background; the pages keep serving until the fresh data lands.')
7411
 
7412
+ # ---- Modules (ex-Library page, folded in β€” owner 2026-07-23): every ACTIVE module with an
7413
  # enable checkbox; a per-user preference layered on the permission gate, never wider.
7414
+ # ARCHIVED modules are invisible to EVERYONE β€” no restore checkbox (owner 2026-07-27;
7415
+ # supersedes the 2026-07-23 per-user-restore semantics). Un-archiving = a registry edit.
7416
  section('Modules', help='Tick a module to show it in your Workflows menu; untick to hide '
7417
  'it. Definitions and data are untouched β€” re-enable anytime.')
7418
  _allowed = allowed_modules()
7419
+ rows = [m for m in registry.REGISTRY if m.get('nav', True) and not m.get('archived')
7420
  and (_allowed is None or m['key'] in _allowed)]
7421
  enabled = user_enabled_modules()
7422
+ # default (never picked): every active module on. A stored selection can only NARROW
7423
+ # this set β€” stale archived keys in old selections drop out via the intersection.
7424
+ cur = ({m['key'] for m in rows} if enabled is None
 
 
7425
  else (enabled & {m['key'] for m in rows}))
7426
  picked = set()
7427
  cols = st.columns(3)
7428
+ for i, m in enumerate(rows):
7429
  with cols[i % 3]:
7430
  if st.checkbox(m['label'], value=m['key'] in cur, key=f"lib_{m['key']}",
7431
  help=m.get('note', '')):
7432
  picked.add(m['key'])
 
 
 
 
 
 
 
 
 
 
7433
  if picked != cur:
7434
  set_user_enabled_modules(picked)
7435
  st.rerun() # menus update immediately
7436
+ st.caption(f'{len(picked)} of {len(rows)} modules enabled.')
 
7437
 
7438
 
7439
 
 
7743
 
7744
 
7745
  def _prewarm_thunks(tid, dm):
7746
+ # ONLY the keep-list pages' bundles are prewarmed (owner archive pass 2026-07-27:
7747
+ # Sales + Customers family + Agents + Procurement + Collections). Archived modules'
7748
+ # bundles never warm β€” they are invisible to everyone, so nobody pays their Odoo pulls.
 
7749
  return [
7750
  ('Sales', lambda: sales_bundle.refresh(tid, dm)),
7751
  ('Customers', lambda: cust_bundle.refresh(tid, None, dm)),
 
7753
  ('Agents', lambda: agent_rollup_c.refresh(tid, dm)),
7754
  ('Agent list', lambda: agent_options_c.refresh(tid)),
7755
  ('Map', lambda: map_locations_c.refresh(tid, None)),
7756
+ ('Procurement', lambda: proc_bundle.refresh()),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7757
  ('Collections', lambda: ar_bundle.refresh()),
 
 
7758
  ]
7759
 
7760
 
 
8054
  # allowed_modules permission gate).
8055
  _allowed_mods = allowed_modules()
8056
  _lib_enabled = user_enabled_modules()
8057
+ # ARCHIVED modules (owner 2026-07-27) are invisible to EVERYONE β€” excluded from the
8058
+ # nav unconditionally. A stored Settings>Modules selection can only NARROW the active
8059
+ # set, never restore an archived module (supersedes the 2026-07-23 restore semantics).
8060
  nav = [m for m in registry.REGISTRY
8061
  if (_allowed_mods is None or m['key'] in _allowed_mods) and m.get('nav', True)
8062
+ and not m.get('parent') and not m.get('archived')
8063
+ and (_lib_enabled is None or m['key'] in _lib_enabled)]
 
8064
  if not nav:
8065
+ # a stored selection that deselects everything β€” fall back to the user's full
8066
+ # PERMITTED active set (fail-closed: never wider than allowed_modules).
8067
  nav = [m for m in registry.REGISTRY
8068
+ if (_allowed_mods is None or m['key'] in _allowed_mods)
8069
+ and m.get('nav', True) and not m.get('parent') and not m.get('archived')]
8070
  w_labels = [m['label'] for m in nav]
8071
  # Analyst-spawned dashboards (views.json) join the same dropdown. BU-scoped users
8072
  # don't see them: a saved query carries its own team_id, so a consolidated view would
core/registry.py CHANGED
@@ -14,7 +14,14 @@ Fields:
14
  parent set -> this row is a SUB-MODULE of <parent key>: it leaves the Workflows dropdown and
15
  renders as a sub-nav button when its parent (or a sibling) is the active module; a
16
  parent grant covers its sub-modules (owner nav redesign 2026-07-23)
17
- archived True -> hidden from menus by default; restorable per user (Settings > Modules)
 
 
 
 
 
 
 
18
  note one-line scope note shown in the UI / docs
19
  """
20
  REGISTRY = [
@@ -46,30 +53,30 @@ REGISTRY = [
46
  'note': 'Every customer pinned at its exact address; box-select to export / reassign β€” by BU.'},
47
  {'key': 'agent', 'label': 'Agents', 'brand': True, 'hq': False, 'validate': True,
48
  'note': 'Per-agent book: sales (custom dates), returns, top SKUs, full customer list incl. inactive. Returns consolidated.'},
49
- {'key': 'products', 'label': 'SKU', 'brand': True, 'hq': False, 'validate': True,
50
  'note': 'SKU movers, zombies, velocity, coverage, drawers β€” by BU (sales-derived).'},
51
- {'key': 'assortment', 'label': 'Assortment', 'brand': True, 'hq': False, 'validate': True,
52
  'note': 'Facet-level performance (category/color/occasion/collection/season) + season readiness β€” by BU.'},
53
- {'key': 'financial', 'label': 'Financial', 'brand': True, 'hq': False, 'validate': True,
54
  'note': 'Gross margin by BU/category/SKU. Cash-conversion cycle is HQ-consolidated.'},
55
- {'key': 'pricing', 'label': 'Pricing', 'brand': True, 'hq': False, 'validate': True,
56
  'note': 'Per-SKU margin/markup/LTM sales + allocated net P&L (channel-rate cost-to-SKU) for pricing decisions.'},
57
- {'key': 'management', 'label': 'Management P&L', 'brand': False, 'hq': True, 'validate': True,
58
- 'nav': False, # rendered INSIDE the Financial module (view toggle) β€” no own nav entry
59
  'note': 'Operating-model management income statements (FFS/RI/GD/BU-M) reproduced from raw Odoo, Sep-2024+.'},
60
- {'key': 'inventory', 'label': 'Inventory', 'brand': False, 'hq': False, 'validate': True,
61
  'note': 'On-hand stock is physically consolidated (shared warehouse); not DBA-split.'},
62
  {'key': 'procurement', 'label': 'Procurement', 'brand': False, 'hq': False, 'validate': True,
63
  'note': 'Biweekly buy list: lead-time-cover trigger, 8-month demand baseline + YTD trend, by supplier.'},
64
- {'key': 'vendor', 'label': 'Vendors', 'brand': False, 'hq': False, 'validate': False,
65
  'note': 'Vendor master data + the SKUs each supplies; multiple-vendor / cheapest-price view.'},
66
- {'key': 'warehouse', 'label': 'Warehouse', 'brand': False, 'hq': False, 'validate': True,
67
  'note': 'Movement & efficiency: on-time ship, Pick-Pack-Ship cycle times, throughput, backlog age, shrinkage. Physical ops (consolidated).'},
68
  {'key': 'ar', 'label': 'Collections', 'brand': False, 'hq': True, 'validate': True,
69
  'note': 'Receivables are company-level (consolidated).'},
70
- {'key': 'returns', 'label': 'Returns', 'brand': False, 'hq': True, 'validate': True,
71
  'note': 'Credit-note lens: refund concentration by SKU (quality) and customer (behavior). Company-level.'},
72
- {'key': 'outreach', 'label': 'Outreach', 'brand': True, 'hq': False, 'validate': False,
73
  'note': 'Campaign emails to customer segments: templates, suppression, send log, revenue attribution. Sending is admin-gated behind SAFE_MODE.'},
74
  {'key': 'backorders', 'label': 'Backorders', 'brand': True, 'hq': False, 'validate': True, 'archived': True,
75
  'note': 'Confirmed-undelivered order lines aged vs promise date, valued, with a supply-aware next action per row (ship / expedite / call). Wholesale scope.'},
@@ -81,11 +88,11 @@ REGISTRY = [
81
  'note': 'Pre-season booking coverage: cumulative booked $ for Aug-Dec delivery vs last year same-week; category TY-vs-LY-as-of-date. The container-program decision, months ahead.'},
82
  {'key': 'spend', 'label': 'Spend & Payables', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
83
  'note': 'Vendor-bill side: payment-terms capture (early-pay cash surrendered), duplicate-bill review, the opex spend cube (fragmentation, consolidate+rebid) and freight recovery. Company-level.'},
84
- {'key': 'complexity', 'label': 'SKU Complexity', 'brand': False, 'hq': False, 'validate': True,
85
  'note': 'BCG tail rationalization: every SKU re-costed by ACTIVITY (lines, picks, returns) + 25%/yr carrying; KILL candidates rest on hard math (GM minus carrying), REVIEW on the pooled activity estimate. All-channel.'},
86
  {'key': 'expenses', 'label': 'Expenses', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
87
  'note': 'Operating expense from the GL (all expense-type accounts; COGS excluded): trend, operating leverage (opex % of revenue), the YoY cost bridge, XmR control-limit spike watch list, fixed/variable split and a drill-to-ledger category directory. Company-level.'},
88
- {'key': 'health', 'label': 'Data Health', 'brand': False, 'hq': True, 'validate': True,
89
  'note': 'Close/reconciliation scan; period-filtered, mostly company-level. ARCHITECTURE '
90
  '(owner 2026-07-23): every discrepancy / potential-error marker lives here β€” '
91
  'procurement mapping gaps, count-trust (unverified on-hand counts), untracked-on-'
 
14
  parent set -> this row is a SUB-MODULE of <parent key>: it leaves the Workflows dropdown and
15
  renders as a sub-nav button when its parent (or a sibling) is the active module; a
16
  parent grant covers its sub-modules (owner nav redesign 2026-07-23)
17
+ archived True -> RETIRED from the UI for EVERYONE (owner 2026-07-27, supersedes the
18
+ 2026-07-23 per-user-restore semantics): no nav entry, no Settings>Modules checkbox,
19
+ prewarm and validate.py skip it. Code and data layer stay in the repo but are NOT
20
+ maintained β€” spend no effort on archived modules until the owner un-archives.
21
+ 2026-07-23 pass: backorders, pricecomp, o2c, bookings, spend, expenses.
22
+ 2026-07-27 pass (keep = Sales + Customers family + Agents + Procurement +
23
+ Collections + Analyst/plumbing): products, assortment, financial, management,
24
+ pricing, inventory, vendor, warehouse, returns, outreach, complexity, health.
25
  note one-line scope note shown in the UI / docs
26
  """
27
  REGISTRY = [
 
53
  'note': 'Every customer pinned at its exact address; box-select to export / reassign β€” by BU.'},
54
  {'key': 'agent', 'label': 'Agents', 'brand': True, 'hq': False, 'validate': True,
55
  'note': 'Per-agent book: sales (custom dates), returns, top SKUs, full customer list incl. inactive. Returns consolidated.'},
56
+ {'key': 'products', 'label': 'SKU', 'brand': True, 'hq': False, 'validate': True, 'archived': True,
57
  'note': 'SKU movers, zombies, velocity, coverage, drawers β€” by BU (sales-derived).'},
58
+ {'key': 'assortment', 'label': 'Assortment', 'brand': True, 'hq': False, 'validate': True, 'archived': True,
59
  'note': 'Facet-level performance (category/color/occasion/collection/season) + season readiness β€” by BU.'},
60
+ {'key': 'financial', 'label': 'Financial', 'brand': True, 'hq': False, 'validate': True, 'archived': True,
61
  'note': 'Gross margin by BU/category/SKU. Cash-conversion cycle is HQ-consolidated.'},
62
+ {'key': 'pricing', 'label': 'Pricing', 'brand': True, 'hq': False, 'validate': True, 'archived': True,
63
  'note': 'Per-SKU margin/markup/LTM sales + allocated net P&L (channel-rate cost-to-SKU) for pricing decisions.'},
64
+ {'key': 'management', 'label': 'Management P&L', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
65
+ 'nav': False, # rendered INSIDE the Financial module (view toggle) β€” archived WITH financial
66
  'note': 'Operating-model management income statements (FFS/RI/GD/BU-M) reproduced from raw Odoo, Sep-2024+.'},
67
+ {'key': 'inventory', 'label': 'Inventory', 'brand': False, 'hq': False, 'validate': True, 'archived': True,
68
  'note': 'On-hand stock is physically consolidated (shared warehouse); not DBA-split.'},
69
  {'key': 'procurement', 'label': 'Procurement', 'brand': False, 'hq': False, 'validate': True,
70
  'note': 'Biweekly buy list: lead-time-cover trigger, 8-month demand baseline + YTD trend, by supplier.'},
71
+ {'key': 'vendor', 'label': 'Vendors', 'brand': False, 'hq': False, 'validate': False, 'archived': True,
72
  'note': 'Vendor master data + the SKUs each supplies; multiple-vendor / cheapest-price view.'},
73
+ {'key': 'warehouse', 'label': 'Warehouse', 'brand': False, 'hq': False, 'validate': True, 'archived': True,
74
  'note': 'Movement & efficiency: on-time ship, Pick-Pack-Ship cycle times, throughput, backlog age, shrinkage. Physical ops (consolidated).'},
75
  {'key': 'ar', 'label': 'Collections', 'brand': False, 'hq': True, 'validate': True,
76
  'note': 'Receivables are company-level (consolidated).'},
77
+ {'key': 'returns', 'label': 'Returns', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
78
  'note': 'Credit-note lens: refund concentration by SKU (quality) and customer (behavior). Company-level.'},
79
+ {'key': 'outreach', 'label': 'Outreach', 'brand': True, 'hq': False, 'validate': False, 'archived': True,
80
  'note': 'Campaign emails to customer segments: templates, suppression, send log, revenue attribution. Sending is admin-gated behind SAFE_MODE.'},
81
  {'key': 'backorders', 'label': 'Backorders', 'brand': True, 'hq': False, 'validate': True, 'archived': True,
82
  'note': 'Confirmed-undelivered order lines aged vs promise date, valued, with a supply-aware next action per row (ship / expedite / call). Wholesale scope.'},
 
88
  'note': 'Pre-season booking coverage: cumulative booked $ for Aug-Dec delivery vs last year same-week; category TY-vs-LY-as-of-date. The container-program decision, months ahead.'},
89
  {'key': 'spend', 'label': 'Spend & Payables', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
90
  'note': 'Vendor-bill side: payment-terms capture (early-pay cash surrendered), duplicate-bill review, the opex spend cube (fragmentation, consolidate+rebid) and freight recovery. Company-level.'},
91
+ {'key': 'complexity', 'label': 'SKU Complexity', 'brand': False, 'hq': False, 'validate': True, 'archived': True,
92
  'note': 'BCG tail rationalization: every SKU re-costed by ACTIVITY (lines, picks, returns) + 25%/yr carrying; KILL candidates rest on hard math (GM minus carrying), REVIEW on the pooled activity estimate. All-channel.'},
93
  {'key': 'expenses', 'label': 'Expenses', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
94
  'note': 'Operating expense from the GL (all expense-type accounts; COGS excluded): trend, operating leverage (opex % of revenue), the YoY cost bridge, XmR control-limit spike watch list, fixed/variable split and a drill-to-ledger category directory. Company-level.'},
95
+ {'key': 'health', 'label': 'Data Health', 'brand': False, 'hq': True, 'validate': True, 'archived': True,
96
  'note': 'Close/reconciliation scan; period-filtered, mostly company-level. ARCHITECTURE '
97
  '(owner 2026-07-23): every discrepancy / potential-error marker lives here β€” '
98
  'procurement mapping gaps, count-trust (unverified on-hand counts), untracked-on-'
ui/session.py CHANGED
@@ -78,6 +78,9 @@ def first_allowed_module():
78
  am = allowed_modules()
79
  if am is None:
80
  return None
 
 
 
81
  for archived_ok in (False, True): # non-archived first; archived only as last resort
82
  for m in registry.REGISTRY:
83
  if (m.get('nav', True) and m['key'] in am
 
78
  am = allowed_modules()
79
  if am is None:
80
  return None
81
+ # Archived modules are invisible to everyone (owner 2026-07-27); the archived_ok=True leg
82
+ # survives ONLY as a misconfiguration fail-safe β€” a user whose ENTIRE grant is archived
83
+ # still lands somewhere instead of a bricked login. Nav never shows archived entries.
84
  for archived_ok in (False, True): # non-archived first; archived only as last resort
85
  for m in registry.REGISTRY:
86
  if (m.get('nav', True) and m['key'] in am