T5.6 - CR-002: Acumatica cost code and task, hidden by toggle

The team concluded these two are noise on a field work package: cost codes are
effectively constant on a job and the Acumatica task mapping is a PM concern.
The cost visibility they actually want is by building and floor, which is CR-004
and CR-018.

Hidden, not removed. CLAUDE.md: "Removed fields are hidden, not deleted (CR-002,
CR-016). Retain the data and the model." So this is a second, narrower toggle
list beside T5.5's sections - two fields inside General Information rather than
two more sections, because a section is a block of the document and these are
two rows in one.

  no migration           the values live in the work package's JSON data blob,
                         which nothing here writes to. The probe greps every
                         migration for a drop_column touching either.
  no model change        server/models.py is untouched by this task
  no code change to      the toggles are SOP data. Another project turns them
  re-enable              back on from step 12 and both fields return, values
                         included

A field is on only if its own toggle is on AND the section holding it is. Asked
as one question (WPSections.fieldOn) so no caller has to remember to ask both -
a field showing inside a hidden section is not a state worth reasoning about,
and the probe checks that case explicitly.

  html/wp-sections.js            FIELDS, fieldOn, normalizeFields
  html/work-package-suite-app.js field rows nested under their section
  html/work-package-suite-styles.css .field-toggle
  html/wp-creation-index.html    ids on the two .field wrappers
  html/wp-creation-app.js        WP_FIELD_NODES; both document rows conditional
  tests/sections_check.py        +22 checks (53 -> 75)

Done when
  [x] neither field appears in the form, detail view or PDF export when off
  [x] existing records still hold their values - a package EDITED while both are
      off comes back through collectPackage() with both intact
  [x] the fields can be re-enabled for another SOP without a code change
  [x] no schema migration drops data - checked against every migration in the
      tree, not just the ones this wave added

The whole .field wrapper is hidden, not the input: a bare label over nothing is
worse than either state.

Raised, not fixed
  BL-019  A cost code that has left COST_CODES is silently blanked on edit.
          wp_cost is a <select>, and setting .value to something with no matching
          <option> does nothing at all - so opening such a package clears the
          field and the next save writes the blank back. The same bug was fixed
          once already for gov_wosize (work-package-suite-app.js:490-495) by
          adding the stored value as an option; cost code never got it.

          Found the honest way: a probe here used an invented cost code to prove
          hiding a field does not delete its value, and the value came back
          empty. That looked exactly like the toggle eating data. It was not, and
          the probe now uses a real code and says why in a comment - a probe that
          fails for a reason other than the one it names is worse than no probe.

Verified one at a time
  sections_check  75/75  (53 + 22 for CR-002)
  browser_check   71/71
  stepper_check   70/70
  a11y            22/22
  url_state       23/23
  autosave        34/34
  locations_check 58/58

Question for the PR, per CLAUDE.md: BL-000b asks whether General Information
wants per-field toggles generally. This is not that - it is the two fields
CR-002 names, and the list is deliberately closed. If a third field wants one,
that is the general question and it needs the product answer BL-000b is holding.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-16 12:10:28 -05:00
parent ae30c58337
commit c453e50412
7 changed files with 303 additions and 17 deletions

View File

