Skip to content

feat: derive tool status from the matching Supplier PO line item - #18

Open
Guru107 wants to merge 5 commits into
developfrom
feature/tooling-status
Open

feat: derive tool status from the matching Supplier PO line item#18
Guru107 wants to merge 5 commits into
developfrom
feature/tooling-status

Conversation

@Guru107

@Guru107 Guru107 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Follow-up to the merged tooling work. Makes tool_status on each tool line derived, not manually entered, from the matching Supplier Purchase Order line item.

Behaviour

Status is per-tool, matched by supplier_po + tool_item against Purchase Order Item, using that line's received_qty vs qty:

  • received 0 → Ordered
  • 0 < received < qty → Partially Received
  • received ≥ qty → Received
  • PO draft → Draft, PO cancelled → Cancelled, tool not a line on the PO → Not on PO, no PO → blank

So on one PO with two tools where only one is received, that tool shows Received while the other shows Ordered — each line reflects its own PO line, not the PO header.

Implementation

  • tool_status is now read-only Data (was a manual Select).
  • Pure compute_tool_status(docstatus, po_item_rows) in the doctype controller, with get_tool_po_status() for the single lookup (used on save via validate).
  • Live in the Tooling Recovery Register, computed with a batched pre-fetch (two queries total, no per-row N+1).
  • On-demand "Refresh Status" button → utils.tooling_utils.refresh_tool_statuses (requires write permission) re-pulls statuses for receipts that land after the last save.
  • Migration patch backfill_tool_status re-derives legacy Select values on existing rows.

Verification

  • Tests cover the per-PO-line mapping (one received / one not), draft PO, no PO, "Not on PO", the live report column, and the refresh path.
  • pre-commit run --all-files → exit 0.
  • Full app suite 78/78 on v15 and v16.

Guru107 added 5 commits July 30, 2026 11:53
tool_status is no longer entered manually — it's read-only and derived
from the Purchase Order Item matching the line's supplier_po + tool_item,
using that line's received_qty vs qty. On a PO with several tools, each
tool reflects its own line: a received tool shows Received while an
unreceived tool on the same PO shows Ordered (Draft/Partially Received/
Cancelled also derived).

Set on save via the controller, computed live in the Tooling Recovery
Register, and refreshable on demand via utils.tooling_utils.refresh_tool_statuses
(wired to a 'Refresh from ERPNext' button) for receipts that land after
the last save. Tests cover the per-PO-line mapping, draft PO, no-PO, and
the refresh path; verified on v15 and v16 (76/76).
…kfill

- Report: derive tool status via a batched pre-fetch (compute_tool_status
  over two queries total) instead of a per-row query pair, removing the
  N+1 at register scale.
- Extract pure compute_tool_status(docstatus, po_item_rows) shared by the
  single lookup and the report; get_tool_po_status now skips the line
  query for non-submitted POs.
- Neutral 'Not on PO' fallback when a tool isn't a line on the linked PO
  (was leaking the PO header status).
- refresh_tool_statuses now requires write permission (it writes derived
  values), not read.
- Add patches/v1_0/backfill_tool_status to re-derive legacy Select values
  ('PO Issued', 'In Development') on existing rows.
- Tests: cover the 'Not on PO' fallback and the report's live per-line
  status. Full suite 78/78 on v15 and v16.
…patch

Replace the single-item get_tool_po_status with a batched
get_tool_po_statuses((supplier_po, tool_item) -> status) used
consistently by the controller save path, the report, the refresh
helper, and the backfill patch — each derives statuses in two queries
regardless of row count. The report also now derives status only for the
rows it actually emits (after the parent/recovery-status filters),
avoiding fetching PO data for skipped rows. Behaviour unchanged;
78/78 on v15 and v16.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant