Fix: Resolve 'Column date cannot be null' error in FG scan
- Added default date/time handling in save_fg_scan() function - Backend now uses current date/time if values not provided - Added hidden date/time form fields in frontend - Updated JavaScript to populate hidden fields before submission - Prevents null database errors when scanning orders
This commit is contained in:
@@ -60,9 +60,17 @@ def save_fg_scan(operator_code, cp_code, oc1_code, oc2_code, defect_code, date,
|
|||||||
tuple: (success: bool, approved_count: int, rejected_count: int)
|
tuple: (success: bool, approved_count: int, rejected_count: int)
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
|
|
||||||
|
# Default to current date/time if not provided
|
||||||
|
if not date:
|
||||||
|
date = datetime.now().strftime('%Y-%m-%d')
|
||||||
|
if not time:
|
||||||
|
time = datetime.now().strftime('%H:%M:%S')
|
||||||
|
|
||||||
# Insert a new entry - each scan is a separate record
|
# Insert a new entry - each scan is a separate record
|
||||||
insert_query = """
|
insert_query = """
|
||||||
INSERT INTO scanfg_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time)
|
INSERT INTO scanfg_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time)
|
||||||
|
|||||||
@@ -36,6 +36,10 @@
|
|||||||
<label for="date_time">Date/Time:</label>
|
<label for="date_time">Date/Time:</label>
|
||||||
<input type="text" id="date_time" name="date_time" readonly>
|
<input type="text" id="date_time" name="date_time" readonly>
|
||||||
|
|
||||||
|
<!-- Hidden fields for actual date/time submission -->
|
||||||
|
<input type="hidden" id="date" name="date">
|
||||||
|
<input type="hidden" id="time" name="time">
|
||||||
|
|
||||||
<div class="form-buttons">
|
<div class="form-buttons">
|
||||||
<button type="submit" class="btn-submit">Submit Scan</button>
|
<button type="submit" class="btn-submit">Submit Scan</button>
|
||||||
<button type="button" class="btn-clear" id="clearOperator">Clear Quality Operator</button>
|
<button type="button" class="btn-clear" id="clearOperator">Clear Quality Operator</button>
|
||||||
@@ -671,11 +675,22 @@ defectCodeInput.addEventListener('input', function() {
|
|||||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||||
const timeValue = `${hours}:${minutes}:${seconds}`;
|
const timeValue = `${hours}:${minutes}:${seconds}`;
|
||||||
|
|
||||||
|
// Format date as YYYY-MM-DD for database
|
||||||
|
const year = now.getFullYear();
|
||||||
|
const month = String(now.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(now.getDate()).padStart(2, '0');
|
||||||
|
const dateValue = `${year}-${month}-${day}`;
|
||||||
|
|
||||||
// Parse the current datetime display and update just the time part
|
// Parse the current datetime display and update just the time part
|
||||||
const dateStr = timeInput.value.split(' ').slice(0, -1).join(' '); // Get date part
|
const dateStr = timeInput.value.split(' ').slice(0, -1).join(' '); // Get date part
|
||||||
timeInput.value = dateStr + ' ' + timeValue;
|
timeInput.value = dateStr + ' ' + timeValue;
|
||||||
|
|
||||||
|
// Populate hidden date/time fields for form submission
|
||||||
|
document.getElementById('date').value = dateValue;
|
||||||
|
document.getElementById('time').value = timeValue;
|
||||||
|
|
||||||
console.log('✅ Time field updated to:', timeValue);
|
console.log('✅ Time field updated to:', timeValue);
|
||||||
|
console.log('✅ Date field set to:', dateValue);
|
||||||
|
|
||||||
// Save current scan data to localStorage for clearing after reload
|
// Save current scan data to localStorage for clearing after reload
|
||||||
localStorage.setItem('fg_scan_clear_after_submit', 'true');
|
localStorage.setItem('fg_scan_clear_after_submit', 'true');
|
||||||
|
|||||||
Reference in New Issue
Block a user