A comprehensive manufacturing and cost estimation system built on Frappe/ERPNext framework for National Paper Factory.
Complete manufacturing cost estimation system with dynamic calculations, item creation, and comprehensive workflow management.
- Dynamic Cost Calculation: Real-time calculation of paper costs, consumables, operations, and overheads
- Automatic Item Creation: Creates finished goods items upon BOM submission
- Quotation Generation: Direct quotation creation from approved BOMs
- Multi-level Calculations: Cascading calculations across all cost components
- Status Management: Automated status tracking through complete workflow lifecycle
- Opportunity Integration: Bi-directional status updates with linked Opportunities
- Weight Per PLY Calculation:
(Size 1 Γ Size 2 Γ· 10000) Γ GSM - Amount Calculation:
Math.round(Weight Per PLY Γ Rate) - Total Board GSM: Sum of all GSM values
- Total Weight Per PLY: Sum of all weight calculations
- Total Amount: Sum of all paper costs
- Rate Fetching: Automatic rate retrieval from Stock Settings β Item valuation
- Item Group Filtering: Filters items by 'Consumable' group
- Minimum Quantity Control: Enforces qty β₯ 1
- Rate Auto-fetch: Stock Settings warehouse β Item valuation rate
- Amount Calculation:
Qty Γ Rate - Total Consumables: Sum of all consumable costs
- Workstation Integration: Auto-fetches hour rates from Operation β Workstation
- Operating Cost Calculation:
(Operation Time Γ· 60) Γ Hour Rate - Total Operating Cost: Sum of all operation costs
- Time-based Costing: Supports minute-based time entry
Specific calculation formulas for different overhead types:
- Cost Of Paper:
Total Amount(from Paper table) - Consumables:
Total Consumables Amount - Direct Labour:
Total Operating Cost - Factory Overhead:
Cost Of Paper Γ 3% - Indirect Labour:
Quantity Required Γ Total Weight Per PLY Γ· 1000 Γ 0.006 - Prime Cost: Sum of all overheads (excluding General Overhead)
- General Overhead:
General Overhead Percentage Γ Prime Cost - Total Cost:
Prime Cost + General Overhead
- Case-insensitive Overhead Matching: Handles "Labour" vs "Labor" spellings
- Cascading Updates: Changes trigger dependent recalculations
- Field Validation: Comprehensive error checking and user guidance
- Dynamic Field Visibility: Item code fields show/hide based on creation status
- Automated Status Workflow: Complete status lifecycle management
- Dashboard Message Management: Clear, non-duplicate status displays
- Draft β Initial state before submission
- Submit Estimate BOM β Automatically:
- Creates finished goods item (if not exists)
- Creates and submits BOM automatically β¨
- Sets status to "To Quotation"
- Updates Opportunity status to "Quotation"
- Create Quotation β Status stays "To Quotation" (BOM already exists)
- Submit Quotation β Status changes to "To Sales Order" + Opportunity β "Converted"
- Submit Sales Order β Status changes to "Completed"
- Cancellation β Reverts appropriate statuses
Draft β To Quotation β To Sales Order β Completed
β β
| |
Estimate BOM Quotation
Submit Submitted
(BOM Auto-
Created)
- On Estimate BOM Submit: Opportunity status β "Quotation"
- On Quotation Submit: Estimate BOM β "To Sales Order", Opportunity β "Converted"
- On Sales Order Submit: Estimate BOM β "Completed"
- On Estimate BOM Cancel: Opportunity status β "Open"
- Button Visibility: "Create Estimate BOM" button hidden when Opportunity is "Converted"
- Trigger:
on_submit()- Automatically creates BOM after item creation - Contents: All paper items, consumables, and operations from Estimate BOM
- Submission: BOM is automatically submitted
- Status Behavior: BOM submission does NOT change Estimate BOM status (hooks disabled)
- Status Changes: Only Quotation/Sales Order submissions trigger status updates
- Error Handling: Comprehensive logging; failures don't block Estimate BOM submission
- Validation: Ensures item exists before BOM creation
- Execution Order:
before_submit()β Creates itemon_submit()β Sets status to "To Quotation" & auto-creates/submits BOM- BOM hooks disabled β Status stays "To Quotation"
- Quotation submit β Triggers status β "To Sales Order"
- Status Persistence: Direct database updates with commit
- Override Class: Disabled in hooks.py - uses main doctype class
- Cache Management: Proper cache clearing ensures updates take effect
- Lifecycle Hooks:
before_submit(): Creates item and updates Opportunityon_submit(): Sets status to "To Quotation" & auto-creates BOMon_cancel(): Reverts Opportunity status to "Open"on_update(): Only updates status for draft documents (docstatus == 0)
- BOM Hooks: β Disabled (BOM auto-created but doesn't change status)
- Quotation Hooks: β
Enabled
on_submit: Estimate BOM β "To Sales Order", Opportunity β "Converted"on_cancel: Estimate BOM β "To Quotation", Opportunity β "Quotation"
- Sales Order Hooks: β
Enabled
on_submit: Estimate BOM β "Completed"on_cancel: Estimate BOM β "To Sales Order"
Workflow Logic: BOM is auto-created for manufacturing but doesn't affect sales workflow. Status changes only when Quotation/Sales Order are created, maintaining proper sales process tracking.
- Sales Order Reference Display: Shows linked Sales Order information in Production Plan list view
- Estimate BOM Linking: Maintains Estimate BOM references through production workflow
- Work Order Creation: Enhanced Work Order creation with automatic Estimate BOM transfer
- Header-level Estimate BOM: Custom field at Work Order header (not item level)
- Automatic Population: Estimate BOM automatically transferred from Production Plan during Work Order creation
- Estimate BOM Viewing: Direct link to view associated Estimate BOM from Work Order
- Dashboard Information: Shows linked Estimate BOM and source Production Plan details
- Estimate BOM β Production Plan: References maintained during planning
- Production Plan β Work Order: Automatic Estimate BOM field population
- Multi-hook System: Multiple validation points ensure reliable data transfer
- Traceability: Complete audit trail from estimation to production execution
- GSM (Grams per Square Meter): For paper specifications
- Size of CTN: Carton size specifications
- Weight/CTN: Carton weight specifications
- Custom Specifications: Detailed product specifications
- Automatic Item Generation: Creates finished goods from BOM data
- Field Mapping: Maps BOM specifications to Item fields
- NPF Settings Integration: Uses default item groups from configuration
- Dual Field System: Separate input and link fields for better UX
- Complete Data Transfer: All customer, item, and pricing data
- Estimate BOM Linking:
custom_estimate_bomfield for traceability - Read-only Field Handling: Force-sets fields using database operations
- Error Handling: Comprehensive validation and user feedback
- Customer Mapping: Proper party_name and customer_name fields
- Item Details: Complete item code, quantity, and specifications
- Pricing: Uses unit price from BOM as quotation rate
- Traceability: Direct link back to source Estimate BOM
- Default Item Groups: Configurable item group assignments
- Paper Item Group: Filter for raw material items
- Finished Goods Group: Default for created items
- Warehouse Settings: Default warehouse for rate fetching
cd $PATH_TO_YOUR_BENCH
bench get-app natinal_pf https://github.com/exvas/natinal_pf.git --branch main
bench install-app natinal_pf- Setup NPF Settings: Configure default item groups and warehouse settings
- Create Item Groups: 'RAW MATERIAL', 'Consumable', and finished goods groups
- Configure Overheads: Set up overhead types and calculation parameters
- Setup Production Planning: Configure warehouses and production workflow settings
- Basic Information: Customer, item code, specifications, quantity, paper dimensions
- Paper Details: Add paper items with automatic rate fetching and weight calculations
- Consumables: Add consumable items with quantity controls and rate auto-fetch
- Operations: Add operations with workstation integration and cost calculations
- Overheads: Add overhead types with automatic formula-based calculations
- Submit: Automatically:
- Creates finished goods item
- Sets status to "To Quotation"
- Creates and submits BOM (includes all paper, consumables, operations)
- BOM submission updates status to "To Sales Order"
- Updates linked Opportunity status
The system now handles everything automatically when you submit an Estimate BOM:
- β Item Creation: Finished goods item created automatically
- β Status Update: Status set to "To Quotation"
- β BOM Creation: Complete BOM with all materials and operations
- β BOM Submission: BOM automatically submitted
- β Status Progression: Status updated to "To Sales Order"
- β Opportunity Sync: Opportunity status updated to "Quotation"
No manual BOM creation needed! Everything happens in one click when you submit the Estimate BOM.
-
Estimate BOM Submission:
- Item auto-created (if not exists)
- Status β "To Quotation"
- BOM auto-created and submitted
- Status β "To Sales Order"
- Opportunity β "Quotation" (if linked)
-
Quotation Creation: Use "Create β Quotation" button from submitted Estimate BOM
-
Estimate BOM Cancellation:
- Status β "Cancelled"
- Opportunity β "Open" (if linked)
- BOM remains (can be cancelled separately)
-
Recovery Functions (if needed):
fix_estimate_bom_status_after_submit(): Fix all submitted BOMs with wrong statusfix_missing_item_for_estimate_bom(name): Create missing item for specific BOMcreate_bom_from_estimate(name): Manually create BOM if auto-creation failed
- Create Production Plan: Link to Sales Order and include Estimate BOM references
- Generate Work Orders: Estimate BOM automatically transferred to Work Orders
- Track Progress: Full traceability from estimation through production execution
Use "Create β Quotation" button from submitted Estimate BOM for automatic data transfer and traceability.
- β Complete Manufacturing Cost Estimation with dynamic calculations
- β Automatic Item Creation from Estimate BOMs with custom specifications
- β Automatic BOM Creation & Submission - fully automated on Estimate BOM submit
- β Quotation Generation with full data transfer and traceability
- β Production Planning Integration with Sales Order references
- β Work Order Management with Estimate BOM linking at header level
- β Multi-level Overhead Calculations with formula-based automation
- β Real-time Rate Fetching from stock settings and item valuations
- β Comprehensive Automated Workflow from estimation to BOM to production
- β Automated Status Management with BOM and Opportunity integration
- β Dashboard Message Control with duplicate prevention
- β Error Recovery Functions for status and item creation issues
- β One-Click Submission - Item, BOM, and status updates all automated
Cause: Cache not cleared after code changes
Solution:
cd /path/to/frappe-bench
bench --site your-site clear-cache
bench restartCause: Error in item creation or validation failure
Solution: Check error logs and use fix function
bench --site your-site execute "natinal_pf.natinal_pf.doctype.estimate_bom.estimate_bom.fix_missing_item_for_estimate_bom" --args "['BOM-ID']"Cause: Missing materials or validation error
Solution: Manually create BOM using recovery function
bench --site your-site execute "natinal_pf.natinal_pf.doctype.estimate_bom.estimate_bom.create_bom_from_estimate" --args "['ESTIMATE-BOM-ID']"Cause: Cache issue or hook not triggered
Solution: Clear cache, restart, and check error logs
bench --site your-site execute "natinal_pf.natinal_pf.doctype.estimate_bom.estimate_bom.fix_missing_item_for_estimate_bom" --args "['BOM-ID']"Cause: Override class in /overrides/estimate_bom.py lacks methods
Solution: Override class is disabled in hooks.py (line 149 commented out). Main doctype class is used instead.
Cause: Hooks are disabled in hooks.py for stability
Solution: Uncomment lines 164-170 in hooks.py to enable, then clear cache and restart
This app uses pre-commit for code formatting and linting:
cd apps/natinal_pf
pre-commit installPre-commit tools: ruff, eslint, prettier, pyupgrade
MIT
Developed for National Paper Factory to streamline manufacturing cost estimation and quotation processes in Frappe/ERPNext environment.
- Frappe Framework v14+
- ERPNext v14+
- Python 3.8+
- MariaDB/MySQL