Skip to main content

datasynth_core/models/
quality_inspection.rs

1//! Quality inspection models for manufacturing processes.
2//!
3//! These models represent quality inspections performed on materials
4//! during incoming receipt, in-process production, and final output.
5
6use chrono::NaiveDate;
7use rust_decimal::Decimal;
8use serde::{Deserialize, Serialize};
9
10/// Result of a quality inspection.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
12#[serde(rename_all = "snake_case")]
13pub enum InspectionResult {
14    /// Material accepted without conditions
15    #[default]
16    Accepted,
17    /// Material rejected
18    Rejected,
19    /// Material accepted with conditions or concessions
20    Conditionally,
21    /// Inspection not yet completed
22    Pending,
23}
24
25/// Type of quality inspection.
26#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
27#[serde(rename_all = "snake_case")]
28pub enum InspectionType {
29    /// Inspection of incoming materials from vendors
30    #[default]
31    Incoming,
32    /// Inspection during production process
33    InProcess,
34    /// Final inspection before delivery or storage
35    Final,
36    /// Random sampling inspection
37    Random,
38    /// Scheduled periodic inspection
39    Periodic,
40}
41
42/// A quality inspection record for a material lot.
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct QualityInspection {
45    /// Unique inspection identifier
46    pub inspection_id: String,
47    /// Company code this inspection belongs to
48    pub company_code: String,
49    /// Type of reference document (e.g., "production_order", "goods_receipt")
50    pub reference_type: String,
51    /// Identifier of the reference document
52    pub reference_id: String,
53    /// Material being inspected
54    pub material_id: String,
55    /// Description of the material being inspected
56    pub material_description: String,
57    /// Type of inspection performed
58    pub inspection_type: InspectionType,
59    /// Date the inspection was performed
60    pub inspection_date: NaiveDate,
61    /// Inspector who performed the inspection
62    pub inspector_id: Option<String>,
63    /// Total lot size under inspection
64    #[serde(with = "rust_decimal::serde::str")]
65    pub lot_size: Decimal,
66    /// Sample size drawn for inspection
67    #[serde(with = "rust_decimal::serde::str")]
68    pub sample_size: Decimal,
69    /// Number of defects found
70    pub defect_count: u32,
71    /// Defect rate (defect_count / sample_size)
72    pub defect_rate: f64,
73    /// Overall inspection result
74    pub result: InspectionResult,
75    /// Individual inspection characteristics measured
76    pub characteristics: Vec<InspectionCharacteristic>,
77    /// Disposition action (e.g., "use_as_is", "return_to_vendor", "scrap")
78    pub disposition: Option<String>,
79    /// Additional notes or observations
80    pub notes: Option<String>,
81}
82
83/// A single measured characteristic within a quality inspection.
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct InspectionCharacteristic {
86    /// Name of the characteristic (e.g., "diameter", "weight", "tensile_strength")
87    pub name: String,
88    /// Target specification value
89    pub target_value: f64,
90    /// Actual measured value
91    pub actual_value: f64,
92    /// Lower specification limit
93    pub lower_limit: f64,
94    /// Upper specification limit
95    pub upper_limit: f64,
96    /// Whether this characteristic passed inspection
97    pub passed: bool,
98}