v0.14.0 - Major Logic Overhaul & Real-Time Dashboard
Logic: Implemented "One User, One Bin" locking to prevent duplicate counting.
Integrity: Standardized is_deleted = 0 and tightened "Matched" criteria to require zero weight variance.
Refresh: Added silent 30-second dashboard polling for all 6 status categories and active counter list.
Tracking: Built user-specific activity tracking to identify who is counting where in real-time.
Stability: Resolved persistent 500 errors by finalizing the active-counters-fragment structure.
This commit is contained in:
@@ -24,7 +24,7 @@ def create_session():
|
||||
flash(f'Session "{session_name}" created successfully!', 'success')
|
||||
return redirect(url_for('sessions.session_detail', session_id=session_id))
|
||||
|
||||
return render_template('create_session.html')
|
||||
return render_template('/counts/create_session.html')
|
||||
|
||||
|
||||
@sessions_bp.route('/session/<int:session_id>')
|
||||
@@ -54,24 +54,38 @@ def session_detail(session_id):
|
||||
''', [session_id], one=True)
|
||||
|
||||
# Get location progress
|
||||
# We add a subquery to count the actual missing lots for each bin
|
||||
locations = query_db('''
|
||||
SELECT lc.*, u.full_name as counter_name
|
||||
SELECT
|
||||
lc.*,
|
||||
u.full_name as counter_name,
|
||||
(SELECT COUNT(*) FROM MissingLots ml
|
||||
WHERE ml.session_id = lc.session_id
|
||||
AND ml.master_expected_location = lc.location_name) as lots_missing_calc
|
||||
FROM LocationCounts lc
|
||||
LEFT JOIN Users u ON lc.counted_by = u.user_id
|
||||
WHERE lc.session_id = ?
|
||||
AND lc.is_deleted = 0
|
||||
ORDER BY lc.status DESC, lc.location_name
|
||||
''', [session_id])
|
||||
|
||||
# Get active counters
|
||||
active_counters = query_db('''
|
||||
SELECT DISTINCT u.full_name, lc.location_name, lc.start_timestamp
|
||||
SELECT
|
||||
u.full_name,
|
||||
u.user_id,
|
||||
MAX(lc.start_timestamp) AS start_timestamp, -- Add the alias here!
|
||||
lc.location_name
|
||||
FROM LocationCounts lc
|
||||
JOIN Users u ON lc.counted_by = u.user_id
|
||||
WHERE lc.session_id = ? AND lc.status = 'in_progress'
|
||||
ORDER BY lc.start_timestamp DESC
|
||||
WHERE lc.session_id = ?
|
||||
AND lc.status = 'in_progress'
|
||||
AND lc.is_deleted = 0
|
||||
GROUP BY u.user_id
|
||||
ORDER BY start_timestamp DESC
|
||||
''', [session_id])
|
||||
|
||||
return render_template('session_detail.html',
|
||||
return render_template('/counts/session_detail.html',
|
||||
count_session=sess,
|
||||
stats=stats,
|
||||
locations=locations,
|
||||
@@ -98,6 +112,7 @@ def get_status_details(session_id, status):
|
||||
WHERE se.session_id = ?
|
||||
AND se.master_status = 'match'
|
||||
AND se.duplicate_status = '00'
|
||||
AND se.master_variance_lbs = 0
|
||||
AND se.is_deleted = 0
|
||||
ORDER BY se.scan_timestamp DESC
|
||||
''', [session_id])
|
||||
@@ -184,20 +199,21 @@ def get_status_details(session_id, status):
|
||||
# Missing lots (in master but not scanned)
|
||||
items = query_db('''
|
||||
SELECT
|
||||
bim.lot_number,
|
||||
bim.item,
|
||||
ml.lot_number,
|
||||
ml.item,
|
||||
bim.description,
|
||||
bim.system_bin,
|
||||
bim.system_quantity
|
||||
FROM BaselineInventory_Master bim
|
||||
WHERE bim.session_id = ?
|
||||
AND bim.lot_number NOT IN (
|
||||
SELECT lot_number
|
||||
FROM ScanEntries
|
||||
WHERE session_id = ? AND is_deleted = 0
|
||||
)
|
||||
ORDER BY bim.system_bin, bim.lot_number
|
||||
''', [session_id, session_id])
|
||||
ml.master_expected_location as system_bin,
|
||||
ml.master_expected_quantity as system_quantity
|
||||
FROM MissingLots ml
|
||||
LEFT JOIN BaselineInventory_Master bim ON
|
||||
ml.lot_number = bim.lot_number AND
|
||||
ml.item = bim.item AND
|
||||
ml.master_expected_location = bim.system_bin AND
|
||||
ml.session_id = bim.session_id
|
||||
WHERE ml.session_id = ?
|
||||
GROUP BY ml.lot_number, ml.item, ml.master_expected_location
|
||||
ORDER BY ml.master_expected_location, ml.lot_number
|
||||
''', [session_id])
|
||||
else:
|
||||
return jsonify({'success': False, 'message': 'Invalid status'})
|
||||
|
||||
@@ -241,4 +257,40 @@ def activate_session(session_id):
|
||||
|
||||
execute_db('UPDATE CountSessions SET status = ? WHERE session_id = ?', ['active', session_id])
|
||||
|
||||
return jsonify({'success': True, 'message': 'Session activated successfully'})
|
||||
return jsonify({'success': True, 'message': 'Session activated successfully'})
|
||||
|
||||
@sessions_bp.route('/session/<int:session_id>/get_stats')
|
||||
@role_required('owner', 'admin')
|
||||
def get_session_stats(session_id):
|
||||
stats = query_db('''
|
||||
SELECT
|
||||
COUNT(DISTINCT se.entry_id) FILTER (WHERE se.master_status = 'match' AND se.duplicate_status = '00' AND se.master_variance_lbs = 0 AND se.is_deleted = 0 AND ABS(se.actual_weight - se.master_expected_weight) < 0.01) as matched,
|
||||
COUNT(DISTINCT se.lot_number) FILTER (WHERE se.duplicate_status IN ('01', '03', '04') AND se.is_deleted = 0) as duplicates,
|
||||
COUNT(DISTINCT se.entry_id) FILTER (WHERE se.master_status = 'match' AND se.duplicate_status = '00' AND se.is_deleted = 0 AND ABS(se.actual_weight - se.master_expected_weight) >= 0.01) as discrepancy,
|
||||
COUNT(DISTINCT se.entry_id) FILTER (WHERE se.master_status = 'wrong_location' AND se.is_deleted = 0) as wrong_location,
|
||||
COUNT(DISTINCT se.entry_id) FILTER (WHERE se.master_status = 'ghost_lot' AND se.is_deleted = 0) as ghost_lots,
|
||||
COUNT(DISTINCT ml.missing_id) as missing
|
||||
FROM CountSessions cs
|
||||
LEFT JOIN ScanEntries se ON cs.session_id = se.session_id
|
||||
LEFT JOIN MissingLots ml ON cs.session_id = ml.session_id
|
||||
WHERE cs.session_id = ?
|
||||
''', [session_id], one=True)
|
||||
|
||||
return jsonify(success=True, stats=dict(stats))
|
||||
@sessions_bp.route('/session/<int:session_id>/active-counters-fragment')
|
||||
@role_required('owner', 'admin')
|
||||
def active_counters_fragment(session_id):
|
||||
# Use that unique-user query we just built together
|
||||
active_counters = query_db('''
|
||||
SELECT
|
||||
u.full_name,
|
||||
MAX(lc.start_timestamp) AS start_timestamp,
|
||||
lc.location_name
|
||||
FROM LocationCounts lc
|
||||
JOIN Users u ON lc.counted_by = u.user_id
|
||||
WHERE lc.session_id = ? AND lc.status = 'in_progress' AND lc.is_deleted = 0
|
||||
GROUP BY u.user_id
|
||||
''', [session_id])
|
||||
|
||||
# This renders JUST the list part, not the whole page
|
||||
return render_template('counts/partials/_active_counters.html', active_counters=active_counters)
|
||||
|
||||
Reference in New Issue
Block a user