Price Book
Attributes Feature Guide
Complete guide to price book attributes, filters, and estimate integration.
10 min read🏷️ Dynamic Attributes Feature Guide
Overview
The Dynamic Attributes feature allows you to add custom key-value pairs to both Inventory Items and Price Book Items. This enables flexible categorization and powerful filtering capabilities.
Features Implemented
1. Database Schema
- Added
attributesJSONB field toinventory_itemstable - Added
attributesJSONB field toprice_book_itemstable - Created GIN indexes for efficient JSONB queries
- Supports unlimited custom attributes per item
2. Backend API Endpoints
Query Inventory by Attributes
GET /api/item-attributes/inventory
Query Parameters:
- attributes: JSON object of key-value pairs (e.g., {"Color": "Red", "Size": "Large"})
- matchAll: boolean (true = match ALL attributes, false = match ANY)
- category: optional category filter
- isActive: optional active status filter
Query Price Book by Attributes
GET /api/item-attributes/price-book
Query Parameters:
- attributes: JSON object of key-value pairs
- matchAll: boolean
- category: optional category filter
- itemType: optional item type filter
- isActive: optional active status filter
Get Available Attributes
GET /api/item-attributes/available-attributes
Query Parameters:
- type: 'inventory' | 'pricebook' | 'both' (default: 'both')
Returns: Array of unique attribute keys used across items
Get Attribute Values
GET /api/item-attributes/attribute-values
Query Parameters:
- key: attribute key to get values for
- type: 'inventory' | 'pricebook' | 'both' (default: 'both')
Returns: Array of unique values for the specified attribute key
3. Frontend Components
AttributesManager Component
Location:
apps/web/src/components/inventory/AttributesManager.tsxFeatures:
- Add/edit/remove custom attributes
- Autocomplete for existing attribute keys
- Autocomplete for common attribute values
- Visual key-value pair management
- Helpful examples for new users
AttributesTestPage
Location:
apps/web/src/pages/inventory/AttributesTestPage.tsxFeatures:
- Test interface for querying items by attributes
- Switch between inventory and price book
- AND/OR logic toggle
- Real-time results display
- Shows available attributes and their values
4. Integration
The Attributes Manager is integrated into:
- ✅ Inventory Item Create/Edit Form
- ✅ Price Book Item Create/Edit Form (ready to add)
Usage Examples
Example 1: Garage Door Parts
{
"Color": "White",
"Material": "Steel",
"Size": "16x7",
"Insulation": "R-16",
"Brand": "Clopay"
}
Example 2: Paint Products
{
"Color": "Eggshell White",
"Finish": "Matte",
"Brand": "Sherwin Williams",
"Coverage": "400 sq ft",
"Type": "Interior"
}
Example 3: HVAC Filters
{
"Size": "16x20x1",
"MERV Rating": "13",
"Brand": "Filtrete",
"Type": "Pleated"
}
Testing Instructions
1. Start the Development Server
cd HomeImprovment
npm run dev:web # Start web frontend
npm run dev:api # Start API backend (in another terminal)
2. Test Attributes on Inventory Items
- Navigate to Inventory page
- Create or edit an inventory item
- Scroll to "Custom Attributes" section
- Click "Add Attribute"
- Enter attribute name (e.g., "Color") and value (e.g., "Red")
- Click "Add" and save the item
3. Test Attributes Query
- Navigate to
/inventory/attributes-test(test page) - Select "Inventory Items" or "Price Book Items"
- Add attributes to search for
- Toggle "Match ALL" / "Match ANY"
- Click "Search"
- View results in the table
4. Test API Directly
# Get all inventory items with Color=Red
curl -H "Authorization: Bearer YOUR_TOKEN" \
"http://localhost:3001/api/item-attributes/inventory?attributes={\"Color\":\"Red\"}"
# Get all price book items with Size=Large OR Material=Steel
curl -H "Authorization: Bearer YOUR_TOKEN" \
"http://localhost:3001/api/item-attributes/price-book?attributes={\"Size\":\"Large\",\"Material\":\"Steel\"}&matchAll=false"
# Get all available attribute keys
curl -H "Authorization: Bearer YOUR_TOKEN" \
"http://localhost:3001/api/item-attributes/available-attributes?type=inventory"
# Get all values for "Color" attribute
curl -H "Authorization: Bearer YOUR_TOKEN" \
"http://localhost:3001/api/item-attributes/attribute-values?key=Color&type=inventory"
Common Use Cases
1. Product Variants
- Track different colors, sizes, or models of the same product
- Example: "Garage Door - 16x7 White" vs "Garage Door - 16x7 Brown"
2. Filtering & Search
- Find all items by brand
- Find all items with specific dimensions
- Find all items with certain certifications
3. Inventory Organization
- Group items by manufacturer
- Organize by material type
- Categorize by application
4. Reporting
- Generate reports by attribute
- Track inventory by custom categories
- Analyze sales by product characteristics
Performance Notes
- JSONB fields are indexed with GIN indexes for fast queries
- Queries support both exact matches and partial matches
- AND/OR logic allows flexible filtering
- Autocomplete reduces typing and ensures consistency
Future Enhancements
Potential improvements:
- Attribute templates by category
- Bulk attribute assignment
- Attribute-based pricing rules
- Export/import attributes
- Attribute validation rules
- Required vs optional attributes
- Attribute groups/categories
API Response Examples
Query Inventory Response
{
"success": true,
"data": [
{
"id": "item-123",
"name": "Garage Door Panel",
"sku": "GD-PANEL-001",
"category": "Doors",
"currentStock": 15,
"attributes": {
"Color": "White",
"Size": "16x7",
"Material": "Steel"
},
"priceBookItem": {
"id": "pb-456",
"name": "Garage Door Panel",
"unitPrice": 299.99
}
}
],
"count": 1
}
Available Attributes Response
{
"success": true,
"data": [
"Color",
"Size",
"Material",
"Brand",
"Model"
]
}
Attribute Values Response
{
"success": true,
"data": [
"White",
"Brown",
"Black",
"Tan"
]
}
Troubleshooting
Attributes not saving
- Check that the
attributesfield is included in the form data - Verify the API request includes the attributes in the body
- Check browser console for errors
Query returns no results
- Verify the attribute keys match exactly (case-sensitive)
- Try using
matchAll=falsefor broader results - Check that items actually have the attributes you're searching for
Autocomplete not working
- Ensure items with attributes exist in the database
- Check that the API endpoints are accessible
- Verify the Redux store is properly configured
Support
For issues or questions:
- Check the browser console for errors
- Check the API logs for backend errors
- Verify database migrations ran successfully
- Test with the AttributesTestPage first
Status: ✅ Backend Complete | ✅ Frontend Complete | ⏳ Ready for Testing