fsanyoto commited on
Commit
07c209f
Β·
verified Β·
1 Parent(s): defe295

Deploy Loopable

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
 
aios_grid_fields.json CHANGED
@@ -260,6 +260,7 @@
260
  }
261
  ],
262
  "_product_comment": "ADDITIVE, wave 15 C-TOPIC. The PRODUCT table's field contract. Kept as a SEPARATE top-level key rather than restructuring `fields` into {customer_data, product_data}: both existing readers (aios_grid._load_fields, aios-web/api/main.py) index doc['fields'] directly, and reshaping that mid-wave would break the embed for a cosmetic gain. The keyed shape can arrive when both readers move in ONE commit; until then this is the product half and `fields` is the customer half.",
 
263
  "product_data": {
264
  "identity": "pid",
265
  "business_key": "code",
@@ -400,18 +401,6 @@
400
  "default": false,
401
  "description": "Days of supply minus lead time. Negative means it runs out before a reorder lands."
402
  },
403
- {
404
- "key": "buy_now",
405
- "label": "Buy signal",
406
- "type": "select",
407
- "source": "odoo",
408
- "default": true,
409
- "description": "Buy now when cover is already shorter than lead time. Blank if either is unknown.",
410
- "options": [
411
- "Buy now",
412
- "OK"
413
- ]
414
- },
415
  {
416
  "key": "stock_bucket",
417
  "label": "Stock status",
 
260
  }
261
  ],
262
  "_product_comment": "ADDITIVE, wave 15 C-TOPIC. The PRODUCT table's field contract. Kept as a SEPARATE top-level key rather than restructuring `fields` into {customer_data, product_data}: both existing readers (aios_grid._load_fields, aios-web/api/main.py) index doc['fields'] directly, and reshaping that mid-wave would break the embed for a cosmetic gain. The keyed shape can arrive when both readers move in ONE commit; until then this is the product half and `fields` is the customer half.",
263
+ "_product_removed_buy_now": "OWNER, 2026-08-03: 'Buy signal' (key buy_now, a select of Buy now / OK) is NO LONGER A PRESET FIELD. It never earned one: it is a formula over two columns that are both still right here, and the platform has a formula field type for exactly that. THE FORMULA, which reproduces the retired column row for row (modules/product_data.validate proves the equivalence, and goes red if it ever stops holding): IF({lead_days} > 0, IF({dos} < {lead_days}, \"Buy now\", \"OK\"), \"\") . Every branch matches the old server rule, including the blanks - the formula engine refuses a comparison against a blank rather than coercing it to 0, so a SKU with no days-of-supply or no lead time comes out empty, which is 'we do not know' and not 'you are fine'. NOTE the column is still COMPUTED in product_data.pool(): it ships nowhere (rows_from_pool projects strictly through this contract, so no Field means no cell on the wire) and exists only as validate()'s oracle. A formula field is PER-USER, so nothing shared may filter on it - the Buy list view filters on dos/lead_days directly (_seed_wave17).",
264
  "product_data": {
265
  "identity": "pid",
266
  "business_key": "code",
 
401
  "default": false,
402
  "description": "Days of supply minus lead time. Negative means it runs out before a reorder lands."
403
  },
 
 
 
 
 
 
 
 
 
 
 
 
