b6bac080bb
- Excel preview detects when a product already has a different STEP file linked - Excel preview detects intra-Excel conflicts (same product, different CAD model names) - Product STEP upload warns when replacing an existing file and shows render count - All warnings are non-blocking (amber badges, toast warnings) - LEARNINGS.md: all open items resolved Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4.0 KiB
4.0 KiB
Plan: Duplicate Product Detection
Context
When importing products via Excel or STEP upload, there's no warning when a product already exists with a different STEP file. This can lead to accidental overwrites or confusion. The feature adds non-blocking warnings (yellow badges, toasts) at import time.
Detection Scenarios
- Excel preview: Product exists in DB with a different STEP file linked → warning icon
- Excel preview: Same product in two rows with different
name_cad_modell→ conflict badge - STEP upload on product: Replacing an existing STEP file on a product that has renders → toast warning
- All warnings are non-blocking — user can still proceed
Affected Files
| File | Change |
|---|---|
backend/app/services/excel_import.py |
Add STEP conflict detection in preview_excel_rows() |
backend/app/api/routers/uploads.py |
Extend preview response with conflict fields |
backend/app/api/routers/products.py |
Add render-count warning to CAD upload response |
frontend/src/api/uploads.ts |
Update TypeScript interfaces |
frontend/src/pages/Upload.tsx |
Display conflict warnings in preview table |
frontend/src/api/products.ts |
Add warning fields to CAD upload response type |
frontend/src/pages/ProductDetail.tsx |
Show toast warnings on STEP replacement |
Tasks
[ ] Task 1: Backend — STEP conflict detection in Excel preview
- File:
backend/app/services/excel_import.py - What: In
preview_excel_rows(), after the product lookup:- If product exists and has
cad_file_id, load the CadFile and compareoriginal_name(stem) with the Excel row'sname_cad_modell - If they differ → set
step_conflict=Truewith details - Track
name_cad_modellper product key in theseendict - If same product appears again with different
name_cad_modell→ setcad_name_conflict=True
- If product exists and has
- Also: Add
selectinload(Product.cad_file)tolookup_product()inbackend/app/domains/products/service.py - Dependencies: None
[ ] Task 2: Backend — Extend preview response models
- File:
backend/app/api/routers/uploads.py - What: Add to the preview row dict and response:
step_conflict: bool,step_conflict_existing_name: str | None,step_conflict_excel_name: str | Nonecad_name_conflict: bool,cad_name_conflict_other_name: str | None,cad_name_conflict_row: int | None- Response-level:
step_conflict_count: int,cad_name_conflict_count: int
- Dependencies: Task 1
[ ] Task 3: Backend — Render warning on product STEP replacement
- File:
backend/app/api/routers/products.py - What: In
upload_product_cad(), before replacing cad_file_id:- Check if product already has a different
cad_file_id - Count existing MediaAssets (renders) for this product
- Add
warnings: list[str]andexisting_render_count: intto response
- Check if product already has a different
- Dependencies: None
[ ] Task 4: Frontend — Update API types
- File:
frontend/src/api/uploads.ts - What: Add conflict fields to
ExcelPreviewRowandExcelPreviewResultinterfaces - Also:
frontend/src/api/products.ts— addwarnings?: string[]andexisting_render_count?: numbertoProductCadUploadResponse - Dependencies: Tasks 2, 3
[ ] Task 5: Frontend — Show conflict warnings in Upload preview
- File:
frontend/src/pages/Upload.tsx - What:
- Add StatCards for
step_conflict_countandcad_name_conflict_count(amber color, AlertTriangle icon) - In the preview table rows: yellow warning icon with tooltip for
step_conflictandcad_name_conflict
- Add StatCards for
- Dependencies: Task 4
[ ] Task 6: Frontend — Show warnings on STEP replacement
- File:
frontend/src/pages/ProductDetail.tsx - What: In
cadUploadMut.onSuccess, check response forwarningsand showtoast.warning()for each - Dependencies: Task 4
Migration Check
No — all detection is computed from existing data.
Order
- Backend Tasks 1+2 (Excel preview conflicts)
- Backend Task 3 (STEP replacement warning)
- Frontend Tasks 4+5+6 (types + UI)