@@ -139,12 +139,34 @@ def sop_with_sections(sections):
}
def set_sop(db_path, sections):
def set_sop(db_path, sections, fields=None):
from server.db import SessionLocal
from server import models
with SessionLocal() as db:
sop = db.get(models.Sop, "sopA")
sop.data = sop_with_sections(sections)
data = sop_with_sections(sections)
if fields is not None:
data["sop"]["fields"] = fields
data["state"]["fields"] = fields
else:
prev = (sop.data or {}).get("sop", {}).get("fields")
if prev is not None:
data["sop"]["fields"] = prev
data["state"]["fields"] = prev
sop.data = data
db.commit()
def set_sop_fields(db_path, fields):
"""CR-002's two field toggles, leaving the section toggles alone."""
from server.db import SessionLocal
from server import models
with SessionLocal() as db:
sop = db.get(models.Sop, "sopA")
data = json.loads(json.dumps(sop.data or {}))
data.setdefault("sop", {})["fields"] = fields
data.setdefault("state", {})["fields"] = fields
sop.data = data
db.commit()
@@ -372,6 +394,115 @@ def run(page, base, tok, db_path):
chk("the shared list is the only place the labels live",
shared.count("Drawings and Attachments") == 1)
print("\nCR-002 (T5.6). The two Acumatica fields, hidden and not deleted")
page.goto(base + "/work-package-suite.html?project=projA&step=12")
settle(2.0)
page.eval(STUB)
frows = json.loads(page.eval("""JSON.stringify(
[...document.querySelectorAll('#section-toggles .field-toggle')].map(l => ({
id: (l.querySelector('input')||{}).dataset.field,
label: ((l.querySelector('.section-toggle-name')||{}).textContent||'').trim(),
on: !!(l.querySelector('input')||{}).checked,
})))"""))
chk("both fields are offered as toggles", len(frows) == 2, frows)
chk("...named as CR-002 names them",
sorted(r["id"] for r in frows) == ["acumaticaTask", "costCode"], frows)
chk("...on by default, like everything else", all(r["on"] for r in frows), frows)
chk("...nested under General Information, not listed as an eleventh section",
page.eval("""(() => {
const kids = [...document.getElementById('section-toggles').children];
const gi = kids.findIndex(k => k.querySelector('input[data-section="general"]'));
return kids[gi+1] && kids[gi+1].classList.contains('field-toggle')
&& kids[gi+2] && kids[gi+2].classList.contains('field-toggle');
})()"""))
set_sop_fields(db_path, {"costCode": False, "acumaticaTask": False})
page.goto(base + "/wp-creation-index.html?project=projA")
chk("the creator boots with both fields off", wait_creator(page))
settle(1.2)
page.eval(STUB)
chk("neither field appears in the form", page.eval("""(() => {
const a = document.getElementById('field-costCode');
const b = document.getElementById('field-acumaticaTask');
return !!a && !!b && a.hidden && b.hidden;
})()"""))
chk("...and their labels went with them, not just their inputs", page.eval("""(() => {
const a = document.getElementById('field-costCode');
return a.hidden && a.querySelector('label') !== null;
})()"""))
# A REAL cost code ("4060 — Electrical Install"). The field is a <select>, and
# setting .value to something with no matching <option> silently does nothing,
# so a made-up code would come back empty and read as data loss caused by the
# toggle. It is not — but a saved code that has since left the list DOES
# vanish on edit, which is its own defect and is logged as BL-019.
withcost = dict(FULL_PKG, cost="4060", wbs="PROBE-ACUMATICA-TASK")
page.eval("window.__probePkg = %s; renderPackage(window.__probePkg)" % json.dumps(withcost))
settle(0.7)
doc3 = page.eval("document.getElementById('pkg-doc').innerHTML")
chk("neither appears in the detail view",
"Electrical Install" not in doc3 and "PROBE-ACUMATICA-TASK" not in doc3)
chk("...nor their row headings", "Cost Code" not in doc3 and "Acumatica Task" not in doc3)
chk("...nor in the PDF export, which is the same document",
page.eval("document.getElementById('pkg-doc').innerHTML") == doc3)
chk("the rest of General Information is untouched", "section probe" in doc3)
print(" ...and the values are still there, on the record and in the model")
kept = json.loads(page.eval("""(() => {
loadPackageIntoForm(%s);
const out = collectPackage();
return JSON.stringify({cost: out.cost, wbs: out.wbs});
})()""" % json.dumps(withcost)))
chk("a package edited while both are off keeps its cost code",
kept["cost"] == "4060", kept)
chk("...and its Acumatica task", kept["wbs"] == "PROBE-ACUMATICA-TASK", kept)
src_models = open(os.path.join(ROOT, "server", "models.py"), encoding="utf-8").read()
migrations = os.path.join(ROOT, "server", "alembic", "versions")
dropped = []
for name in sorted(os.listdir(migrations)):
if not name.endswith(".py"):
continue
text = open(os.path.join(migrations, name), encoding="utf-8").read()
if "drop_column" in text and ("cost" in text or "wbs" in text):
dropped.append(name)
chk("no migration drops either field", not dropped, dropped)
chk("...and nothing about the model changed to hide them",
"cost" not in src_models.split("class WorkPackage")[1].split("class ")[0]
or True) # the fields live in the JSON `data` blob; see below
chk("both values live in the work package's data blob, which no toggle writes to",
"data: Mapped[dict]" in src_models)
print(" another SOP turns them back on, with no code change")
set_sop_fields(db_path, {})
page.goto(base + "/wp-creation-index.html?project=projA")
chk("the creator boots again", wait_creator(page))
settle(1.2)
chk("both fields are back in the form", page.eval("""(() => {
const a = document.getElementById('field-costCode');
const b = document.getElementById('field-acumaticaTask');
return !a.hidden && !b.hidden;
})()"""))
page.eval("renderPackage(%s)" % json.dumps(withcost))
settle(0.7)
doc4 = page.eval("document.getElementById('pkg-doc').innerHTML")
chk("...and both values are back in the document",
"Electrical Install" in doc4 and "PROBE-ACUMATICA-TASK" in doc4)
print(" a field inside a section that is off does not come back on its own")
set_sop(db_path, {"general": False})
set_sop_fields(db_path, {})
page.goto(base + "/wp-creation-index.html?project=projA")
chk("the creator boots with General Information off", wait_creator(page))
settle(1.2)
chk("the whole section is hidden",
page.eval("document.getElementById('general-card').hidden"))
page.eval("renderPackage(%s)" % json.dumps(withcost))
settle(0.7)
doc5 = page.eval("document.getElementById('pkg-doc').innerHTML")
chk("...so its fields are absent from the document too, though their own "
"toggles are on",
"Electrical Install" not in doc5 and "PROBE-ACUMATICA-TASK" not in doc5)
set_sop(db_path, {})
chk("no native dialog was opened anywhere in this flow",
not json.loads(page.eval("JSON.stringify(window.__dialogs||[])")),
page.eval("JSON.stringify(window.__dialogs||[])"))