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

@@ -41,6 +41,8 @@ let state = {
// adding a key on first read would make merely LOOKING at step 12 count as an
// unsaved change and fire T4.3's guard on the way out.
sections: (typeof WPSections !== 'undefined') ? WPSections.defaults() : {},
// CR-002: the two Acumatica fields, off-switchable inside General Information.
fields: (typeof WPSections !== 'undefined') ? WPSections.fieldDefaults() : {},
quality: {qcreq:'', photo:'', hold:''},
platforms: {tracking:'CxAlloy', commissioning:'CxAlloy', trackingUrl:'', commissioningUrl:''},
sequence: [],
@@ -467,7 +469,10 @@ function restoreSavedSOP(){
// mean every section is on — the alternative would switch them all off for
// every project in the estate. Normalised HERE, before the dirty fingerprint
// is taken, so filling the gap does not read as an edit.
if(typeof WPSections !== 'undefined') state.sections = WPSections.normalize(state.sections);
if(typeof WPSections !== 'undefined'){
state.sections = WPSections.normalize(state.sections);
state.fields = WPSections.normalizeFields(state.fields);
}
// A SOP saved before the team was account-backed has no teamIds; default them
// so the pickers render (the stored names show as "(no account)" until linked).
if(!state.teamIds) state.teamIds = {pm:'', apm:'', cm:'', qm:''};
@@ -1525,11 +1530,29 @@ function sopSections(){
state.sections = WPSections.normalize(state.sections);
return state.sections;
}
function sopFields(){
if(typeof WPSections === 'undefined') return {};
state.fields = WPSections.normalizeFields(state.fields);
return state.fields;
}
function renderSectionToggles(){
const host = document.getElementById('section-toggles');
if(!host || typeof WPSections === 'undefined') return;
const on = sopSections();
const fields = sopFields();
// A field row nested under the section that contains it, so "Acumatica task"
// is visibly a part of General Information rather than an eleventh section.
const fieldRows = secId => WPSections.fieldsFor(secId).map(f => `
<label class="field-toggle${fields[f.id] ? '' : ' is-off'}" for="fld-${escAttr(f.id)}">
<input type="checkbox" id="fld-${escAttr(f.id)}" data-field="${escAttr(f.id)}"
${fields[f.id] ? 'checked' : ''}>
<span class="section-toggle-body">
<span class="section-toggle-name">${escAttr(f.label)}</span>
<span class="section-toggle-note">${escAttr(f.note)}</span>
</span>
<span class="section-toggle-state">${fields[f.id] ? 'In use' : 'Not used'}</span>
</label>`).join('');
host.innerHTML = WPSections.LIST.map(sec => `
<label class="section-toggle${on[sec.id] ? '' : ' is-off'}" for="sec-${escAttr(sec.id)}">
<input type="checkbox" id="sec-${escAttr(sec.id)}" data-section="${escAttr(sec.id)}"
@@ -1539,16 +1562,16 @@ function renderSectionToggles(){
<span class="section-toggle-note">${escAttr(sec.note)}</span>
</span>
<span class="section-toggle-state">${on[sec.id] ? 'In use' : 'Not used'}</span>
</label>`).join('');
</label>` + fieldRows(sec.id)).join('');
renderSectionSummary();
}
function renderSectionSummary(){
const el = document.getElementById('section-summary');
if(!el || typeof WPSections === 'undefined') return;
const off = WPSections.offList(sopSections());
const off = WPSections.offList(sopSections()).concat(WPSections.offFieldList(sopFields()));
el.textContent = off.length
? `${off.length} section${off.length===1?'':'s'} turned off: ${off.join(', ')}. `
? `${off.length} turned off: ${off.join(', ')}. `
+ 'Their data is retained and returns if they are turned back on.'
: 'Every section is in use. Turn off anything this project does not need.';
}
@@ -1558,10 +1581,12 @@ document.addEventListener('DOMContentLoaded', function(){
if(!host) return;
host.addEventListener('change', function(e){
const t = e.target;
if(!t || !t.dataset || !t.dataset.section) return;
const on = sopSections();
on[t.dataset.section] = !!t.checked;
const wrap = t.closest('.section-toggle');
if(!t || !t.dataset) return;
const isField = !!t.dataset.field;
if(!isField && !t.dataset.section) return;
if(isField) sopFields()[t.dataset.field] = !!t.checked;
else sopSections()[t.dataset.section] = !!t.checked;
const wrap = t.closest(isField ? '.field-toggle' : '.section-toggle');
if(wrap){
wrap.classList.toggle('is-off', !t.checked);
const st = wrap.querySelector('.section-toggle-state');
@@ -1591,7 +1616,7 @@ function pushSectionsToCreator(){
try {
const cw = frame.contentWindow;
if(cw && typeof cw.applySopSections === 'function'){
cw.applySopSections(sopSections());
cw.applySopSections(sopSections(), sopFields());
return true;
}
} catch(e){ /* cross-document timing; the creator picks it up on its next boot */ }
@@ -2014,6 +2039,7 @@ function completeSOP(){
// CR-006. Rides on the SOP because the creator already reads the SOP: this is
// what makes the toggles reach a work package without a second channel.
sections: (typeof WPSections !== 'undefined') ? WPSections.normalize(state.sections) : {},
fields: (typeof WPSections !== 'undefined') ? WPSections.normalizeFields(state.fields) : {},
quality: {
qcReq: state.quality.qcreq,
photo: state.quality.photo,

View File

@@ -734,6 +734,26 @@ body.embed-full { overflow: hidden; }
.section-toggle.is-off { border-left-color: var(--border-strong); }
.section-toggle.is-off .section-toggle-name { color: var(--text-light); }
/* CR-002: a field inside a section, not an eleventh section. Indented and
smaller so the nesting is visible, and it inherits every other rule above so
the two cannot look like different kinds of control. */
.field-toggle {
display: flex;
align-items: flex-start;
gap: var(--wp-s3);
padding: var(--wp-s2) var(--wp-s3) var(--wp-s2) var(--wp-s6);
border: 1px solid var(--border);
border-left: 3px solid var(--success);
background: var(--bg);
margin-bottom: -1px;
cursor: pointer;
}
.field-toggle:hover { background: var(--cds-layer-hover); }
.field-toggle input { flex: none; width: 16px; height: 16px; margin-top: 2px; }
.field-toggle .section-toggle-name { font-size: 13px; }
.field-toggle.is-off { border-left-color: var(--border-strong); }
.field-toggle.is-off .section-toggle-name { color: var(--text-light); }
/* .field-error is declared once, in theme-light.css — the launcher's create form
and T5.8's step validation use the same component. */

View File

@@ -122,7 +122,7 @@ function applySOP(){
updateNumber(); updateReleaseBanner();
// CR-006. Last, after every builder has rendered its card — applying it earlier
// would be undone by whichever builder touched the same card afterwards.
applySopSections(SOP && SOP.sections);
applySopSections(SOP && SOP.sections, SOP && SOP.fields);
}
// Per-package kind. A project whose SOP has bimEnabled produces both install (IWP)
// and BIM (EWP) packages; the kind selector tailors which fields, WP types, and
@@ -1215,8 +1215,8 @@ function renderPackage(pkg){
${pkg.disciplines&&pkg.disciplines.length?`<tr><th>Discipline(s)</th><td>${esc(pkg.disciplines.join(', '))}${pkg.split?' <span style="color:var(--accent);font-size:10px">[MASTER — split into instances]</span>':''}${pkg.instanceOf?` <span style="color:var(--accent);font-size:10px">[instance of ${esc(pkg.parentNumber||'')}]</span>`:''}</td></tr>`:''}
<tr><th>System / Facility Code / UPN</th><td>${cell(pkg.system)}</td></tr>
${sectionOn('location')?`<tr><th>Location</th><td>${cell(pkg.location)}</td></tr>`:''}
<tr><th>Cost Code</th><td>${pkg.cost?esc(pkg.cost)+(costDesc?' — '+esc(costDesc):''):ns()}</td></tr>
<tr><th>Acumatica Task</th><td>${cell(pkg.wbs)}</td></tr>
${fieldOn('costCode')?`<tr><th>Cost Code</th><td>${pkg.cost?esc(pkg.cost)+(costDesc?' — '+esc(costDesc):''):ns()}</td></tr>`:''}
${fieldOn('acumaticaTask')?`<tr><th>Acumatica Task</th><td>${cell(pkg.wbs)}</td></tr>`:''}
<tr><th>Assignees</th><td>${cell(pkg.assignees)}</td></tr>
<tr><th>Distribution</th><td>${cell(pkg.distribution)}</td></tr>
<tr><th>Due Date</th><td>${cell(pkg.due)}</td></tr>
@@ -1446,20 +1446,40 @@ const WP_SECTION_NODES = {
closeout: ['#closeout-card'],
};
// CR-002: two fields inside General Information, off-switchable on their own.
// Hiding the whole .field wrapper rather than the input, so the label goes with
// it — a bare label over nothing is worse than either state.
const WP_FIELD_NODES = {
costCode: ['#field-costCode'],
acumaticaTask: ['#field-acumaticaTask'],
};
let wpSections = (typeof WPSections !== 'undefined') ? WPSections.defaults() : {};
let wpFields = (typeof WPSections !== 'undefined') ? WPSections.fieldDefaults() : {};
function sectionOn(id){
if(typeof WPSections === 'undefined') return true;
return WPSections.isOn(wpSections, id);
}
function fieldOn(id){
if(typeof WPSections === 'undefined') return true;
return WPSections.fieldOn(wpSections, wpFields, id);
}
/* Apply a section map to the form. Called from applySOP() on boot — which covers
a reload, a fresh tab and the standalone page — and from the SOP wizard next
door while the frame is already open (X4). Exposed on window deliberately: the
wizard is a different document and can only reach a global. */
function applySopSections(sections){
function applySopSections(sections, fields){
if(typeof WPSections === 'undefined') return wpSections;
wpSections = WPSections.normalize(sections);
wpFields = WPSections.normalizeFields(fields);
Object.keys(WP_FIELD_NODES).forEach(id => {
const on = fieldOn(id);
WP_FIELD_NODES[id].forEach(sel => {
document.querySelectorAll(sel).forEach(el => { el.hidden = !on; });
});
});
Object.keys(WP_SECTION_NODES).forEach(id => {
const on = wpSections[id];
WP_SECTION_NODES[id].forEach(sel => {

View File

@@ -165,8 +165,12 @@
Information's grid. CR-004 gives it structured building/floor/sector
fields of its own in wave 6; only this wrapper's contents change then. -->
<div class="field" id="location-card"><label>Location</label><input type="text" id="wp_location" placeholder="building / level / sector / room"></div>
<div class="field"><label>Cost code</label><select id="wp_cost"></select><div class="field-hint sop-hint">Acumatica cost codes</div></div>
<div class="field"><label>Acumatica task</label><input type="text" id="wp_wbs" placeholder="Acumatica task no."></div>
<!-- CR-002 hides these two rather than deleting them: the columns, the model
and every value already captured stay exactly as they are, and another
project can turn them back on without a code change. The ids are what
WP_FIELD_NODES addresses. -->
<div class="field" id="field-costCode"><label>Cost code</label><select id="wp_cost"></select><div class="field-hint sop-hint">Acumatica cost codes</div></div>
<div class="field" id="field-acumaticaTask"><label>Acumatica task</label><input type="text" id="wp_wbs" placeholder="Acumatica task no."></div>
</div>
<div class="field-grid">
<div class="field"><label>Owner <span class="help-tip" data-tip="The accountable owner (a user account on this project). Assigning notifies them by email if email notifications are enabled in the admin console.">i</span></label><select id="wp_assignee"><option value="">— Unassigned —</option></select></div>

View File

@@ -49,6 +49,45 @@
var IDS = LIST.map(function (s) { return s.id; });
/* Individual fields that can be switched off inside a section — CR-002.
A second, narrower list rather than more sections, because a section is a
block of the document and these are two rows inside one. BL-000b asks
whether General Information wants per-field toggles generally; this is not
that. It is the two fields CR-002 names, expressed as toggles because
CLAUDE.md says removals are expressed through toggles and the data is
retained — the columns and the model stay exactly as they are.
Same rule as sections: an id is permanent, absent means ON. */
var FIELDS = [
{ id: 'costCode', section: 'general', label: 'Acumatica cost code',
note: 'Effectively constant on a job, so it is noise on a field work package (CR-002). The value stays on every package that has one.' },
{ id: 'acumaticaTask', section: 'general', label: 'Acumatica task',
note: 'A PM concern rather than a field one (CR-002). The cost visibility the team actually wants is by building and floor — CR-004 and CR-018.' },
];
var FIELD_IDS = FIELDS.map(function (f) { return f.id; });
function fieldDefaults() {
var out = {};
FIELD_IDS.forEach(function (id) { out[id] = true; });
return out;
}
function normalizeFields(stored) {
var out = fieldDefaults();
if (stored && typeof stored === 'object') {
FIELD_IDS.forEach(function (id) {
if (Object.prototype.hasOwnProperty.call(stored, id)) out[id] = stored[id] !== false;
});
}
return out;
}
function fieldsFor(sectionId) {
return FIELDS.filter(function (f) { return f.section === sectionId; });
}
function defaults() {
// A new SOP has everything on. A project opts OUT of what it does not use;
// it does not have to discover and opt in to what it does.
@@ -83,6 +122,22 @@
return LIST.filter(function (x) { return !s[x.id]; }).map(function (x) { return x.label; });
}
/* A field is on only if its own toggle is on AND the section holding it is.
Asked as one question so no caller has to remember to ask both — a field
showing inside a hidden section is not a state anyone wants to reason
about. */
function fieldOn(sections, fields, id) {
var f = FIELDS.filter(function (x) { return x.id === id; })[0];
if (!f) return true;
if (!isOn(sections, f.section)) return false;
return normalizeFields(fields)[id];
}
function offFieldList(fields) {
var s = normalizeFields(fields);
return FIELDS.filter(function (x) { return !s[x.id]; }).map(function (x) { return x.label; });
}
window.WPSections = {
LIST: LIST,
IDS: IDS,
@@ -90,5 +145,13 @@
normalize: normalize,
isOn: isOn,
offList: offList,
FIELDS: FIELDS,
FIELD_IDS: FIELD_IDS,
fieldDefaults: fieldDefaults,
normalizeFields: normalizeFields,
fieldsFor: fieldsFor,
fieldOn: fieldOn,
offFieldList: offFieldList,
};
})(window);