feat: derive tool status from the matching Supplier PO line item - #18
Open
Guru107 wants to merge 5 commits into
Open
feat: derive tool status from the matching Supplier PO line item#18Guru107 wants to merge 5 commits into
Guru107 wants to merge 5 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the merged tooling work. Makes
tool_statuson 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_itemagainstPurchase Order Item, using that line'sreceived_qtyvsqty: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_statusis now read-onlyData(was a manual Select).compute_tool_status(docstatus, po_item_rows)in the doctype controller, withget_tool_po_status()for the single lookup (used on save viavalidate).utils.tooling_utils.refresh_tool_statuses(requires write permission) re-pulls statuses for receipts that land after the last save.backfill_tool_statusre-derives legacy Select values on existing rows.Verification
pre-commit run --all-files→ exit 0.