fix(receiving): drop dead staged state — Option B (draft→counted→closed)

Reported 2026-05-20: the receiving state machine had four states
(draft → counted → staged → closed) where the middle pair was pure
ceremony. Real-usage data on entech:

  state distribution: 14 draft, 4 closed (zero `staged` records)
  median dwell counted → staged: 11 seconds
  median dwell staged  → closed: 4 minutes

`staged` captured no fields, fired no gates, mapped to the same SO
`x_fc_receiving_status='partial'` as `counted`. Pure click-through.

Cleanup:
- State Selection retains `staged` as `Staged (legacy)` so historical
  records remain readable; new transitions never write it.
- statusbar_visible drops it from the chevron header.
- action_mark_staged becomes a thin shim that advances counted →
  closed directly (any old button binding still works).
- action_close now accepts `counted` as a valid source state (was
  previously only `staged` / legacy `accepted` / `resolved`).
- View: "Stage for Racking" button removed. "Close" button renamed
  to "Close — Racking Confirmed" so the racking-crew confirmation
  meaning stays obvious.
- _update_so_receiving_status mapping unchanged for legacy `staged`
  (still maps to partial) — only the comment block updated to
  describe the new canonical flow.

Migration 19.0.3.20.0 advances any `staged` records to `closed`
and syncs the linked SO's x_fc_receiving_status to `received` so
downstream gates (job step start, mark_done qty check, cert
creation) don't see a stale "partial" status.

Module: fusion_plating_receiving 19.0.3.19.0 → 19.0.3.20.0.

Tests: TestQtyReceivedPropagation updated — 5 tests dropped the
action_mark_staged() call, walk draft → counted → closed directly.
All 11 tests green (carrier 6 + propagation 5).

Verified on entech: existing 14 draft + 4 closed records untouched.
Direct draft → counted → closed transition works end-to-end on
RCV-30041 (was the test target).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-05-20 08:40:43 -04:00
parent d7bee9e854
commit 3d1b6e7ec5
5 changed files with 103 additions and 33 deletions

View File

@@ -54,9 +54,14 @@ class FpReceiving(models.Model):
[
('draft', 'Awaiting Parts'),
('counted', 'Counted'),
('staged', 'Staged for Racking'),
('closed', 'Closed'),
# Legacy values — kept readable, never written by new code
# Legacy values — kept readable, never written by new code.
# 2026-05-20: `staged` collapsed away. The state had zero
# downstream effect (same SO mapping as counted, no field
# captured, action_mark_staged just flipped a flag) and
# median dwell was 11 sec — pure ceremony. Pre-migrate
# advances any existing 'staged' record to 'closed'.
('staged', 'Staged (legacy)'),
('inspecting', 'Inspecting (legacy)'),
('accepted', 'Accepted (legacy)'),
('discrepancy', 'Discrepancy (legacy)'),
@@ -768,20 +773,33 @@ class FpReceiving(models.Model):
) % {'user': self.env.user.name, 'n': rec.box_count_in})
def action_mark_staged(self):
"""Boxes are in the racking area, awaiting the racking crew."""
"""Deprecated 2026-05-20 — `staged` state was dead ceremony
(median dwell 11 sec, no captured data, no downstream effect).
Kept as a thin shim so any legacy button binding still works:
it advances counted records straight to closed.
"""
for rec in self:
if rec.state not in ('counted',):
raise UserError(_('Only Counted records can be marked Staged.'))
rec.state = 'staged'
rec._update_so_receiving_status()
rec.message_post(body=_('Boxes staged for racking.'))
if rec.state != 'counted':
raise UserError(_(
'Only Counted records can be closed. Stage-for-racking '
'is no longer a separate step.'
))
rec.action_close()
def action_close(self):
"""Close the receiving — all boxes opened, inspection complete."""
"""Close the receiving — all boxes opened, inspection complete.
2026-05-20: now reachable directly from `counted` (the `staged`
intermediate was dropped). Legacy values 'staged' / 'accepted'
/ 'resolved' still accepted so pre-Sub-8 records can be closed
without manual SQL surgery.
"""
for rec in self:
if rec.state not in ('staged', 'accepted', 'resolved'):
raise UserError(_('Only Staged (or legacy Accepted / Resolved) '
'records can be closed.'))
if rec.state not in ('counted', 'staged', 'accepted', 'resolved'):
raise UserError(_(
'Only Counted (or legacy Staged / Accepted / Resolved) '
'records can be closed.'
))
rec.state = 'closed'
rec._update_so_receiving_status()
rec.message_post(body=_('Receiving closed.'))
@@ -859,14 +877,16 @@ class FpReceiving(models.Model):
def _update_so_receiving_status(self):
"""Update the linked sale order's receiving status.
Sub 8 maps the new box-count-only states (`counted`, `staged`,
`closed`) onto the SO's `x_fc_receiving_status`:
Sub 8 + 2026-05-20 cleanup map the receiving states onto the
SO's `x_fc_receiving_status`:
- draft -> not_received (no rows or just-created)
- counted / staged -> partial (boxes on dock, parts not yet
racked / inspected)
- closed -> received (all boxes opened, racking done)
Legacy states (inspecting / accepted / discrepancy / resolved) keep
their original mapping for back-compat with pre-Sub-8 records.
- counted -> partial (boxes on dock,
parts not yet racked)
- closed -> received (all boxes opened,
racking confirmed)
Legacy values (staged / inspecting / accepted / discrepancy /
resolved) keep their pre-Sub-8 / pre-cleanup mapping so
records that haven't been touched still resolve sanely.
"""
for rec in self:
if not rec.sale_order_id: