Files
HartOMat/backend/app/domains/imports/tasks.py
T
Hartmut f19a6ccde8 feat(F-G-H-I): STL cache, invoices, import validation, notification settings
Phase F — STL Hash Cache:
- Migration 041: step_file_hash column on cad_files
- cache_service.py: SHA256 hash + MinIO-backed STL cache (check/store)
- render_step_thumbnail: compute+persist hash before render
- generate_stl_cache: check MinIO cache before cadquery conversion, store after

Phase G — Invoices:
- Migration 042: invoices + invoice_lines tables with RLS
- Invoice/InvoiceLine models + schemas
- billing service: generate_invoice_number (INV-YYYY-NNNN), create/list/get/delete/PDF
- WeasyPrint PDF generation; backend Dockerfile + pyproject.toml deps
- invoice_router with 6 endpoints; registered in main.py
- frontend: Billing.tsx page + api/billing.ts; route + nav link

Phase H — Import Sanity Check:
- Migration 043: import_validations table
- ImportValidation model + schemas
- run_sanity_check: material fuzzy-match (cutoff=0.8), STEP availability, duplicate detection
- validate_excel_import Celery task (queue: step_processing)
- uploads.py: create ImportValidation on /excel, fire task, expose GET /validations/{id}
- frontend: Upload.tsx polling ValidationDialog with Ampel status indicators

Phase I — Notification Settings:
- Migration 044: notification_configs table (user×event×channel toggles)
- NotificationConfig model + seeds (in_app=true, email=false)
- get/upsert/reset config endpoints on /notifications/config
- frontend: NotificationSettings.tsx page + api/notifications.ts extensions

Infrastructure:
- docker-compose.yml: add worker-thumbnail service (concurrency=1, Q=thumbnail_rendering)
- Fix Dockerfile: libgdk-pixbuf-2.0-0 (correct Debian bookworm package name)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 18:05:01 +01:00

39 lines
1.6 KiB
Python

"""Celery tasks for import validation."""
from __future__ import annotations
import logging
from celery import shared_task
logger = logging.getLogger(__name__)
@shared_task(name="imports.validate_excel_import", queue="step_processing", bind=True)
def validate_excel_import(self, validation_id: str, excel_path: str, tenant_id: str | None = None):
"""Run sanity check on imported Excel file and store results."""
logger.info("Running import validation %s for %s", validation_id, excel_path)
try:
from app.domains.imports.service import run_sanity_check
result = run_sanity_check(validation_id, excel_path, tenant_id)
logger.info("Validation %s completed: %s", validation_id, result.get("summary", {}))
return result
except Exception as exc:
logger.error("Validation %s failed: %s", validation_id, exc)
# Mark as failed in DB
try:
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from app.config import settings as app_settings
from app.domains.imports.models import ImportValidation
from datetime import datetime
sync_url = app_settings.database_url.replace("+asyncpg", "")
engine = create_engine(sync_url)
with Session(engine) as db:
val = db.get(ImportValidation, validation_id)
if val:
val.status = "failed"
val.completed_at = datetime.utcnow()
db.commit()
except Exception:
pass
raise