Enhance Sp7 Query Builder to Support Calculated Fields - #7410
Closed
grantfitzsimmons with Copilot wants to merge 2 commits into
Closed
Enhance Sp7 Query Builder to Support Calculated Fields#7410grantfitzsimmons with Copilot wants to merge 2 commits into
grantfitzsimmons with Copilot wants to merge 2 commits into
Conversation
Copilot
AI
changed the title
[WIP] Enhancing Sp7 Query Builder to Support Calculated Fields
Enhance Sp7 Query Builder to Support Calculated Fields
Sep 12, 2025
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.
This PR implements support for calculated fields in the Sp7 Query Builder, bringing feature parity with the Sp6 query builder for calculated field functionality.
Problem
The Sp7 query builder was unable to query calculated fields like
actualCountAmt,totalPreps,isOnLoan, etc., even though these fields were already computed and available in the API. Users needed to access these fields through the query builder interface to create sophisticated queries for collection management workflows.Solution
Enhanced the query field specification system to recognize and generate SQL expressions for calculated fields:
Key Changes
Enhanced
PRECALCULATED_FIELDSDictionary: Updated to include all calculated fields with proper camelCase naming to match frontend schema expectations:actualCountAmt,isOnLoan,isOnGift,isOnDisposal,isOnExchangeOut,isOnExchangeIntotalPreps,totalItems,unresolvedPreps,unresolvedItems,resolvedPreps,resolvedItemstotalCountAmt,actualTotalCountAmt,collectionObjectCount,preparationCounttotalPreps,totalItemsImplemented
get_calculated_field_expression()Function: Creates SQLAlchemy expressions for calculated fields using subqueries. For example:Fixed Query Builder Integration: Updated
QueryFieldSpec.add_spec_to_query()to properly handle calculated fields when regular model attributes are not found, falling back to generated SQL expressions.Corrected Model Field References: Fixed all SQLAlchemy model field references to use correct lowercase naming convention (
preparationid,loanid, etc.).Technical Implementation
The solution uses SQLAlchemy subqueries to calculate field values dynamically within queries, ensuring:
Example Usage
Users can now create queries like:
actualCountAmt> 0"unresolvedPreps> 5"totalCountAmt!=actualTotalCountAmt"Validation
Added
validate_calculated_fields.pyscript to verify implementation correctness without requiring full Django environment setup. All tests pass, confirming proper integration between backend calculations and frontend schema expectations.This enhancement resolves the gap between Sp6 and Sp7 query builder capabilities, enabling sophisticated collection management queries using calculated fields.
Created from VS Code via the GitHub Pull Request extension.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.