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:
@@ -111,16 +111,23 @@ def my_counts(session_id):
|
||||
|
||||
# Get this user's active bins
|
||||
active_bins = query_db('''
|
||||
SELECT lc.*,
|
||||
COUNT(se.entry_id) as scan_count
|
||||
FROM LocationCounts lc
|
||||
LEFT JOIN ScanEntries se ON lc.location_count_id = se.location_count_id AND se.is_deleted = 0
|
||||
WHERE lc.session_id = ?
|
||||
AND lc.counted_by = ?
|
||||
AND lc.status = 'in_progress'
|
||||
GROUP BY lc.location_count_id
|
||||
ORDER BY lc.start_timestamp DESC
|
||||
''', [session_id, session['user_id']])
|
||||
SELECT lc.*,
|
||||
COUNT(se.entry_id) as scan_count
|
||||
FROM LocationCounts lc
|
||||
LEFT JOIN ScanEntries se ON lc.location_count_id = se.location_count_id AND se.is_deleted = 0
|
||||
WHERE lc.session_id = ?
|
||||
AND lc.status = 'in_progress'
|
||||
AND lc.is_deleted = 0
|
||||
AND (
|
||||
lc.counted_by = ?
|
||||
OR lc.location_count_id IN (
|
||||
SELECT location_count_id FROM ScanEntries
|
||||
WHERE scanned_by = ? AND is_deleted = 0
|
||||
)
|
||||
)
|
||||
GROUP BY lc.location_count_id
|
||||
ORDER BY lc.start_timestamp DESC
|
||||
''', [session_id, session['user_id'], session['user_id']])
|
||||
|
||||
# Get this user's completed bins
|
||||
completed_bins = query_db('''
|
||||
@@ -129,11 +136,17 @@ def my_counts(session_id):
|
||||
FROM LocationCounts lc
|
||||
LEFT JOIN ScanEntries se ON lc.location_count_id = se.location_count_id AND se.is_deleted = 0
|
||||
WHERE lc.session_id = ?
|
||||
AND lc.counted_by = ?
|
||||
AND lc.status = 'completed'
|
||||
AND (
|
||||
lc.counted_by = ?
|
||||
OR lc.location_count_id IN (
|
||||
SELECT location_count_id FROM ScanEntries
|
||||
WHERE scanned_by = ? AND is_deleted = 0
|
||||
)
|
||||
)
|
||||
GROUP BY lc.location_count_id
|
||||
ORDER BY lc.end_timestamp DESC
|
||||
''', [session_id, session['user_id']])
|
||||
ORDER BY lc.start_timestamp DESC
|
||||
''', [session_id, session['user_id'], session['user_id']])
|
||||
|
||||
return render_template('counts/my_counts.html',
|
||||
count_session=sess,
|
||||
@@ -144,7 +157,7 @@ def my_counts(session_id):
|
||||
@counting_bp.route('/session/<int:session_id>/start-bin', methods=['POST'])
|
||||
@login_required
|
||||
def start_bin_count(session_id):
|
||||
"""Start counting a new bin"""
|
||||
"""Start counting a new bin or resume an existing in-progress one"""
|
||||
sess = get_active_session(session_id)
|
||||
if not sess:
|
||||
flash('Session not found or archived', 'warning')
|
||||
@@ -158,7 +171,21 @@ def start_bin_count(session_id):
|
||||
if not location_name:
|
||||
flash('Bin number is required', 'danger')
|
||||
return redirect(url_for('counting.my_counts', session_id=session_id))
|
||||
|
||||
|
||||
# --- NEW LOGIC: Check for existing in-progress bin ---
|
||||
existing_bin = query_db('''
|
||||
SELECT location_count_id
|
||||
FROM LocationCounts
|
||||
WHERE session_id = ? AND location_name = ? AND status = 'in_progress'
|
||||
''', [session_id, location_name], one=True)
|
||||
|
||||
if existing_bin:
|
||||
flash(f'Resuming bin: {location_name}', 'info')
|
||||
return redirect(url_for('counting.count_location',
|
||||
session_id=session_id,
|
||||
location_count_id=existing_bin['location_count_id']))
|
||||
# --- END NEW LOGIC ---
|
||||
|
||||
# Count expected lots from MASTER baseline for this location
|
||||
expected_lots = query_db('''
|
||||
SELECT COUNT(DISTINCT lot_number) as count
|
||||
@@ -168,7 +195,7 @@ def start_bin_count(session_id):
|
||||
|
||||
expected_count = expected_lots['count'] if expected_lots else 0
|
||||
|
||||
# Create new location count
|
||||
# Create new location count if none existed
|
||||
conn = get_db()
|
||||
cursor = conn.cursor()
|
||||
|
||||
@@ -184,7 +211,6 @@ def start_bin_count(session_id):
|
||||
flash(f'Started counting bin: {location_name}', 'success')
|
||||
return redirect(url_for('counting.count_location', session_id=session_id, location_count_id=location_count_id))
|
||||
|
||||
|
||||
@counting_bp.route('/location/<int:location_count_id>/complete', methods=['POST'])
|
||||
@login_required
|
||||
def complete_location(location_count_id):
|
||||
@@ -512,7 +538,7 @@ def scan_lot(session_id, location_count_id):
|
||||
def delete_scan(entry_id):
|
||||
"""Soft delete a scan and recalculate duplicate statuses"""
|
||||
# Get the scan being deleted
|
||||
scan = query_db('SELECT * FROM ScanEntries WHERE entry_id = ?', [entry_id], one=True)
|
||||
scan = query_db('SELECT * FROM ScanEntries WHERE entry_id = ? AND is_deleted = 0', [entry_id], one=True)
|
||||
|
||||
if not scan:
|
||||
return jsonify({'success': False, 'message': 'Scan not found'})
|
||||
@@ -572,7 +598,7 @@ def update_scan(entry_id):
|
||||
comment = data.get('comment', '')
|
||||
|
||||
# Get the scan
|
||||
scan = query_db('SELECT * FROM ScanEntries WHERE entry_id = ?', [entry_id], one=True)
|
||||
scan = query_db('SELECT * FROM ScanEntries WHERE entry_id = ? AND is_deleted = 0', [entry_id], one=True)
|
||||
|
||||
if not scan:
|
||||
return jsonify({'success': False, 'message': 'Scan not found'})
|
||||
@@ -593,7 +619,7 @@ def update_scan(entry_id):
|
||||
actual_weight = ?,
|
||||
comment = ?,
|
||||
modified_timestamp = CURRENT_TIMESTAMP
|
||||
WHERE entry_id = ?
|
||||
WHERE entry_id = ? and is_deleted = 0
|
||||
''', [item, weight, comment, entry_id])
|
||||
|
||||
return jsonify({'success': True, 'message': 'Scan updated'})
|
||||
@@ -625,7 +651,7 @@ def recalculate_duplicate_status(session_id, lot_number, current_location):
|
||||
duplicate_info = NULL,
|
||||
comment = NULL,
|
||||
modified_timestamp = CURRENT_TIMESTAMP
|
||||
WHERE entry_id = ?
|
||||
WHERE entry_id = ? and is_deleted = 0
|
||||
''', [scan['entry_id']])
|
||||
updated_entries.append({
|
||||
'entry_id': scan['entry_id'],
|
||||
@@ -670,7 +696,7 @@ def recalculate_duplicate_status(session_id, lot_number, current_location):
|
||||
duplicate_info = ?,
|
||||
comment = ?,
|
||||
modified_timestamp = CURRENT_TIMESTAMP
|
||||
WHERE entry_id = ?
|
||||
WHERE entry_id = ? and is_deleted = 0
|
||||
''', [duplicate_status, duplicate_info, duplicate_info, scan['entry_id']])
|
||||
|
||||
# Update our tracking list
|
||||
@@ -689,7 +715,7 @@ def recalculate_duplicate_status(session_id, lot_number, current_location):
|
||||
duplicate_info = ?,
|
||||
comment = ?,
|
||||
modified_timestamp = CURRENT_TIMESTAMP
|
||||
WHERE entry_id = ?
|
||||
WHERE entry_id = ? and is_deleted = 0
|
||||
''', [duplicate_status, duplicate_info, duplicate_info, prev_scan['entry_id']])
|
||||
|
||||
# Update tracking for previous scans
|
||||
@@ -754,4 +780,57 @@ def finish_location(session_id, location_count_id):
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'redirect': url_for('counting.count_session', session_id=session_id)
|
||||
})
|
||||
})
|
||||
|
||||
@counting_bp.route('/session/<int:session_id>/finalize-all', methods=['POST'])
|
||||
@login_required
|
||||
def finalize_all_locations(session_id):
|
||||
"""Finalize all 'in_progress' locations in a session"""
|
||||
if session.get('role') not in ['owner', 'admin']:
|
||||
return jsonify({'success': False, 'message': 'Permission denied'}), 403
|
||||
|
||||
# 1. Get all in_progress locations for this session
|
||||
locations = query_db('''
|
||||
SELECT location_count_id, location_name
|
||||
FROM LocationCounts
|
||||
WHERE session_id = ?
|
||||
AND status = 'in_progress'
|
||||
AND is_deleted = 0
|
||||
''', [session_id])
|
||||
|
||||
if not locations:
|
||||
return jsonify({'success': True, 'message': 'No open bins to finalize.'})
|
||||
|
||||
# 2. Loop through and run the finalize logic for each
|
||||
for loc in locations:
|
||||
# We reuse the logic from your existing finish_location route
|
||||
execute_db('''
|
||||
UPDATE LocationCounts
|
||||
SET status = 'completed', end_timestamp = CURRENT_TIMESTAMP
|
||||
WHERE location_count_id = ?
|
||||
''', [loc['location_count_id']])
|
||||
|
||||
# Identify missing lots from MASTER baseline
|
||||
expected_lots = query_db('''
|
||||
SELECT lot_number, item, description, system_quantity
|
||||
FROM BaselineInventory_Master
|
||||
WHERE session_id = ? AND system_bin = ?
|
||||
''', [session_id, loc['location_name']])
|
||||
|
||||
scanned_lots = query_db('''
|
||||
SELECT DISTINCT lot_number
|
||||
FROM ScanEntries
|
||||
WHERE location_count_id = ? AND is_deleted = 0
|
||||
''', [loc['location_count_id']])
|
||||
|
||||
scanned_lot_numbers = {s['lot_number'] for s in scanned_lots}
|
||||
|
||||
for expected in expected_lots:
|
||||
if expected['lot_number'] not in scanned_lot_numbers:
|
||||
execute_db('''
|
||||
INSERT INTO MissingLots (session_id, lot_number, master_expected_location, item, master_expected_quantity, marked_by)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
''', [session_id, expected['lot_number'], loc['location_name'],
|
||||
expected['item'], expected['system_quantity'], session['user_id']])
|
||||
|
||||
return jsonify({'success': True, 'message': f'Successfully finalized {len(locations)} bins.'})
|
||||
Reference in New Issue
Block a user