404
  {
405
  "key": "stock_bucket",
406
  "label": "Stock status",
modules/product_data.py CHANGED
@@ -39,10 +39,17 @@ import core.periods as P
39
  import core.table_store as table_store
40
  import modules.products as products
41
 
42
- #: Columns that exist ONLY on a consolidated pull. See decision 2.
43
  #: `cover_gap_d` / `buy_now` (wave 17) join it because both are computed FROM `dos`, and a buy
44
  #: signal built on a stock number the caller cannot see would be a recommendation nobody could
45
  #: check ([[no-unverifiable-aggregates]]).
 
 
 
 
 
 
 
46
  CONSOLIDATED_ONLY = ("on_hand", "unit_cost", "inv_value", "qty_ltm", "dos", "stock_bucket",
47
  "cover_gap_d", "buy_now")
48
 
@@ -187,6 +194,18 @@ def pool(team_id=None, t=None):
187
  # no lead time; `dos` is null for anything that never sells through. "We don't know"
188
  # and "you're fine" are different sentences, and only one of them is safe to print
189
  # beside a purchasing decision.
 
 
 
 
 
 
 
 
 
 
 
 
190
  dos, lead = e.get("dos"), s.get("lead_days")
191
  if isinstance(dos, (int, float)) and isinstance(lead, (int, float)) and lead > 0:
192
  row["cover_gap_d"] = int(round(dos - lead))
@@ -201,6 +220,47 @@ def pool(team_id=None, t=None):
201
  return rows
202
 
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  def validate(team_id=None, t=None):
205
  """Reconcile what SHIPS to an independent aggregate β€” the platform's own rule that a number
206
  which does not tie to Odoo does not ship.
@@ -241,4 +301,56 @@ def validate(team_id=None, t=None):
241
  "detail": {"buy_now": len(buy), "ok": len(ok_rows), "unknown": len(blank),
242
  "misclassified": mis},
243
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  return checks
 
39
  import core.table_store as table_store
40
  import modules.products as products
41
 
42
+ #: POOL-ROW KEYS that exist ONLY on a consolidated pull. See decision 2.
43
  #: `cover_gap_d` / `buy_now` (wave 17) join it because both are computed FROM `dos`, and a buy
44
  #: signal built on a stock number the caller cannot see would be a recommendation nobody could
45
  #: check ([[no-unverifiable-aggregates]]).
46
+ #:
47
+ #: ⚠ ROW KEYS, NOT FIELDS, and the distinction started mattering on 2026-08-03. Two readers:
48
+ #: `verify_perm_scope` asserts the shape of a POOL ROW against this, and `routes_products`
49
+ #: narrows the FIELD list with it. Since owner item 5 `buy_now` is a row key with no Field β€”
50
+ #: computed as `validate()`'s oracle, projected onto no wire β€” so it belongs here for the first
51
+ #: reader and is inert for the second. Removing it would stop the scope gate proving that a
52
+ #: BU-scoped pull withholds it.
53
  CONSOLIDATED_ONLY = ("on_hand", "unit_cost", "inv_value", "qty_ltm", "dos", "stock_bucket",
54
  "cover_gap_d", "buy_now")
55
 
 
194
  # no lead time; `dos` is null for anything that never sells through. "We don't know"
195
  # and "you're fine" are different sentences, and only one of them is safe to print
196
  # beside a purchasing decision.
197
+ #
198
+ # β›” `buy_now` SHIPS NOWHERE ANY MORE, and is computed anyway. OWNER 2026-08-03: it
199
+ # is not a preset field β€” it is a formula over the two columns beside it, and the
200
+ # platform has a formula field type for exactly that. Its Field is gone from
201
+ # `aios_grid_fields.json`, and `rows_from_pool` projects rows STRICTLY through that
202
+ # contract, so no Field means no cell on the wire. Nothing renders this key.
203
+ #
204
+ # It stays computed because deleting it would delete the PROOF. `validate()` below
205
+ # reconciles the formula's predicate against this one, row for row, which is the only
206
+ # thing that makes "the same exact figures" a claim rather than an assertion β€” and
207
+ # this repo has the scar already (wave 17: archiving `ar` "would have DELETED the
208
+ # proof"). Two comparisons per SKU is what that costs.
209
  dos, lead = e.get("dos"), s.get("lead_days")
210
  if isinstance(dos, (int, float)) and isinstance(lead, (int, float)) and lead > 0:
211
  row["cover_gap_d"] = int(round(dos - lead))
 
220
  return rows
221
 
222
 
223
+ #: ⭐ THE BUY SIGNAL, AS THE FORMULA FIELD EVALUATES IT (owner, 2026-08-03).
224
+ #:
225
+ #: The owner's ruling was that "Buy signal" is not a preset field β€” it is a formula over two
226
+ #: columns the product table already carries, and the platform has a formula field type for it.
227
+ #: The formula, verbatim, is what `_seed_wave17.BUY_SIGNAL_FORMULA` creates and what the JSON
228
+ #: contract's `_product_removed_buy_now` note records:
229
+ #:
230
+ #: IF({lead_days} > 0, IF({dos} < {lead_days}, "Buy now", "OK"), "")
231
+ #:
232
+ #: This function is a PORT of how `customer-grid/formulaEngine.ts` evaluates that tree, not a
233
+ #: restatement of the business rule β€” that is the whole point, because the two could drift and
234
+ #: `validate()` is where the drift must show. Three engine behaviours it reproduces exactly:
235
+ #:
236
+ #: Β· a `ref` to a missing/non-numeric cell is None (`case "ref"` returns null for anything
237
+ #: that is not a finite number or a string);
238
+ #: Β· `cmp` returns BLANK unless BOTH sides read as numbers β€” it never coerces a blank to 0,
239
+ #: which is the difference between this and a filter engine's `toNum(null) === 0`;
240
+ #: Β· `IF` with a non-boolean condition returns BLANK ("no truthiness"), so a blank comparison
241
+ #: propagates out as a blank cell rather than taking the false branch.
242
+ BUY_SIGNAL_FORMULA = 'IF({lead_days} > 0, IF({dos} < {lead_days}, "Buy now", "OK"), "")'
243
+
244
+
245
+ def _buy_signal_formula(row):
246
+ """Evaluate `BUY_SIGNAL_FORMULA` over one pool row -> 'Buy now' | 'OK' | '' (blank)."""
247
+ def num(v):
248
+ # The engine's `ref` + `asNumber`: booleans are not values here, and a non-finite
249
+ # number is null. `isinstance(True, int)` is True in Python, so bool is excluded first.
250
+ if isinstance(v, bool) or not isinstance(v, (int, float)):
251
+ return None
252
+ return v if v == v and v not in (float('inf'), float('-inf')) else None
253
+
254
+ lead, dos = num(row.get("lead_days")), num(row.get("dos"))
255
+ if lead is None: # `{lead_days} > 0` is blank -> IF(blank, …) is blank
256
+ return ""
257
+ if not lead > 0:
258
+ return "" # the formula's own else-branch
259
+ if dos is None: # `{dos} < {lead_days}` is blank -> IF(blank, …) is blank
260
+ return ""
261
+ return "Buy now" if dos < lead else "OK"
262
+
263
+
264
  def validate(team_id=None, t=None):
265
  """Reconcile what SHIPS to an independent aggregate β€” the platform's own rule that a number
266
  which does not tie to Odoo does not ship.
 
301
  "detail": {"buy_now": len(buy), "ok": len(ok_rows), "unknown": len(blank),
302
  "misclassified": mis},
303
  })
