Production Traceability provides complete visibility into the journey of materials and products through the manufacturing system, enabling quality control, compliance, and supply chain transparency.
This feature is planned for future implementation as part of the complete production management system.
┌─────────────────────────────────────────┐│ Supplier Shipment ││ - Supplier name ││ - Invoice number ││ - Receipt date │└─────────────────────────────────────────┘ │ ↓┌─────────────────────────────────────────┐│ Raw Material Stock ││ - Material ID & name ││ - Quantity & cost ││ - Storage location │└─────────────────────────────────────────┘ │ ↓┌─────────────────────────────────────────┐│ Material Issue ││ - Production order ││ - Quantity issued ││ - Issue date & person │└─────────────────────────────────────────┘ │ ↓┌─────────────────────────────────────────┐│ Production Order ││ - Order number ││ - Product being made ││ - Production stages ││ - Workers assigned │└─────────────────────────────────────────┘ │ ↓┌─────────────────────────────────────────┐│ Production Completion ││ - Completion date ││ - Quantity completed ││ - Quality inspection │└─────────────────────────────────────────┘ │ ↓┌─────────────────────────────────────────┐│ Finished Product ││ - Product serial/lot number ││ - Inventory location ││ - Ready for sale │└─────────────────────────────────────────┘ │ ↓┌─────────────────────────────────────────┐│ Customer Shipment ││ - Customer name ││ - Order number ││ - Delivery date │└─────────────────────────────────────────┘
class TraceabilityService: @staticmethod def trace_product_to_materials(product_serial: str) -> dict: """ Trace finished product back to source materials. Returns complete chain: - Product details - Production order used - Materials consumed - Material receipts - Suppliers """ # Find finished product by serial number product = FinishedProduct.query.filter_by(serial_number=product_serial).first() # Get production completion record completion = product.completions.first() # Get production order order = completion.production_order # Get material issues for order materials_used = [] for issue in order.material_issues: receipt = issue.material.receipts.order_by( MaterialReceipt.receipt_date.desc() ).first() materials_used.append({ "material": issue.material.name, "quantity_used": issue.quantity_issued, "batch": receipt.batch_number if receipt else None, "supplier": receipt.supplier_name if receipt else None, "receipt_date": receipt.receipt_date if receipt else None }) return { "product": product.to_dict(), "production_order": order.order_number, "completion_date": completion.completion_date, "materials": materials_used } @staticmethod def trace_material_to_products(material_batch: str) -> dict: """ Trace material batch forward to finished products. Returns: - Material receipt details - Production orders that used it - Finished products created - Customer shipments """ # Find material receipt by batch receipt = MaterialReceipt.query.filter_by(batch_number=material_batch).first() # Find material issues using this material # (Simplified - would need batch tracking in issues) material_issues = receipt.material.issues.all() products_created = [] for issue in material_issues: order = issue.production_order for completion in order.product.completions: if completion.production_order_id == order.id_order: products_created.append({ "product": order.product.name, "serial": order.product.serial_number, "completion_date": completion.completion_date, "quantity": completion.quantity_completed }) return { "material": receipt.material.name, "batch": receipt.batch_number, "supplier": receipt.supplier_name, "receipt_date": receipt.receipt_date, "quantity_received": receipt.quantity_received, "products_created": products_created } @staticmethod def get_quality_trail(product_serial: str) -> dict: """ Get complete quality control history for product. Returns all quality checkpoints: - Material receipt inspections - Production stage quality checks - Final product inspection """ product = FinishedProduct.query.filter_by(serial_number=product_serial).first() completion = product.completions.first() order = completion.production_order quality_checks = [] # Production stage checks for stage in order.stages: if 'QC' in stage.stage_name or 'quality' in stage.notes.lower(): quality_checks.append({ "type": "Stage Inspection", "stage": stage.stage_name, "date": stage.end_time, "inspector": stage.worker_name, "notes": stage.notes }) # Final inspection quality_checks.append({ "type": "Final Inspection", "date": completion.completion_date, "inspector": completion.quality_inspector, "status": product.quality_status, "defects": completion.quantity_defective, "notes": completion.quality_notes }) return { "product": product.name, "serial": product_serial, "quality_checks": quality_checks }
Generate unique serial numbers for high-value items:
Format: [TYPE]-[YYYY]-[MMDD]-[SEQ]
Example: TBL-2024-0315-0042
Quality Documentation
Record detailed quality information:
Take photos of defects
Note specific issues found
Track inspector names
Data Retention
Maintain traceability records:
Keep all records for minimum 2-5 years
Never delete traceability data
Archive old records, don’t purge
Critical: Never delete records involved in traceability chains (receipts, issues, completions, shipments). Use soft delete only and archive after appropriate retention period.