Bug: Fixed Imports of Consumption Sheets Module
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
"version": "1.0.0",
|
||||
"author": "STUFF",
|
||||
"description": "Production lot tracking and consumption reporting with Excel export",
|
||||
"icon": "fa-clipboard-list",
|
||||
"requires_roles": ["owner", "admin", "staff"],
|
||||
"routes_prefix": "/conssheets",
|
||||
"has_migrations": true,
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"""
|
||||
Consumption Sheets Module - Routes
|
||||
Converted from cons_sheets.py
|
||||
Converted from conssheets.py
|
||||
"""
|
||||
from flask import render_template, request, redirect, url_for, flash, jsonify, session, send_file
|
||||
from db import query_db, execute_db
|
||||
from utils import login_required, role_required
|
||||
from datetime import datetime
|
||||
import sqlite3
|
||||
import io
|
||||
import os
|
||||
|
||||
|
||||
def register_routes(bp):
|
||||
@@ -16,7 +18,7 @@ def register_routes(bp):
|
||||
# CONSUMPTION SHEETS ROUTES
|
||||
# =========================================================================
|
||||
|
||||
@bp.route('/admin/consumption-sheets')
|
||||
@bp.route('/admin')
|
||||
@role_required('owner', 'admin')
|
||||
def admin_processes():
|
||||
"""List all consumption sheet process types (Active or Archived)"""
|
||||
@@ -33,7 +35,7 @@ def register_routes(bp):
|
||||
ORDER BY cp.process_name ASC
|
||||
''', [is_active_val])
|
||||
|
||||
return render_template('cons_sheets/admin_processes.html',
|
||||
return render_template('conssheets/admin_processes.html',
|
||||
processes=processes,
|
||||
showing_archived=show_archived)
|
||||
|
||||
@@ -47,7 +49,7 @@ def register_routes(bp):
|
||||
|
||||
if not process_name:
|
||||
flash('Process name is required', 'danger')
|
||||
return redirect(url_for('cons_sheets.create_process'))
|
||||
return redirect(url_for('conssheets.create_process'))
|
||||
|
||||
# Generate process_key from name (lowercase, underscores)
|
||||
process_key = process_name.lower().replace(' ', '_').replace('-', '_')
|
||||
@@ -58,7 +60,7 @@ def register_routes(bp):
|
||||
existing = query_db('SELECT id FROM cons_processes WHERE process_key = ?', [process_key], one=True)
|
||||
if existing:
|
||||
flash(f'A process with key "{process_key}" already exists', 'danger')
|
||||
return redirect(url_for('cons_sheets.create_process'))
|
||||
return redirect(url_for('conssheets.create_process'))
|
||||
|
||||
process_id = execute_db('''
|
||||
INSERT INTO cons_processes (process_key, process_name, created_by)
|
||||
@@ -69,15 +71,15 @@ def register_routes(bp):
|
||||
create_process_detail_table(process_key)
|
||||
|
||||
flash(f'Process "{process_name}" created successfully!', 'success')
|
||||
return redirect(url_for('cons_sheets.process_detail', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_detail', process_id=process_id))
|
||||
|
||||
return render_template('cons_sheets/create_process.html')
|
||||
return render_template('conssheets/create_process.html')
|
||||
|
||||
|
||||
|
||||
def get_db_path():
|
||||
"""Get the database path"""
|
||||
db_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'database', 'scanlook.db')
|
||||
db_path = 'database/scanlook.db'
|
||||
print(f"DEBUG: Database path is: {db_path}")
|
||||
print(f"DEBUG: Path exists: {os.path.exists(db_path)}")
|
||||
return db_path
|
||||
@@ -167,7 +169,7 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
# Soft delete: Set is_active = 0
|
||||
# The existing admin_processes route already filters for is_active=1,
|
||||
@@ -175,7 +177,7 @@ def register_routes(bp):
|
||||
execute_db('UPDATE cons_processes SET is_active = 0 WHERE id = ?', [process_id])
|
||||
|
||||
flash(f'Process "{process["process_name"]}" has been deleted.', 'success')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
|
||||
@bp.route('/admin/consumption-sheets/<int:process_id>/restore', methods=['POST'])
|
||||
@@ -184,7 +186,7 @@ def register_routes(bp):
|
||||
"""Restore a soft-deleted process type"""
|
||||
execute_db('UPDATE cons_processes SET is_active = 1 WHERE id = ?', [process_id])
|
||||
flash('Process has been restored.', 'success')
|
||||
return redirect(url_for('cons_sheets.admin_processes', archived=1))
|
||||
return redirect(url_for('conssheets.admin_processes', archived=1))
|
||||
|
||||
|
||||
|
||||
@@ -196,7 +198,7 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
# Get header fields
|
||||
header_fields = query_db('''
|
||||
@@ -212,7 +214,7 @@ def register_routes(bp):
|
||||
ORDER BY sort_order, id
|
||||
''', [process_id])
|
||||
|
||||
return render_template('cons_sheets/process_detail.html',
|
||||
return render_template('conssheets/process_detail.html',
|
||||
process=process,
|
||||
header_fields=header_fields,
|
||||
detail_fields=detail_fields)
|
||||
@@ -226,7 +228,7 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
# Get header fields
|
||||
header_fields = query_db('''
|
||||
@@ -242,7 +244,7 @@ def register_routes(bp):
|
||||
ORDER BY sort_order, id
|
||||
''', [process_id])
|
||||
|
||||
return render_template('cons_sheets/process_fields.html',
|
||||
return render_template('conssheets/process_fields.html',
|
||||
process=process,
|
||||
header_fields=header_fields,
|
||||
detail_fields=detail_fields)
|
||||
@@ -256,7 +258,7 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
# Get all active fields for mapping display
|
||||
header_fields = query_db('''
|
||||
@@ -271,7 +273,7 @@ def register_routes(bp):
|
||||
ORDER BY sort_order, id
|
||||
''', [process_id])
|
||||
|
||||
return render_template('cons_sheets/process_template.html',
|
||||
return render_template('conssheets/process_template.html',
|
||||
process=process,
|
||||
header_fields=header_fields,
|
||||
detail_fields=detail_fields)
|
||||
@@ -285,21 +287,21 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
if 'template_file' not in request.files:
|
||||
flash('No file selected', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
file = request.files['template_file']
|
||||
|
||||
if file.filename == '':
|
||||
flash('No file selected', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
if not file.filename.endswith('.xlsx'):
|
||||
flash('Only .xlsx files are allowed', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
# Read file as binary
|
||||
template_data = file.read()
|
||||
@@ -313,7 +315,7 @@ def register_routes(bp):
|
||||
''', [template_data, filename, process_id])
|
||||
|
||||
flash(f'Template "{filename}" uploaded successfully!', 'success')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
|
||||
@bp.route('/admin/consumption-sheets/<int:process_id>/template/settings', methods=['POST'])
|
||||
@@ -324,7 +326,7 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
rows_per_page = request.form.get('rows_per_page', 30)
|
||||
detail_start_row = request.form.get('detail_start_row', 10)
|
||||
@@ -340,11 +342,11 @@ def register_routes(bp):
|
||||
|
||||
if not page_height:
|
||||
flash('Page Height is required for the new strategy', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
except ValueError:
|
||||
flash('Invalid number values', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
# Update query - We ignore detail_end_row (leave it as is or null)
|
||||
execute_db('''
|
||||
@@ -355,7 +357,7 @@ def register_routes(bp):
|
||||
''', [rows_per_page, detail_start_row, page_height, print_start_col, print_end_col, process_id])
|
||||
|
||||
flash('Settings updated successfully!', 'success')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
@bp.route('/admin/consumption-sheets/<int:process_id>/template/download')
|
||||
@role_required('owner', 'admin')
|
||||
@@ -367,7 +369,7 @@ def register_routes(bp):
|
||||
|
||||
if not process or not process['template_file']:
|
||||
flash('No template found', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_template', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_template', process_id=process_id))
|
||||
|
||||
return Response(
|
||||
process['template_file'],
|
||||
@@ -382,13 +384,13 @@ def register_routes(bp):
|
||||
"""Add a new field to a process"""
|
||||
if table_type not in ['header', 'detail']:
|
||||
flash('Invalid table type', 'danger')
|
||||
return redirect(url_for('cons_sheets.process_fields', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_fields', process_id=process_id))
|
||||
|
||||
process = query_db('SELECT * FROM cons_processes WHERE id = ?', [process_id], one=True)
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
if request.method == 'POST':
|
||||
field_label = request.form.get('field_label', '').strip()
|
||||
@@ -399,7 +401,7 @@ def register_routes(bp):
|
||||
|
||||
if not field_label:
|
||||
flash('Field label is required', 'danger')
|
||||
return redirect(url_for('cons_sheets.add_field', process_id=process_id, table_type=table_type))
|
||||
return redirect(url_for('conssheets.add_field', process_id=process_id, table_type=table_type))
|
||||
|
||||
# Generate field_name from label (lowercase, underscores)
|
||||
field_name = field_label.lower().replace(' ', '_').replace('-', '_')
|
||||
@@ -413,7 +415,7 @@ def register_routes(bp):
|
||||
|
||||
if existing:
|
||||
flash(f'A field with name "{field_name}" already exists', 'danger')
|
||||
return redirect(url_for('cons_sheets.add_field', process_id=process_id, table_type=table_type))
|
||||
return redirect(url_for('conssheets.add_field', process_id=process_id, table_type=table_type))
|
||||
|
||||
# Get next sort_order
|
||||
max_sort = query_db('''
|
||||
@@ -438,9 +440,9 @@ def register_routes(bp):
|
||||
add_column_to_detail_table(process['process_key'], field_name, field_type)
|
||||
|
||||
flash(f'Field "{field_label}" added successfully!', 'success')
|
||||
return redirect(url_for('cons_sheets.process_fields', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_fields', process_id=process_id))
|
||||
|
||||
return render_template('cons_sheets/add_field.html',
|
||||
return render_template('conssheets/add_field.html',
|
||||
process=process,
|
||||
table_type=table_type)
|
||||
|
||||
@@ -454,7 +456,7 @@ def register_routes(bp):
|
||||
|
||||
if not process or not field:
|
||||
flash('Process or field not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.admin_processes'))
|
||||
return redirect(url_for('conssheets.admin_processes'))
|
||||
|
||||
if request.method == 'POST':
|
||||
field_label = request.form.get('field_label', '').strip()
|
||||
@@ -466,7 +468,7 @@ def register_routes(bp):
|
||||
|
||||
if not field_label:
|
||||
flash('Field label is required', 'danger')
|
||||
return redirect(url_for('cons_sheets.edit_field', process_id=process_id, field_id=field_id))
|
||||
return redirect(url_for('conssheets.edit_field', process_id=process_id, field_id=field_id))
|
||||
|
||||
execute_db('''
|
||||
UPDATE cons_process_fields
|
||||
@@ -475,9 +477,9 @@ def register_routes(bp):
|
||||
''', [field_label, field_type, int(max_length) if max_length else None, is_required, is_duplicate_key, excel_cell or None, field_id])
|
||||
|
||||
flash(f'Field "{field_label}" updated successfully!', 'success')
|
||||
return redirect(url_for('cons_sheets.process_fields', process_id=process_id))
|
||||
return redirect(url_for('conssheets.process_fields', process_id=process_id))
|
||||
|
||||
return render_template('cons_sheets/edit_field.html',
|
||||
return render_template('conssheets/edit_field.html',
|
||||
process=process,
|
||||
field=field)
|
||||
|
||||
@@ -520,7 +522,7 @@ def register_routes(bp):
|
||||
''', [process_id], one=True)
|
||||
|
||||
|
||||
@bp.route('/cons-sheets')
|
||||
@bp.route('/')
|
||||
@login_required
|
||||
def index():
|
||||
"""Consumption Sheets module landing - show user's sessions"""
|
||||
@@ -530,7 +532,7 @@ def register_routes(bp):
|
||||
has_access = query_db('''
|
||||
SELECT 1 FROM UserModules um
|
||||
JOIN Modules m ON um.module_id = m.module_id
|
||||
WHERE um.user_id = ? AND m.module_key = 'cons_sheets' AND m.is_active = 1
|
||||
WHERE um.user_id = ? AND m.module_key = 'conssheets' AND m.is_active = 1
|
||||
''', [user_id], one=True)
|
||||
|
||||
if not has_access:
|
||||
@@ -567,12 +569,12 @@ def register_routes(bp):
|
||||
SELECT * FROM cons_processes WHERE is_active = 1 ORDER BY process_name
|
||||
''')
|
||||
|
||||
return render_template('cons_sheets/staff_index.html',
|
||||
return render_template('conssheets/staff_index.html',
|
||||
sessions=sessions_with_counts,
|
||||
processes=processes)
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/new/<int:process_id>', methods=['GET', 'POST'])
|
||||
@bp.route('/new/<int:process_id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def new_session(process_id):
|
||||
"""Create a new scanning session - enter header info"""
|
||||
@@ -580,7 +582,7 @@ def register_routes(bp):
|
||||
|
||||
if not process:
|
||||
flash('Process not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.index'))
|
||||
return redirect(url_for('conssheets.index'))
|
||||
|
||||
# Get header fields for this process
|
||||
header_fields = query_db('''
|
||||
@@ -600,7 +602,7 @@ def register_routes(bp):
|
||||
|
||||
if missing_required:
|
||||
flash(f'Required fields missing: {", ".join(missing_required)}', 'danger')
|
||||
return render_template('cons_sheets/new_session.html',
|
||||
return render_template('conssheets/new_session.html',
|
||||
process=process,
|
||||
header_fields=header_fields,
|
||||
form_data=request.form)
|
||||
@@ -621,15 +623,15 @@ def register_routes(bp):
|
||||
''', [session_id, field['id'], value])
|
||||
|
||||
flash('Session created! Start scanning lots.', 'success')
|
||||
return redirect(url_for('cons_sheets.scan_session', session_id=session_id))
|
||||
return redirect(url_for('conssheets.scan_session', session_id=session_id))
|
||||
|
||||
return render_template('cons_sheets/new_session.html',
|
||||
return render_template('conssheets/new_session.html',
|
||||
process=process,
|
||||
header_fields=header_fields,
|
||||
form_data={})
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>')
|
||||
@bp.route('/session/<int:session_id>')
|
||||
@login_required
|
||||
def scan_session(session_id):
|
||||
"""Main scanning interface for a session"""
|
||||
@@ -643,11 +645,11 @@ def register_routes(bp):
|
||||
|
||||
if not sess:
|
||||
flash('Session not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.index'))
|
||||
return redirect(url_for('conssheets.index'))
|
||||
|
||||
if sess['status'] == 'archived':
|
||||
flash('This session has been archived', 'warning')
|
||||
return redirect(url_for('cons_sheets.index'))
|
||||
return redirect(url_for('conssheets.index'))
|
||||
|
||||
# Get header values for display
|
||||
header_values = query_db('''
|
||||
@@ -680,7 +682,7 @@ def register_routes(bp):
|
||||
dup_key_field_row = get_duplicate_key_field(sess['process_id'])
|
||||
dup_key_field = dict(dup_key_field_row) if dup_key_field_row else None
|
||||
|
||||
return render_template('cons_sheets/scan_session.html',
|
||||
return render_template('conssheets/scan_session.html',
|
||||
session=sess,
|
||||
header_values=header_values,
|
||||
scans=scans,
|
||||
@@ -688,7 +690,7 @@ def register_routes(bp):
|
||||
dup_key_field=dup_key_field)
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/scan', methods=['POST'])
|
||||
@bp.route('/session/<int:session_id>/scan', methods=['POST'])
|
||||
@login_required
|
||||
def scan_lot(session_id):
|
||||
"""Process a scan with duplicate detection using dynamic tables"""
|
||||
@@ -823,7 +825,7 @@ def register_routes(bp):
|
||||
})
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/detail/<int:detail_id>')
|
||||
@bp.route('/session/<int:session_id>/detail/<int:detail_id>')
|
||||
@login_required
|
||||
def get_detail(session_id, detail_id):
|
||||
"""Get detail info for editing"""
|
||||
@@ -852,7 +854,7 @@ def register_routes(bp):
|
||||
return jsonify({'success': True, 'detail': dict(detail)})
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/detail/<int:detail_id>/update', methods=['POST'])
|
||||
@bp.route('/session/<int:session_id>/detail/<int:detail_id>/update', methods=['POST'])
|
||||
@login_required
|
||||
def update_detail(session_id, detail_id):
|
||||
"""Update a scanned detail"""
|
||||
@@ -909,7 +911,7 @@ def register_routes(bp):
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/detail/<int:detail_id>/delete', methods=['POST'])
|
||||
@bp.route('/session/<int:session_id>/detail/<int:detail_id>/delete', methods=['POST'])
|
||||
@login_required
|
||||
def delete_detail(session_id, detail_id):
|
||||
"""Soft-delete a scanned detail"""
|
||||
@@ -939,7 +941,7 @@ def register_routes(bp):
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/archive', methods=['POST'])
|
||||
@bp.route('/session/<int:session_id>/archive', methods=['POST'])
|
||||
@login_required
|
||||
def archive_session(session_id):
|
||||
"""Archive (soft-delete) a session"""
|
||||
@@ -957,7 +959,7 @@ def register_routes(bp):
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/template')
|
||||
@bp.route('/session/<int:session_id>/template')
|
||||
@login_required
|
||||
def download_import_template(session_id):
|
||||
"""Generate a blank Excel template for bulk import"""
|
||||
@@ -967,7 +969,7 @@ def register_routes(bp):
|
||||
|
||||
# Get Process ID
|
||||
sess = query_db('SELECT process_id FROM cons_sessions WHERE id = ?', [session_id], one=True)
|
||||
if not sess: return redirect(url_for('cons_sheets.index'))
|
||||
if not sess: return redirect(url_for('conssheets.index'))
|
||||
|
||||
# Get Detail Fields
|
||||
fields = query_db('''
|
||||
@@ -996,7 +998,7 @@ def register_routes(bp):
|
||||
headers={'Content-Disposition': 'attachment; filename=import_template.xlsx'}
|
||||
)
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/import', methods=['POST'])
|
||||
@bp.route('/session/<int:session_id>/import', methods=['POST'])
|
||||
@login_required
|
||||
def import_session_data(session_id):
|
||||
"""Bulk import detail rows from Excel"""
|
||||
@@ -1015,17 +1017,17 @@ def register_routes(bp):
|
||||
|
||||
if not sess:
|
||||
flash('Session not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.index'))
|
||||
return redirect(url_for('conssheets.index'))
|
||||
|
||||
# 2. Check File
|
||||
if 'file' not in request.files:
|
||||
flash('No file uploaded', 'danger')
|
||||
return redirect(url_for('cons_sheets.scan_session', session_id=session_id))
|
||||
return redirect(url_for('conssheets.scan_session', session_id=session_id))
|
||||
|
||||
file = request.files['file']
|
||||
if file.filename == '':
|
||||
flash('No file selected', 'danger')
|
||||
return redirect(url_for('cons_sheets.scan_session', session_id=session_id))
|
||||
return redirect(url_for('conssheets.scan_session', session_id=session_id))
|
||||
|
||||
try:
|
||||
# 3. Read Excel
|
||||
@@ -1051,7 +1053,7 @@ def register_routes(bp):
|
||||
|
||||
if not col_mapping:
|
||||
flash('Error: No matching columns found in Excel. Please use the template.', 'danger')
|
||||
return redirect(url_for('cons_sheets.scan_session', session_id=session_id))
|
||||
return redirect(url_for('conssheets.scan_session', session_id=session_id))
|
||||
|
||||
# 4. Process Rows
|
||||
table_name = f"cons_proc_{sess['process_key']}_details"
|
||||
@@ -1095,9 +1097,9 @@ def register_routes(bp):
|
||||
flash(f'Import Error: {str(e)}', 'danger')
|
||||
print(f"DEBUG IMPORT ERROR: {str(e)}") # Print to console for good measure
|
||||
|
||||
return redirect(url_for('cons_sheets.scan_session', session_id=session_id))
|
||||
return redirect(url_for('conssheets.scan_session', session_id=session_id))
|
||||
|
||||
@bp.route('/cons-sheets/session/<int:session_id>/export')
|
||||
@bp.route('/session/<int:session_id>/export')
|
||||
@login_required
|
||||
def export_session(session_id):
|
||||
"""Export session: Hide Rows Strategy + Manual Column Widths"""
|
||||
@@ -1123,7 +1125,7 @@ def register_routes(bp):
|
||||
|
||||
if not sess or not sess['template_file']:
|
||||
flash('Session or Template not found', 'danger')
|
||||
return redirect(url_for('cons_sheets.index'))
|
||||
return redirect(url_for('conssheets.index'))
|
||||
|
||||
# Validation
|
||||
page_height = sess['page_height']
|
||||
@@ -1132,7 +1134,7 @@ def register_routes(bp):
|
||||
|
||||
if not page_height:
|
||||
flash('Configuration Error: Page Height is not set.', 'danger')
|
||||
return redirect(url_for('cons_sheets.scan_session', session_id=session_id))
|
||||
return redirect(url_for('conssheets.scan_session', session_id=session_id))
|
||||
|
||||
# Get Data
|
||||
header_fields = query_db('''
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Fields
|
||||
</a>
|
||||
</div>
|
||||
@@ -72,7 +72,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary">Cancel</a>
|
||||
<a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Add Field</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
<p class="page-subtitle" style="margin-bottom: var(--space-xs);">Manage process types and templates</p>
|
||||
|
||||
{% if showing_archived %}
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" style="font-size: 0.85rem; color: var(--color-primary); display: inline-flex; align-items: center; gap: 6px;">
|
||||
<a href="{{ url_for('conssheets.admin_processes') }}" style="font-size: 0.85rem; color: var(--color-primary); display: inline-flex; align-items: center; gap: 6px;">
|
||||
<i class="fa-solid fa-eye"></i> Return to Active List
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('cons_sheets.admin_processes', archived=1) }}" style="font-size: 0.85rem; color: var(--color-text-muted); display: inline-flex; align-items: center; gap: 6px;">
|
||||
<a href="{{ url_for('conssheets.admin_processes', archived=1) }}" style="font-size: 0.85rem; color: var(--color-text-muted); display: inline-flex; align-items: center; gap: 6px;">
|
||||
<i class="fa-solid fa-box-archive"></i> View Archived Processes
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.create_process') }}" class="btn btn-primary">
|
||||
<a href="{{ url_for('conssheets.create_process') }}" class="btn btn-primary">
|
||||
<span class="btn-icon">+</span> New Process
|
||||
</a>
|
||||
</div>
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
{% if showing_archived %}
|
||||
<form method="POST"
|
||||
action="{{ url_for('cons_sheets.restore_process', process_id=process.id) }}"
|
||||
action="{{ url_for('conssheets.restore_process', process_id=process.id) }}"
|
||||
style="margin: 0;">
|
||||
<button type="submit" class="btn-icon-only" title="Restore Process" style="color: var(--color-success);">
|
||||
<i class="fa-solid fa-trash-arrow-up"></i>
|
||||
@@ -56,7 +56,7 @@
|
||||
</form>
|
||||
{% else %}
|
||||
<form method="POST"
|
||||
action="{{ url_for('cons_sheets.delete_process', process_id=process.id) }}"
|
||||
action="{{ url_for('conssheets.delete_process', process_id=process.id) }}"
|
||||
onsubmit="return confirm('Are you sure you want to delete {{ process.process_name }}?');"
|
||||
style="margin: 0;">
|
||||
<button type="submit" class="btn-icon-only" title="Delete Process">
|
||||
@@ -86,7 +86,7 @@
|
||||
</div>
|
||||
|
||||
<div class="session-actions">
|
||||
<a href="{{ url_for('cons_sheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-block">
|
||||
<a href="{{ url_for('conssheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-block">
|
||||
Configure
|
||||
</a>
|
||||
</div>
|
||||
@@ -100,7 +100,7 @@
|
||||
<div class="empty-icon">📝</div>
|
||||
<h2 class="empty-title">No Processes Defined</h2>
|
||||
<p class="empty-text">Create a process type to get started (e.g., "AD WIP")</p>
|
||||
<a href="{{ url_for('cons_sheets.create_process') }}" class="btn btn-primary">
|
||||
<a href="{{ url_for('conssheets.create_process') }}" class="btn btn-primary">
|
||||
Create First Process
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.admin_processes') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Processes
|
||||
</a>
|
||||
</div>
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="btn btn-secondary">Cancel</a>
|
||||
<a href="{{ url_for('conssheets.admin_processes') }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Create Process</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Fields
|
||||
</a>
|
||||
</div>
|
||||
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary">Cancel</a>
|
||||
<a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary">Save Changes</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.index') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back
|
||||
</a>
|
||||
</div>
|
||||
@@ -76,7 +76,7 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="form-actions">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="btn btn-secondary">Cancel</a>
|
||||
<a href="{{ url_for('conssheets.index') }}" class="btn btn-secondary">Cancel</a>
|
||||
<button type="submit" class="btn btn-primary" {% if not header_fields %}disabled{% endif %}>
|
||||
Start Scanning
|
||||
</button>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.admin_processes') }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.admin_processes') }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to Processes
|
||||
</a>
|
||||
</div>
|
||||
@@ -38,7 +38,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-primary btn-block">
|
||||
<a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}" class="btn btn-primary btn-block">
|
||||
Configure Fields
|
||||
</a>
|
||||
</div>
|
||||
@@ -67,7 +67,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.process_template', process_id=process.id) }}" class="btn btn-primary btn-block">
|
||||
<a href="{{ url_for('conssheets.process_template', process_id=process.id) }}" class="btn btn-primary btn-block">
|
||||
Configure Template
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to {{ process.process_name }}
|
||||
</a>
|
||||
</div>
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="fields-section">
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">Header Fields</h2>
|
||||
<a href="{{ url_for('cons_sheets.add_field', process_id=process.id, table_type='header') }}" class="btn btn-primary btn-sm">
|
||||
<a href="{{ url_for('conssheets.add_field', process_id=process.id, table_type='header') }}" class="btn btn-primary btn-sm">
|
||||
<span class="btn-icon">+</span> Add Field
|
||||
</a>
|
||||
</div>
|
||||
@@ -48,7 +48,7 @@
|
||||
<td>{{ '✓' if field.is_required else '—' }}</td>
|
||||
<td>{{ field.excel_cell or '—' }}</td>
|
||||
<td>
|
||||
<a href="{{ url_for('cons_sheets.edit_field', process_id=process.id, field_id=field.id) }}" class="btn btn-secondary btn-sm">Edit</a>
|
||||
<a href="{{ url_for('conssheets.edit_field', process_id=process.id, field_id=field.id) }}" class="btn btn-secondary btn-sm">Edit</a>
|
||||
<button onclick="confirmDelete(this)"
|
||||
data-id="{{ field.id }}"
|
||||
data-label="{{ field.field_label }}"
|
||||
@@ -73,7 +73,7 @@
|
||||
<div class="fields-section">
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">Detail Fields</h2>
|
||||
<a href="{{ url_for('cons_sheets.add_field', process_id=process.id, table_type='detail') }}" class="btn btn-primary btn-sm">
|
||||
<a href="{{ url_for('conssheets.add_field', process_id=process.id, table_type='detail') }}" class="btn btn-primary btn-sm">
|
||||
<span class="btn-icon">+</span> Add Field
|
||||
</a>
|
||||
</div>
|
||||
@@ -100,7 +100,7 @@
|
||||
<td>{{ '✓' if field.is_required else '—' }}</td>
|
||||
<td>{{ field.excel_cell or '—' }}</td>
|
||||
<td>
|
||||
<a href="{{ url_for('cons_sheets.edit_field', process_id=process.id, field_id=field.id) }}" class="btn btn-secondary btn-sm">Edit</a>
|
||||
<a href="{{ url_for('conssheets.edit_field', process_id=process.id, field_id=field.id) }}" class="btn btn-secondary btn-sm">Edit</a>
|
||||
<button onclick="confirmDelete(this)"
|
||||
data-id="{{ field.id }}"
|
||||
data-label="{{ field.field_label }}"
|
||||
@@ -156,7 +156,7 @@ function confirmDelete(btn) {
|
||||
const fieldLabel = btn.dataset.label;
|
||||
|
||||
if (confirm('Delete field "' + fieldLabel + '"?\n\nThis will soft-delete the field (data preserved but hidden).')) {
|
||||
fetch('{{ url_for("cons_sheets.delete_field", process_id=process.id, field_id=0) }}'.replace('0', fieldId), {
|
||||
fetch('{{ url_for("conssheets.delete_field", process_id=process.id, field_id=0) }}'.replace('0', fieldId), {
|
||||
method: 'POST'
|
||||
})
|
||||
.then(response => response.json())
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
{% block content %}
|
||||
<div class="dashboard-container">
|
||||
<div class="mode-selector">
|
||||
<a href="{{ url_for('cons_sheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.process_detail', process_id=process.id) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-arrow-left"></i> Back to {{ process.process_name }}
|
||||
</a>
|
||||
</div>
|
||||
@@ -27,14 +27,14 @@
|
||||
<div class="template-info">
|
||||
<span class="template-icon">📄</span>
|
||||
<span class="template-name">{{ process.template_filename }}</span>
|
||||
<a href="{{ url_for('cons_sheets.download_template', process_id=process.id) }}" class="btn btn-secondary btn-sm">Download</a>
|
||||
<a href="{{ url_for('conssheets.download_template', process_id=process.id) }}" class="btn btn-secondary btn-sm">Download</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="no-template">No template uploaded yet</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<form method="POST" action="{{ url_for('cons_sheets.upload_template', process_id=process.id) }}" enctype="multipart/form-data" class="upload-form">
|
||||
<form method="POST" action="{{ url_for('conssheets.upload_template', process_id=process.id) }}" enctype="multipart/form-data" class="upload-form">
|
||||
<div class="form-group">
|
||||
<label for="template_file" class="form-label">Upload New Template</label>
|
||||
<input type="file" id="template_file" name="template_file" accept=".xlsx" class="form-input" required>
|
||||
@@ -48,7 +48,7 @@
|
||||
<div class="config-section">
|
||||
<h2 class="section-title">Page Settings</h2>
|
||||
|
||||
<form method="POST" action="{{ url_for('cons_sheets.update_template_settings', process_id=process.id) }}">
|
||||
<form method="POST" action="{{ url_for('conssheets.update_template_settings', process_id=process.id) }}">
|
||||
<div class="form-group">
|
||||
<label for="rows_per_page" class="form-label">Rows Per Page (Capacity)</label>
|
||||
<input type="number" id="rows_per_page" name="rows_per_page"
|
||||
@@ -157,12 +157,12 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}" class="btn btn-secondary" style="margin-top: var(--space-lg);">
|
||||
<a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}" class="btn btn-secondary" style="margin-top: var(--space-lg);">
|
||||
Edit Field Mappings
|
||||
</a>
|
||||
{% else %}
|
||||
<div class="empty-state-small">
|
||||
<p>No fields defined yet. <a href="{{ url_for('cons_sheets.process_fields', process_id=process.id) }}">Add fields first</a>.</p>
|
||||
<p>No fields defined yet. <a href="{{ url_for('conssheets.process_fields', process_id=process.id) }}">Add fields first</a>.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="count-location-container">
|
||||
<div class="location-header">
|
||||
<div class="location-info">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="breadcrumb">← Back to Sessions</a>
|
||||
<a href="{{ url_for('conssheets.index') }}" class="breadcrumb">← Back to Sessions</a>
|
||||
<div class="location-label">{{ session.process_name }}</div>
|
||||
<div class="header-values">
|
||||
{% for hv in header_values %}
|
||||
@@ -136,7 +136,7 @@
|
||||
|
||||
<div class="finish-section">
|
||||
<div class="action-buttons-row">
|
||||
<a href="{{ url_for('cons_sheets.index') }}" class="btn btn-secondary btn-block btn-lg">← Back to Sessions</a>
|
||||
<a href="{{ url_for('conssheets.index') }}" class="btn btn-secondary btn-block btn-lg">← Back to Sessions</a>
|
||||
<button class="btn btn-success btn-block btn-lg" onclick="exportToExcel()">📊 Export to Excel</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -157,12 +157,12 @@
|
||||
|
||||
<div style="margin-bottom: 30px; padding: 15px; background: var(--color-bg); border-radius: 8px;">
|
||||
<p style="font-size: 0.9rem; margin-bottom: 10px;">Step 1: Get the correct format</p>
|
||||
<a href="{{ url_for('cons_sheets.download_import_template', session_id=session['id']) }}" class="btn btn-secondary btn-sm">
|
||||
<a href="{{ url_for('conssheets.download_import_template', session_id=session['id']) }}" class="btn btn-secondary btn-sm">
|
||||
<i class="fa-solid fa-download"></i> Download Template
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form action="{{ url_for('cons_sheets.import_session_data', session_id=session['id']) }}" method="POST" enctype="multipart/form-data">
|
||||
<form action="{{ url_for('conssheets.import_session_data', session_id=session['id']) }}" method="POST" enctype="multipart/form-data">
|
||||
<div style="margin-bottom: 20px;">
|
||||
<input type="file" name="file" accept=".xlsx" class="file-input" required style="width: 100%;">
|
||||
</div>
|
||||
@@ -226,7 +226,7 @@ document.getElementById('lotScanForm').addEventListener('submit', function(e) {
|
||||
function checkDuplicate() {
|
||||
const fieldValues = {};
|
||||
fieldValues[dupKeyFieldName] = currentDupKeyValue;
|
||||
fetch(`/cons-sheets/session/${sessionId}/scan`, {
|
||||
fetch(`/conssheets/session/${sessionId}/scan`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ field_values: fieldValues, check_only: true })
|
||||
@@ -300,7 +300,7 @@ function submitScan() {
|
||||
if (input) fieldValues[field.field_name] = input.value;
|
||||
}
|
||||
});
|
||||
fetch(`/cons-sheets/session/${sessionId}/scan`, {
|
||||
fetch(`/conssheets/session/${sessionId}/scan`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ field_values: fieldValues, confirm_duplicate: isDuplicateConfirmed })
|
||||
@@ -359,7 +359,7 @@ function addScanToList(detailId, fieldValues, duplicateStatus) {
|
||||
}
|
||||
|
||||
function openScanDetail(detailId) {
|
||||
fetch(`/cons-sheets/session/${sessionId}/detail/${detailId}`)
|
||||
fetch(`/conssheets/session/${sessionId}/detail/${detailId}`)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) displayScanDetail(data.detail);
|
||||
@@ -413,7 +413,7 @@ function saveDetail(detailId) {
|
||||
if (input) fieldValues[field.field_name] = input.value;
|
||||
});
|
||||
const comment = document.getElementById('editComment').value;
|
||||
fetch(`/cons-sheets/session/${sessionId}/detail/${detailId}/update`, {
|
||||
fetch(`/conssheets/session/${sessionId}/detail/${detailId}/update`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ field_values: fieldValues, comment: comment })
|
||||
@@ -427,7 +427,7 @@ function saveDetail(detailId) {
|
||||
|
||||
function deleteDetail(detailId) {
|
||||
if (!confirm('Delete this scan?')) return;
|
||||
fetch(`/cons-sheets/session/${sessionId}/detail/${detailId}/delete`, {
|
||||
fetch(`/conssheets/session/${sessionId}/detail/${detailId}/delete`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
@@ -439,7 +439,7 @@ function deleteDetail(detailId) {
|
||||
}
|
||||
|
||||
function exportToExcel() {
|
||||
window.location.href = `/cons-sheets/session/${sessionId}/export?format=xlsx`;
|
||||
window.location.href = `/conssheets/session/${sessionId}/export?format=xlsx`;
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', function(e) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<h2 class="section-title">Start New Session</h2>
|
||||
<div class="process-buttons">
|
||||
{% for p in processes %}
|
||||
<a href="{{ url_for('cons_sheets.new_session', process_id=p.id) }}" class="btn btn-primary">
|
||||
<a href="{{ url_for('conssheets.new_session', process_id=p.id) }}" class="btn btn-primary">
|
||||
<span class="btn-icon">+</span> {{ p.process_name }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
@@ -34,7 +34,7 @@
|
||||
<div class="sessions-list">
|
||||
{% for s in sessions %}
|
||||
<div class="session-list-item-container">
|
||||
<a href="{{ url_for('cons_sheets.scan_session', session_id=s.id) }}" class="session-list-item">
|
||||
<a href="{{ url_for('conssheets.scan_session', session_id=s.id) }}" class="session-list-item">
|
||||
<div class="session-list-info">
|
||||
<h3 class="session-list-name">{{ s.process_name }}</h3>
|
||||
<div class="session-list-meta">
|
||||
|
||||
Reference in New Issue
Block a user