Files
TimeTracker/docker/fix-invoice-tables.py
Dries Peeters d230a41e8a feat: enhance web interface layout and fix logo import circular dependency
- Improve web interface layout for better user-friendliness and mobile responsiveness
  * Update CSS variables for consistent spacing and component sizing
  * Enhance card layouts with improved padding, borders, and shadows
  * Optimize button and form element dimensions for better touch targets
  * Add hover effects and animations for improved user interaction
  * Implement responsive grid system with mobile-first approach

- Refactor mobile JavaScript to prevent duplicate initialization
  * Consolidate mobile enhancements into dedicated utility classes
  * Add initialization guards to prevent double loading
  * Implement MobileUtils and MobileNavigation classes
  * Remove duplicate event listeners and mobile enhancements

- Fix circular import issue in logo handling
  * Replace problematic 'from app import app' with Flask's current_app
  * Add error handling for cases where current_app is unavailable
  * Improve logo path resolution with fallback mechanisms
  * Fix settings model to use proper Flask context

- Clean up template code and remove duplication
  * Remove duplicate mobile enhancements from base template
  * Clean up dashboard template JavaScript
  * Centralize all mobile functionality in mobile.js
  * Add proper error handling and debugging

- Update CSS variables and spacing system
  * Introduce --section-spacing and --card-spacing variables
  * Add mobile-specific spacing variables
  * Improve border-radius and shadow consistency
  * Enhance typography and visual hierarchy

This commit resolves the double loading issue and logo import errors while
significantly improving the overall user experience and mobile responsiveness
of the web interface.
2025-08-30 10:09:06 +02:00

94 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""
Quick fix script to create missing invoice tables
Run this if the database is missing invoice tables
"""
import os
import sys
from sqlalchemy import create_engine, text, inspect
def main():
url = os.getenv("DATABASE_URL", "")
if not url.startswith("postgresql"):
print("No PostgreSQL database configured")
return
print(f"Database URL: {url}")
try:
engine = create_engine(url, pool_pre_ping=True)
inspector = inspect(engine)
# Check if invoice tables exist
existing_tables = inspector.get_table_names()
print(f"Existing tables: {existing_tables}")
if 'invoices' in existing_tables and 'invoice_items' in existing_tables:
print("✓ Invoice tables already exist")
return
print("Creating missing invoice tables...")
# Create invoices table
if 'invoices' not in existing_tables:
print("Creating invoices table...")
create_invoices_sql = """
CREATE TABLE invoices (
id SERIAL PRIMARY KEY,
invoice_number VARCHAR(50) UNIQUE NOT NULL,
project_id INTEGER REFERENCES projects(id) ON DELETE CASCADE,
client_name VARCHAR(200) NOT NULL,
client_email VARCHAR(200),
client_address TEXT,
issue_date DATE NOT NULL,
due_date DATE NOT NULL,
status VARCHAR(20) DEFAULT 'draft' NOT NULL,
subtotal NUMERIC(10, 2) NOT NULL DEFAULT 0,
tax_rate NUMERIC(5, 2) NOT NULL DEFAULT 0,
tax_amount NUMERIC(10, 2) NOT NULL DEFAULT 0,
total_amount NUMERIC(10, 2) NOT NULL DEFAULT 0,
notes TEXT,
terms TEXT,
created_by INTEGER REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
"""
with engine.connect() as conn:
conn.execute(text(create_invoices_sql))
conn.commit()
print("✓ invoices table created")
# Create invoice_items table
if 'invoice_items' not in existing_tables:
print("Creating invoice_items table...")
create_invoice_items_sql = """
CREATE TABLE invoice_items (
id SERIAL PRIMARY KEY,
invoice_id INTEGER REFERENCES invoices(id) ON DELETE CASCADE,
description VARCHAR(500) NOT NULL,
quantity NUMERIC(10, 2) NOT NULL DEFAULT 1,
unit_price NUMERIC(10, 2) NOT NULL,
total_amount NUMERIC(10, 2) NOT NULL,
time_entry_ids VARCHAR(500),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
"""
with engine.connect() as conn:
conn.execute(text(create_invoice_items_sql))
conn.commit()
print("✓ invoice_items table created")
print("✓ All invoice tables created successfully")
except Exception as e:
print(f"Error creating invoice tables: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == '__main__':
main()