updated printing solutions

This commit is contained in:
2025-10-05 09:29:37 +03:00
parent f105da2012
commit 16641193de
11 changed files with 1072 additions and 22 deletions

View File

@@ -29,7 +29,13 @@ warehouse_bp = Blueprint('warehouse', __name__)
def format_cell_data(cell):
"""Helper function to format cell data, especially dates and times"""
# Import date and datetime at the top of the function
from datetime import datetime, date
if isinstance(cell, datetime):
# Format datetime as dd/mm/yyyy
return cell.strftime('%d/%m/%Y')
elif isinstance(cell, date):
# Format date as dd/mm/yyyy
return cell.strftime('%d/%m/%Y')
elif isinstance(cell, timedelta):
@@ -38,9 +44,18 @@ def format_cell_data(cell):
hours, remainder = divmod(total_seconds, 3600)
minutes, seconds = divmod(remainder, 60)
return f"{hours:02d}:{minutes:02d}:{seconds:02d}"
elif hasattr(cell, 'date'): # Handle date objects
# Format date as dd/mm/yyyy
return cell.strftime('%d/%m/%Y')
elif isinstance(cell, str):
# Handle string dates in yyyy-mm-dd or yyyy-mm-dd HH:MM:SS
import re
match = re.match(r'^(\d{4})-(\d{2})-(\d{2})(.*)$', cell)
if match:
year, month, day, rest = match.groups()
formatted = f"{day}/{month}/{year}"
if rest.strip():
# If there is a time part, keep it after the date
formatted += rest
return formatted
return cell
else:
return cell
@@ -262,7 +277,9 @@ def scan():
ORDER BY Id DESC
LIMIT 15
""")
scan_data = cursor.fetchall()
raw_scan_data = cursor.fetchall()
# Apply formatting to scan data for consistent date display
scan_data = [[format_cell_data(cell) for cell in row] for row in raw_scan_data]
conn.close()
except mariadb.Error as e:
print(f"Error fetching scan data: {e}")
@@ -2393,6 +2410,11 @@ def import_locations_csv():
from app.warehouse import import_locations_csv_handler
return import_locations_csv_handler()
@warehouse_bp.route('/generate_location_label_pdf', methods=['POST'])
def generate_location_label_pdf():
from app.warehouse import generate_location_label_pdf
return generate_location_label_pdf()
# NOTE for frontend/extension developers:
# To print labels, call the Chrome extension and pass the PDF URL: