fsanyoto commited on
Commit
23c7452
·
verified ·
1 Parent(s): 7d8fd31

Deploy Data Management Platform (rename + sales forecast removed)

Browse files
aios_grid_component/index.html CHANGED
The diff for this file is too large to render. See raw diff
 
aios_grid_embed.html CHANGED
The diff for this file is too large to render. See raw diff
 
app.py CHANGED
@@ -5558,6 +5558,29 @@ def _cl_handle_one(event, uname, allowed_pids, fields, measure_keys=(),
5558
  ws['fields'][key] = field
5559
  return True
5560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5561
  if kind == 'add_to_list':
5562
  # "Add to list" (owner item 6): a view's current matches become fixed cohort members.
5563
  #
@@ -5738,6 +5761,87 @@ def _cl_grid_colcfg(label, extra_help=None):
5738
  return st.column_config.TextColumn(label, pinned=pin, help=extra_help)
5739
 
5740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5741
  def page_cohort():
5742
  """Cohort — the SAME table as Customer over a FIXED set of customers.
5743
 
@@ -5829,54 +5933,18 @@ def page_cohort():
5829
  f"24 months, so not shown.")
5830
 
5831
  try:
5832
- import aios_grid
5833
- _ws = _cl_table_workspace(uname)
5834
- # Membership scoped to the CALLER's whole book (not to this cohort's rows) — a condition
5835
- # on ANOTHER cohort has to be answerable from this page too, and the Cohorts column has
5836
- # to be able to say a customer is also in one.
5837
- _pool_pids = {r['pid'] for r in rows}
5838
- _cohort_lists = [{'id': cid, 'name': c.get('name') or cid,
5839
- 'pids': [p for p in (c.get('members') or []) if p in _pool_pids]}
5840
- for cid, c in sorted(cohort_mod.visible(uname, _pool_pids).items(),
5841
- key=lambda kv: (kv[1].get('name') or '').lower())]
5842
- _fields = aios_grid.fields_from_workspace(_ws, cohorts=bool(_cohort_lists))
5843
- st.markdown("<span class='aios-grid-host-marker aios-grid-host-cohort'></span>",
5844
- unsafe_allow_html=True)
5845
- # storageKey is per COHORT: view state belongs to the list you are looking at, and one
5846
- # shared key would leak one cohort's filters onto every other.
5847
- _views = aios_grid.views_from_defs({}, _ws.get('views'), _fields)
5848
- # CG-8 rides here too, and not as a nicety: Cohort shares the SAME saved views as Data,
5849
- # so a view carrying a measure condition would have that condition stripped by the next
5850
- # autosave here (an unknown colId is dropped) if this page did not know measures exist.
5851
- # The zero-group is reconstructed over the COHORT's rows, which is what this table holds.
5852
- _measures = _cl_measure_offer(team_id)
5853
- _pend_cfg = _cl_pending_view(st.session_state.get(f'cohort_grid_{active}'))
5854
- _cohort_pids = {r['pid'] for r in crows}
5855
- _msets = _cl_resolve_measures(_views, _pend_cfg, team_id, _cohort_pids, b['pulled_at'])
5856
- # Formula-measure columns (owner item 7) — values over THIS cohort's rows.
5857
- _derived = aios_grid.cohort_cells(_cohort_lists)
5858
- for _pid, _cells in _cl_measure_columns(_fields, team_id, _cohort_pids,
5859
- b['pulled_at']).items():
5860
- _derived.setdefault(_pid, {}).update(_cells)
5861
- ev = aios_grid.render(
5862
- aios_grid.rows_from_pool(crows, _fields, _ws.get('overlays'), derived=_derived),
5863
- _fields,
5864
- workspace={'storageKey': (f"royal-imports:cohort:{uname}:{active}:"
5865
- f"{team_id if team_id is not None else 'all'}"),
5866
- 'views': _views,
5867
- # Owner items 4+6: the cohort IS the row set — no view switcher here.
5868
- 'hideViews': True,
5869
- # Cohort shares its saved views with Data, so a view carrying a cohort
5870
- # condition must find its vocabulary here too — otherwise this page's
5871
- # next autosave would drop the condition as naming an unknown list.
5872
- 'lists': _cohort_lists},
5873
- key=f'cohort_grid_{active}', height=640, user_options=_assignable_people(),
5874
- measures=_measures, measure_sets=_msets, today=str(P.today()))
5875
- if _cl_handle_grid_event(ev, uname, set(by_pid), _fields,
5876
- measure_keys={m['key'] for m in _measures},
5877
- resolved_ids=set(_msets),
5878
- cohort_ids={c['id'] for c in _cohort_lists},
5879
- measure_offer=_measures):
5880
  st.rerun()
5881
  except Exception as _e:
5882
  _tel.error('cohort:grid', _e)
@@ -5925,61 +5993,20 @@ def page_customer_data():
5925
  # views/rule-engine workbench BELOW serves as the fallback — the page never hard-fails.
5926
  _embed_ok = False
5927
  try:
5928
- import aios_grid
5929
- _table_ws = _cl_table_workspace(uname)
5930
- # The view menu's "Add to list" targets (owner item 6), the vocabulary of the
5931
- # `Where [Cohort] [is any of] [...]` condition (owner item 5), AND — since 2026-07-27 —
5932
- # the values of the derived Cohorts COLUMN. One array, so what the picker offers, what
5933
- # the engine tests and what the cell says cannot disagree. `visible()` scopes each
5934
- # membership to what this caller may see, so `pids` is already a permission-safe set.
5935
- _cohort_lists = [{'id': cid, 'name': c.get('name') or cid,
5936
- 'pids': [p for p in (c.get('members') or []) if p in by_pid]}
5937
- for cid, c in sorted(cohort_mod.visible(uname, set(by_pid)).items(),
5938
- key=lambda kv: (kv[1].get('name') or '').lower())]
5939
- _grid_fields = aios_grid.fields_from_workspace(_table_ws, cohorts=bool(_cohort_lists))
5940
- _grid_views = aios_grid.views_from_defs(
5941
- defs, _table_ws.get('views'), _grid_fields)
5942
- _grid_workspace = {
5943
- 'storageKey': (f"royal-imports:customer-list:{uname}:"
5944
- f"{team_id if team_id is not None else 'all'}:"
5945
- f"{agent or 'all'}"),
5946
- 'views': _grid_views,
5947
- 'lists': _cohort_lists,
5948
- }
5949
- # Page-scoped CSS sentinel: removes the dashboard max-width so the component follows
5950
- # the main column when the owner collapses/opens Streamlit navigation.
5951
- st.markdown("<span class='aios-grid-host-marker'></span>", unsafe_allow_html=True)
5952
- # CG-8 — measure conditions ("Where Sales, in the last 90 days, > 5,000"). Resolved
5953
- # HERE, server-side, to a set of pids per condition; the client engine then treats that
5954
- # set as a membership test and the table stays whole-book, so its counts stay its own.
5955
- #
5956
- # The pending event is read from the component's OWN return value at the top of this
5957
- # run, so a condition the user just typed is answered in the same run that delivers it.
5958
- _measures = _cl_measure_offer(team_id)
5959
- _measure_sets = _cl_resolve_measures(
5960
- _grid_views, _cl_pending_view(st.session_state.get('cl_aios_grid')),
5961
- team_id, set(by_pid), b['pulled_at'])
5962
- # Formula-measure columns (owner item 7): host-computed values, merged with the cohort
5963
- # cells into ONE derived dict — the same read-only channel, never the cached pool rows.
5964
- _derived = aios_grid.cohort_cells(_cohort_lists)
5965
- for _pid, _cells in _cl_measure_columns(_grid_fields, team_id, set(by_pid),
5966
- b['pulled_at']).items():
5967
- _derived.setdefault(_pid, {}).update(_cells)
5968
- _grid_event = aios_grid.render(
5969
- aios_grid.rows_from_pool(rows, _grid_fields, _table_ws.get('overlays'),
5970
- derived=_derived),
5971
- _grid_fields, workspace=_grid_workspace, key='cl_aios_grid', height=760,
5972
- user_options=_assignable_people(),
5973
- measures=_measures, measure_sets=_measure_sets, today=str(P.today()))
5974
  _embed_ok = True
5975
  # NOTE the return-value contract: True means "re-render from server state",
5976
  # not "handled". A view autosave persists and returns False on purpose.
5977
- if _cl_handle_grid_event(
5978
- _grid_event, uname, set(by_pid), _grid_fields,
5979
- measure_keys={m['key'] for m in _measures},
5980
- resolved_ids=set(_measure_sets),
5981
- cohort_ids={c['id'] for c in _grid_workspace['lists']},
5982
- measure_offer=_measures):
5983
  st.rerun()
5984
  except Exception as _grid_error:
5985
  _tel.error('customer-list:grid', _grid_error)
 
5558
  ws['fields'][key] = field
5559
  return True
5560
 
5561
+ if kind == 'field_delete':
5562
+ # Delete a USER-CREATED column outright (owner gap closed 2026-07-27). The prefix IS
5563
+ # the permission: only the created strata (`custom_` overlay fields, `measure_` formula
5564
+ # columns) are deletable — a base field's key fails the prefix test no matter what the
5565
+ # browser claims, so the table's contract cannot be deleted from the client. The store
5566
+ # scrubs the field's stored cell values with it (delete_table_field); views naming the
5567
+ # key self-heal on their next autosave, the rule every stale colId already rides.
5568
+ key = str(event.get('key') or '')[:80]
5569
+ import aios_grid as _ag3
5570
+ if not (key.startswith('custom_') or key.startswith(_ag3.MEASURE_FIELD_PREFIX)):
5571
+ return False
5572
+ if store.available():
5573
+ cl_mod.delete_table_field(uname, key)
5574
+ else:
5575
+ _session_ready()
5576
+ ws['fields'].pop(key, None)
5577
+ for _row in ws['overlays'].values():
5578
+ if isinstance(_row, dict):
5579
+ _row.pop(key, None)
5580
+ # True: the field contract rows_from_pool projects through has changed — same reason
5581
+ # field_upsert reruns.
5582
+ return True
5583
+
5584
  if kind == 'add_to_list':
5585
  # "Add to list" (owner item 6): a view's current matches become fixed cohort members.
5586
  #
 
5761
  return st.column_config.TextColumn(label, pinned=pin, help=extra_help)
5762
 
5763
 
5764
+ def _table_grid(*, uname, team_id, pool_rows, grid_rows, stamp, defs=None,
5765
+ storage_key, grid_key, height, hide_views=False, cohort_variant=False):
5766
+ """THE table-page grid block — ONE implementation of the Airtable-style work surface
5767
+ (the table-page factory, owner directive 2026-07-27: duplicating the Customer table to
5768
+ the next object must be a registry row + a config, not a copy of page_customer_data).
5769
+
5770
+ page_customer_data and page_cohort are CONFIGS of this function. What a table OBJECT
5771
+ supplies:
5772
+ pool_rows the caller's whole permitted pool — event guards + cohort vocabulary
5773
+ grid_rows the rows THIS surface holds (Customer: the pool; Cohort: the fixed set).
5774
+ Measure conditions and formula-measure columns resolve over THESE pids —
5775
+ the zero-group is reconstructed from what the table holds.
5776
+ stamp the pool's pull stamp (memo keys for measure resolution)
5777
+ defs legacy list-formula defs projected into views ({} for everything new)
5778
+ storage_key / grid_key / height / hide_views / cohort_variant presentation identity
5779
+ The store ops behind the event loop are the Customer table's today
5780
+ (modules/customer_data via core/table_store); a NEW object threads its own
5781
+ `core.table_store.make('<its>_table_workspace')` through _cl_handle_grid_event when it
5782
+ arrives — one seam, deliberately not widened before a second object exists.
5783
+
5784
+ Everything else — fields from the workspace, saved views, measure conditions (CG-8),
5785
+ formula-measure columns (item 7), cohort cells, the once-by-id event loop — is the same
5786
+ machinery on purpose: ONE implementation is what keeps the eventual React-shell port a
5787
+ one-place job.
5788
+
5789
+ Returns True when the caller must st.rerun() (the handler's return-value contract:
5790
+ "re-render from server state", NOT "handled" — see _cl_handle_one).
5791
+ """
5792
+ import aios_grid
5793
+ ws = _cl_table_workspace(uname)
5794
+ pool_pids = {r['pid'] for r in pool_rows}
5795
+ grid_pids = {r['pid'] for r in grid_rows}
5796
+ # The "Add to list" targets, the `Where [Cohort] ...` vocabulary AND the derived Cohorts
5797
+ # column's values — ONE array, so what the picker offers, what the engine tests and what
5798
+ # the cell says cannot disagree. visible() scopes membership to what this caller may see;
5799
+ # membership is filtered against the caller's WHOLE pool (not this surface's rows) so a
5800
+ # condition on ANOTHER cohort stays answerable from every table page.
5801
+ cohort_lists = [{'id': cid, 'name': c.get('name') or cid,
5802
+ 'pids': [p for p in (c.get('members') or []) if p in pool_pids]}
5803
+ for cid, c in sorted(cohort_mod.visible(uname, pool_pids).items(),
5804
+ key=lambda kv: (kv[1].get('name') or '').lower())]
5805
+ fields = aios_grid.fields_from_workspace(ws, cohorts=bool(cohort_lists))
5806
+ views = aios_grid.views_from_defs(defs or {}, ws.get('views'), fields)
5807
+ # Page-scoped CSS sentinel: removes the dashboard max-width so the component follows the
5808
+ # main column; the cohort variant subtracts the sub-rail's extra height (-106px).
5809
+ st.markdown("<span class='aios-grid-host-marker%s'></span>"
5810
+ % (' aios-grid-host-cohort' if cohort_variant else ''),
5811
+ unsafe_allow_html=True)
5812
+ # CG-8 measure conditions — resolved HERE, server-side, to a pid set per condition; the
5813
+ # client engine treats each as a membership test, so the table's counts stay its own.
5814
+ # The pending event is read from the component's OWN return value at the top of this run,
5815
+ # so a condition the user just typed is answered in the same run that delivers it.
5816
+ measures = _cl_measure_offer(team_id)
5817
+ msets = _cl_resolve_measures(views, _cl_pending_view(st.session_state.get(grid_key)),
5818
+ team_id, grid_pids, stamp)
5819
+ # Formula-measure columns (item 7): host-computed values, merged with the cohort cells
5820
+ # into ONE derived dict — the same read-only channel, never the cached pool rows.
5821
+ derived = aios_grid.cohort_cells(cohort_lists)
5822
+ for _pid, _cells in _cl_measure_columns(fields, team_id, grid_pids, stamp).items():
5823
+ derived.setdefault(_pid, {}).update(_cells)
5824
+ workspace = {'storageKey': storage_key, 'views': views, 'lists': cohort_lists}
5825
+ if hide_views:
5826
+ workspace['hideViews'] = True
5827
+ ev = aios_grid.render(
5828
+ aios_grid.rows_from_pool(grid_rows, fields, ws.get('overlays'), derived=derived),
5829
+ fields, workspace=workspace, key=grid_key, height=height,
5830
+ user_options=_assignable_people(),
5831
+ measures=measures, measure_sets=msets, today=str(P.today()))
5832
+ try:
5833
+ return _cl_handle_grid_event(ev, uname, pool_pids, fields,
5834
+ measure_keys={m['key'] for m in measures},
5835
+ resolved_ids=set(msets),
5836
+ cohort_ids={c['id'] for c in cohort_lists},
5837
+ measure_offer=measures)
5838
+ except Exception as _he:
5839
+ # The grid RENDERED — a handler bug must not make the page fall back to the legacy
5840
+ # workbench under a working table (or claim the table failed). Log it, skip the rerun.
5841
+ _tel.error('table-grid:handle', _he)
5842
+ return False
5843
+
5844
+
5845
  def page_cohort():
5846
  """Cohort — the SAME table as Customer over a FIXED set of customers.
5847
 
 
5933
  f"24 months, so not shown.")
5934
 
5935
  try:
5936
+ # The factory call IS this page's grid (owner items 4/6/10 live in the config):
5937
+ # hideViews because the cohort IS the row set — an "All customers" tab beside it would
5938
+ # name a set this table does not hold; storageKey is per COHORT so one list's filters
5939
+ # never leak onto another; measure conditions + formula columns resolve over the
5940
+ # COHORT's rows (the zero-group is what this table holds); defs={} — legacy list
5941
+ # formulas are the Customer page's projection, not this one's.
5942
+ if _table_grid(uname=uname, team_id=team_id, pool_rows=rows, grid_rows=crows,
5943
+ stamp=b['pulled_at'], defs={},
5944
+ storage_key=(f"royal-imports:cohort:{uname}:{active}:"
5945
+ f"{team_id if team_id is not None else 'all'}"),
5946
+ grid_key=f'cohort_grid_{active}', height=640,
5947
+ hide_views=True, cohort_variant=True):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5948
  st.rerun()
5949
  except Exception as _e:
5950
  _tel.error('cohort:grid', _e)
 
5993
  # views/rule-engine workbench BELOW serves as the fallback — the page never hard-fails.
5994
  _embed_ok = False
5995
  try:
5996
+ # The factory call IS this page's table (the whole scoped book, saved views, legacy
5997
+ # list defs projected in). _embed_ok flips only after a successful render, so the
5998
+ # legacy Streamlit workbench below still serves as the fallback when the embed build
5999
+ # is absent or errors — the page never hard-fails.
6000
+ _rerun = _table_grid(uname=uname, team_id=team_id, pool_rows=rows, grid_rows=rows,
6001
+ stamp=b['pulled_at'], defs=defs,
6002
+ storage_key=(f"royal-imports:customer-list:{uname}:"
6003
+ f"{team_id if team_id is not None else 'all'}:"
6004
+ f"{agent or 'all'}"),
6005
+ grid_key='cl_aios_grid', height=760)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6006
  _embed_ok = True
6007
  # NOTE the return-value contract: True means "re-render from server state",
6008
  # not "handled". A view autosave persists and returns False on purpose.
6009
+ if _rerun:
 
 
 
 
 
6010
  st.rerun()
6011
  except Exception as _grid_error:
6012
  _tel.error('customer-list:grid', _grid_error)
core/table_store.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """The generic per-user TABLE WORKSPACE store — the persistence half of the table-page factory.
2
+
3
+ One durable store key holds one table OBJECT's per-user Airtable-style state:
4
+
5
+ {username: {'views': {view_id: SavedView},
6
+ 'fields': {field_key: Field}, # notes + custom_ + measure_ strata
7
+ 'overlays': {str(pid): {field_key: value}}}}
8
+
9
+ `make(table_key)` returns the six operations a table page's host loop needs, closed over that
10
+ key. The Customer table's ops (`modules/customer_data.py`, key 'customer_table_workspace') are
11
+ these exact functions — the logic MOVED here 2026-07-27 so that duplicating the Customer table
12
+ pattern to a new object is a registry row + a config, not a copy of the store plumbing
13
+ (owner directive: the table-page factory).
14
+
15
+ A LIST (membership/formula semantics) is deliberately a different store from a VIEW
16
+ (presentation/query state) — see modules/customer_data.py's customer_lists key.
17
+ """
18
+ import core.store as store
19
+
20
+
21
+ class TableStore:
22
+ """The six store operations for one table object's workspace, closed over its store key."""
23
+
24
+ def __init__(self, table_key):
25
+ self.table_key = table_key
26
+
27
+ # ---------------------------------------------------------------- read
28
+ def workspace(self, username):
29
+ """One user's durable workspace: always the full three-strata shape."""
30
+ try:
31
+ ws = (store.get(self.table_key) or {}).get(username, {}) or {}
32
+ except Exception:
33
+ ws = {}
34
+ return {
35
+ 'views': dict(ws.get('views') or {}),
36
+ 'fields': dict(ws.get('fields') or {}),
37
+ 'overlays': dict(ws.get('overlays') or {}),
38
+ }
39
+
40
+ # ---------------------------------------------------------------- write
41
+ def _update(self, username, change):
42
+ def _up(data):
43
+ ws = data.setdefault(username, {})
44
+ ws.setdefault('views', {})
45
+ ws.setdefault('fields', {})
46
+ ws.setdefault('overlays', {})
47
+ change(ws)
48
+ return data
49
+ store.update(self.table_key, _up)
50
+
51
+ def save_view(self, username, view):
52
+ """Upsert a serializable SavedView by stable id."""
53
+ view_id = str((view or {}).get('id') or '').strip()
54
+ if not view_id:
55
+ raise ValueError('view id is required')
56
+ self._update(username, lambda ws: ws['views'].__setitem__(view_id, dict(view)))
57
+
58
+ def delete_view(self, username, view_id):
59
+ """Delete a custom/list view override. The system all-rows view is guarded by caller."""
60
+ self._update(username, lambda ws: ws['views'].pop(str(view_id), None))
61
+
62
+ def save_field(self, username, field):
63
+ """Persist a column note or a user-created (custom_/measure_) field definition."""
64
+ key = str((field or {}).get('key') or '').strip()
65
+ if not key:
66
+ raise ValueError('field key is required')
67
+
68
+ def _save(ws):
69
+ # A cleared note on an immutable source field returns to the canonical schema
70
+ # instead of leaving a meaningless override row. Custom fields remain even with
71
+ # an empty note.
72
+ if not field.get('custom') and not str(field.get('note') or '').strip():
73
+ ws['fields'].pop(key, None)
74
+ else:
75
+ ws['fields'][key] = dict(field)
76
+
77
+ self._update(username, _save)
78
+
79
+ def delete_field(self, username, key):
80
+ """Delete a USER-CREATED field definition outright (owner gap closed 2026-07-27).
81
+
82
+ Only the created strata ever reach here (`custom_` overlay fields, `measure_` formula
83
+ columns — the caller enforces the prefix). The stored overlay VALUES for the key are
84
+ scrubbed with it: a deleted column's cells must not linger as orphan data that would
85
+ silently resurface if the key were ever reused. Views referencing the key self-heal on
86
+ their next autosave (an unknown colId is dropped) — the rule every stale key rides.
87
+ """
88
+ key = str(key or '').strip()
89
+ if not key:
90
+ return
91
+
92
+ def _drop(ws):
93
+ ws['fields'].pop(key, None)
94
+ for row in ws['overlays'].values():
95
+ if isinstance(row, dict):
96
+ row.pop(key, None)
97
+
98
+ self._update(username, _drop)
99
+
100
+ def patch_overlay(self, username, pid, updates):
101
+ """Patch only the external editable stratum; never writes to the source system."""
102
+ clean = dict(updates or {})
103
+ if not clean:
104
+ return
105
+
106
+ def _patch(ws):
107
+ ws['overlays'].setdefault(str(int(pid)), {}).update(clean)
108
+
109
+ self._update(username, _patch)
110
+
111
+
112
+ def make(table_key):
113
+ return TableStore(table_key)
modules/customer_data.py CHANGED
@@ -18,6 +18,7 @@ no link (owner/CFO/admin) see the whole book.
18
  import core.odoo as O
19
  import core.periods as P
20
  import core.store as store
 
21
  import modules.ar as ar
22
  import modules.customers as cust
23
  import modules.sales as S
@@ -381,77 +382,19 @@ def delete_list(username, name):
381
  # semantics, while a VIEW owns presentation/query state (filters, multi-sort, grouping,
382
  # visible fields, widths, color, row height). List views can reference the same formula
383
  # without conflating the two persistence contracts.
384
- def table_workspace(username):
385
- """Return one user's durable Customer table workspace.
386
-
387
- Shape:
388
- {'views': {view_id: SavedView}, 'fields': {field_key: Field},
389
- 'overlays': {str(pid): {overlay_field: value}}}
390
- """
391
- try:
392
- ws = (store.get(TABLE_KEY) or {}).get(username, {}) or {}
393
- except Exception:
394
- ws = {}
395
- return {
396
- 'views': dict(ws.get('views') or {}),
397
- 'fields': dict(ws.get('fields') or {}),
398
- 'overlays': dict(ws.get('overlays') or {}),
399
- }
400
-
401
-
402
- def _update_table_workspace(username, change):
403
- def _up(data):
404
- ws = data.setdefault(username, {})
405
- ws.setdefault('views', {})
406
- ws.setdefault('fields', {})
407
- ws.setdefault('overlays', {})
408
- change(ws)
409
- return data
410
- store.update(TABLE_KEY, _up)
411
-
412
-
413
- def save_table_view(username, view):
414
- """Upsert a serializable SavedView by stable id."""
415
- view_id = str((view or {}).get('id') or '').strip()
416
- if not view_id:
417
- raise ValueError('view id is required')
418
- _update_table_workspace(
419
- username, lambda ws: ws['views'].__setitem__(view_id, dict(view)))
420
-
421
-
422
- def delete_table_view(username, view_id):
423
- """Delete a custom/list view override. The system All-customers view is guarded by caller."""
424
- _update_table_workspace(
425
- username, lambda ws: ws['views'].pop(str(view_id), None))
426
-
427
-
428
- def save_table_field(username, field):
429
- """Persist a column note or a user-created overlay field definition."""
430
- key = str((field or {}).get('key') or '').strip()
431
- if not key:
432
- raise ValueError('field key is required')
433
-
434
- def _save(ws):
435
- # A cleared note on an immutable source field returns to the canonical schema instead
436
- # of leaving a meaningless override row. Custom fields remain even with an empty note.
437
- if not field.get('custom') and not str(field.get('note') or '').strip():
438
- ws['fields'].pop(key, None)
439
- else:
440
- ws['fields'][key] = dict(field)
441
-
442
- _update_table_workspace(username, _save)
443
-
444
-
445
- def patch_table_overlay(username, pid, updates):
446
- """Patch only the external editable stratum; never writes to Odoo."""
447
- clean = dict(updates or {})
448
- if not clean:
449
- return
450
-
451
- def _patch(ws):
452
- ws['overlays'].setdefault(str(int(pid)), {}).update(clean)
453
-
454
- _update_table_workspace(username, _patch)
455
 
456
 
457
  # ------------------------------------------------------------------ digest compatibility
 
18
  import core.odoo as O
19
  import core.periods as P
20
  import core.store as store
21
+ import core.table_store as table_store
22
  import modules.ar as ar
23
  import modules.customers as cust
24
  import modules.sales as S
 
382
  # semantics, while a VIEW owns presentation/query state (filters, multi-sort, grouping,
383
  # visible fields, widths, color, row height). List views can reference the same formula
384
  # without conflating the two persistence contracts.
385
+ #
386
+ # The store logic MOVED to core/table_store.py 2026-07-27 (the table-page factory): these
387
+ # names are the Customer table's instance of the generic per-object workspace store, kept as
388
+ # module functions so every existing caller (app.py's host loop, QA gates) is untouched.
389
+ # A NEW table object gets its own `core.table_store.make('<its>_table_workspace')`.
390
+ _TSTORE = table_store.make(TABLE_KEY)
391
+
392
+ table_workspace = _TSTORE.workspace
393
+ save_table_view = _TSTORE.save_view
394
+ delete_table_view = _TSTORE.delete_view
395
+ save_table_field = _TSTORE.save_field
396
+ delete_table_field = _TSTORE.delete_field
397
+ patch_table_overlay = _TSTORE.patch_overlay
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
 
399
 
400
  # ------------------------------------------------------------------ digest compatibility