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,8 +60,16 @@ def save_fg_scan(operator_code, cp_code, oc1_code, oc2_code, defect_code, date,
|
||||
tuple: (success: bool, approved_count: int, rejected_count: int)
|
||||
"""
|
||||
try:
|
||||
from datetime import datetime
|
||||
|
||||
db = get_db()
|
||||
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_query = """
|
||||
|
||||
@@ -35,6 +35,10 @@
|
||||
|
||||
<label for="date_time">Date/Time:</label>
|
||||
<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">
|
||||
<button type="submit" class="btn-submit">Submit Scan</button>
|
||||
@@ -671,11 +675,22 @@ defectCodeInput.addEventListener('input', function() {
|
||||
const seconds = String(now.getSeconds()).padStart(2, '0');
|
||||
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
|
||||
const dateStr = timeInput.value.split(' ').slice(0, -1).join(' '); // Get date part
|
||||
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('✅ Date field set to:', dateValue);
|
||||
|
||||
// Save current scan data to localStorage for clearing after reload
|
||||
localStorage.setItem('fg_scan_clear_after_submit', 'true');
|
||||
|
||||
Reference in New Issue
Block a user