Stock Cutting Documentation¶
Overview¶
The Stock Cutting module (stock.cut) provides optimization for cutting stock materials to fulfill orders with minimal waste. This module integrates with an external solver service to generate optimal cutting patterns based on available stock widths and order requirements.
Model Information¶
Model Name: stock.cut
Display Name: Stock Cutting
Key Fields: None (no unique constraint defined)
Features¶
- ❌ Audit logging enabled (
_audit_log) - ❌ Multi-company support (
company_id) - ❌ Full-text content search (
_content_search) - ❌ Unique key constraint
Field Reference¶
Header Fields¶
| Field | Type | Required | Description |
|---|---|---|---|
date |
Date | ❌ | Date of the cutting operation (defaults to current date) |
total_waste |
Decimal | ❌ | Computed field showing total waste across all patterns |
Relationship Fields¶
| Field | Type | Description |
|---|---|---|
orders |
One2Many | Links to stock.cut.order - Order requirements to be fulfilled |
stock |
One2Many | Links to stock.cut.stock - Available stock materials |
patterns |
One2Many | Links to stock.cut.pattern - Generated cutting patterns |
API Methods¶
1. Create Record¶
Method: create(vals, context)
Creates a new stock cutting record.
Parameters:
vals = {
"date": "2025-10-27", # Optional: defaults to today
"orders": [ # Related order records
("create", {
"width": 100.0,
"qty": 50,
"qty_type": "exact"
})
],
"stock": [ # Related stock records
("create", {
"width": 200.0,
"qty": 25,
"jumbo": False
})
]
}
Returns: int - New record ID
Example:
# Create a new cutting operation
cut_id = get_model("stock.cut").create({
"date": "2025-10-27",
"orders": [
("create", {
"width": 100.0,
"qty": 50,
"qty_type": "exact"
}),
("create", {
"width": 150.0,
"qty": 30,
"qty_type": "allow"
})
],
"stock": [
("create", {
"width": 300.0,
"qty": 20,
"jumbo": False
})
]
})
2. Solve Cutting Pattern¶
Method: solve(ids, context)
Sends cutting requirements to external solver service and generates optimal cutting patterns.
Parameters:
- ids (list): List of stock.cut record IDs to solve
Behavior:
- Collects all orders (width, qty, qty_type) from the cutting record
- Collects all available stock (width, qty, jumbo flag) from the cutting record
- Sends data to external solver API at http://compass.netforce.com:12080/solve
- Deletes existing patterns and creates new patterns from solver response
- Each pattern shows how to cut stock to fulfill orders with minimal waste
Returns: None (updates patterns in place)
Example:
# Generate optimal cutting patterns
get_model("stock.cut").solve([cut_id])
# The patterns field will be populated with optimal cuts
cut = get_model("stock.cut").browse(cut_id)
for pattern in cut.patterns:
print(f"Stock width: {pattern.stock_width}")
print(f"Repeat {pattern.num} times")
print(f"Cut 1: {pattern.width1} x {pattern.qty1}")
print(f"Waste: {pattern.waste}")
External API Integration:
- Endpoint: POST http://compass.netforce.com:12080/solve
- Request Format: JSON with orders and stock data
- Response Format: JSON with array of cutting patterns
- Error Handling: Raises exception on HTTP errors or missing patterns
Computed Fields Functions¶
get_total_waste(ids, context)¶
Calculates the total waste across all cutting patterns by summing the total_waste field from each pattern line.
Returns: Dictionary mapping record ID to total waste amount
Related Models¶
| Model | Relationship | Description |
|---|---|---|
stock.cut.order |
One2Many | Order requirements that need to be fulfilled |
stock.cut.stock |
One2Many | Available stock materials for cutting |
stock.cut.pattern |
One2Many | Generated cutting patterns with waste calculations |
Common Use Cases¶
Use Case 1: Create Cutting Operation with Solver¶
# 1. Create the cutting record with orders and stock
cut_id = get_model("stock.cut").create({
"date": "2025-10-27",
"orders": [
("create", {"width": 100.0, "qty": 50, "qty_type": "exact"}),
("create", {"width": 150.0, "qty": 30, "qty_type": "allow"}),
],
"stock": [
("create", {"width": 300.0, "qty": 20, "jumbo": False}),
("create", {"width": 250.0, "qty": 15, "jumbo": False}),
]
})
# 2. Solve for optimal patterns
get_model("stock.cut").solve([cut_id])
# 3. Review results
cut = get_model("stock.cut").browse(cut_id)
print(f"Total waste: {cut.total_waste}")
for pattern in cut.patterns:
print(f"Pattern: {pattern.stock_width} repeated {pattern.num} times")
Use Case 2: Analyze Cutting Efficiency¶
# Get cutting record
cut = get_model("stock.cut").browse(cut_id)
# Calculate efficiency
total_material = sum(s.width * s.qty for s in cut.stock)
total_waste = cut.total_waste
efficiency = ((total_material - total_waste) / total_material) * 100
print(f"Cutting efficiency: {efficiency:.2f}%")
print(f"Total waste: {total_waste}")
Integration Points¶
External Systems¶
- Compass Solver Service: External optimization service at
http://compass.netforce.com:12080/solvethat calculates optimal cutting patterns using linear programming or similar algorithms
Internal Modules¶
- Stock Management: Used to track available materials for cutting
- Order Management: Order requirements drive cutting pattern generation
Best Practices¶
1. Verify Solver Availability¶
# Good example: Check solver before creating large cutting operations
import requests
try:
response = requests.get("http://compass.netforce.com:12080/health", timeout=5)
if response.status_code == 200:
# Solver is available, proceed with cutting
get_model("stock.cut").solve([cut_id])
except requests.RequestException:
# Handle solver unavailability
print("Solver service is unavailable")
2. Batch Similar Orders¶
Group orders with similar widths before solving to improve optimization results and reduce computation time.
3. Review Patterns Before Production¶
Always review generated patterns and verify waste percentages are acceptable before proceeding to actual cutting operations.
Troubleshooting¶
"Request failed: [status_code]"¶
Cause: External solver service returned an error or is unavailable
Solution:
- Check solver service status at http://compass.netforce.com:12080
- Verify network connectivity
- Review order and stock data for invalid values (negative numbers, zero quantities)
"Missing patterns"¶
Cause: Solver returned a response without pattern data
Solution:
- Verify that orders and stock data are valid
- Check that stock widths are larger than order widths
- Ensure sufficient stock quantity exists to fulfill orders
Zero or negative waste values¶
Cause: Invalid pattern calculations or data
Solution: Review stock widths and order widths for accuracy
Performance Tips¶
1. Minimize Solver Calls¶
- Collect all orders before calling solve() rather than solving incrementally
- Use batch operations when processing multiple cutting operations
2. Clean Up Old Patterns¶
# Delete old patterns before resolving
cut = get_model("stock.cut").browse(cut_id)
cut.patterns.delete()
get_model("stock.cut").solve([cut_id])
Version History¶
Last Updated: October 2025
Model Version: stock_cut.py
Framework: Netforce
Additional Resources¶
- Stock Cut Order Documentation:
stock.cut.order - Stock Cut Stock Documentation:
stock.cut.stock - Stock Cut Pattern Documentation:
stock.cut.pattern
This documentation is generated for developer onboarding and reference purposes.