304
+ # ⭐ OWNER 2026-08-03 β€” "use the formula fields to come up to the same EXACT figures".
305
+ #
306
+ # This is that sentence, as a check. The retired preset column and the formula that
307
+ # replaces it must agree on every SKU, in all three states, or the replacement is not a
308
+ # replacement. `_buy_signal_formula` is a line-by-line port of the client formula
309
+ # engine's evaluation of
310
+ #
311
+ # IF({lead_days} > 0, IF({dos} < {lead_days}, "Buy now", "OK"), "")
312
+ #
313
+ # including the part that is easy to get wrong: a comparison against a BLANK is blank,
314
+ # never a coerced 0. (The client engine's `cmp` returns null unless both sides read as
315
+ # numbers, and `IF` refuses a non-boolean condition β€” so a missing `dos` yields "" and
316
+ # not "Buy now". A filter engine would have said `0 < 30` and swept in every SKU that
317
+ # never sells through; the formula engine does not, and this check is what holds it.)
318
+ #
319
+ # ⚠ It compares SETS OF SKUs, not counts. Two different partitions can share a shape.
320
+ disagree = sorted(r["code"] for r in rows
321
+ if (r.get("buy_now") or "") != _buy_signal_formula(r))
322
+ checks.append({
323
+ "check": 'Buy signal as a FORMULA field == the retired preset column, per SKU '
324
+ '(IF({lead_days} > 0, IF({dos} < {lead_days}, "Buy now", "OK"), ""))',
325
+ "ours": len(rows) - len(disagree), "theirs": len(rows),
326
+ "ok": not disagree,
327
+ "detail": {"disagreeing_skus": disagree[:10], "n_disagree": len(disagree)},
328
+ })
329
+ # The other half of "the same figures": the SHARED Buy list view can no longer filter on
330
+ # the retired column, and its replacement conditions must select the same SKUs. They are
331
+ # `dos isNotEmpty AND lead_days isNotEmpty AND lead_days > 0 AND dos < lead_days`
332
+ # (_seed_wave17.views), so this reproduces exactly that conjunction.
333
+ #
334
+ # β›” THE NEGATIVE CONTROL IS WHY THIS IS NOT `cover_gap_d < 0`, which reads like the
335
+ # obvious filter and is WRONG: `cover_gap_d` is `int(round(dos - lead))`, so a genuine
336
+ # gap of -0.4 days rounds to 0 and that SKU drops off a buy list it belongs on.
337
+ view_rows = {r["code"] for r in rows
338
+ if isinstance(r.get("dos"), (int, float))
339
+ and isinstance(r.get("lead_days"), (int, float))
340
+ and r["lead_days"] > 0 and r["dos"] < r["lead_days"]}
341
+ signal_rows = {r["code"] for r in buy}
342
+ rounding_would_miss = sorted(
343
+ c for c in signal_rows
344
+ if next((r for r in rows if r["code"] == c), {}).get("cover_gap_d") == 0)
345
+ checks.append({
346
+ "check": "Buy list view conditions (dos/lead_days, no retired column) select "
347
+ "exactly the Buy-now SKUs",
348
+ "ours": len(view_rows), "theirs": len(signal_rows),
349
+ "ok": view_rows == signal_rows,
350
+ "detail": {"only_in_view": sorted(view_rows - signal_rows)[:10],
351
+ "only_in_signal": sorted(signal_rows - view_rows)[:10],
352
+ # Reported, not asserted: how many SKUs a `cover_gap_d < 0` filter would
353
+ # have silently dropped. 0 today does not make that filter correct.
354
+ "cover_gap_rounds_to_zero": len(rounding_would_miss)},
355
+ })
356
  return checks