Commit Graph

315 Commits

Author SHA1 Message Date
5df182e030 Fix: Auto-fill product prices when empty or zero in autosave
Исправлена проблема с пропаданием цен товаров при автосохранении и
перезагрузке страницы.

ПРОБЛЕМА:
- При автосохранении пустые поля цен отправлялись как '0'
- Backend сохранял 0 в базу данных
- При перезагрузке страницы поля цен оставались пустыми
- Итоговая сумма товаров показывала 0.00 руб.

РЕШЕНИЕ 1 - Backend (draft_service.py):
- Изменена логика обработки цен в update_draft()
- Если цена пустая или равна 0, используется actual_price из каталога
- Добавлена корректная обработка price_raw перед конвертацией в Decimal
- Улучшена логика определения is_custom_price

Логика обработки цены:
1. Получаем price_raw из items_data
2. Если price_raw пустой или 0 → используем original_price из каталога
3. Если price_raw заполнен → используем его и сравниваем с original_price
4. is_custom_price = True только если разница больше 0.01

РЕШЕНИЕ 2 - Frontend (order_form.html):
- Добавлена fallback логика в шаблоне для отображения цены
- Если item_form.instance.price пустой/None/0 → показываем actual_price
- Используется inline условие {% if %} для проверки наличия цены
- Отдельная логика для product и product_kit

Теперь работает корректно:
 При выборе товара цена автоматически заполняется из каталога
 Автосохранение сохраняет правильную цену (из каталога или изменённую)
 При перезагрузке страницы цены отображаются корректно
 Итоговая сумма товаров рассчитывается правильно
 Бейдж "Изменена" показывается только для реально изменённых цен

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 20:15:50 +03:00
80260c8a34 Fix: Restore delivery address and order items data on page reload
Исправлены две критические проблемы с автосохранением и восстановлением
данных при перезагрузке страницы редактирования заказа:

1. ПРОБЛЕМА: Адрес доставки не восстанавливался после перезагрузки
   РЕШЕНИЕ (forms.py):
   - Добавлена инициализация полей адреса в OrderForm.__init__()
   - Поля заполняются из order.delivery_address при редактировании
   - Инициализируются все поля: улица, дом, квартира, подъезд, этаж, домофон, инструкции

2. ПРОБЛЕМА: Цены и количество товаров не сохранялись через автосохранение
   РЕШЕНИЕ (draft_service.py):
   - Добавлена обработка items в DraftOrderService.update_draft()
   - Автосохранение теперь обновляет/создаёт/удаляет позиции заказа
   - Сохраняются: product/product_kit, quantity, price, is_custom_price
   - Корректно определяется is_custom_price через сравнение с оригинальной ценой

Логика обработки items:
- Существующие позиции обновляются (product, quantity, price)
- Новые позиции создаются
- Лишние позиции удаляются
- Поддержка как товаров (product_id), так и комплектов (product_kit_id)

Теперь при перезагрузке страницы:
 Адрес доставки полностью восстанавливается во всех полях
 Товары сохраняются с правильными ценами и количествами
 Изменённые цены корректно отмечаются бейджем "Изменена"
 Все данные синхронизируются между автосохранением и базой данных

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:57:32 +03:00
a3f5ac4c08 Fix: Enable autosave for delivery address fields with partial data
Исправлена проблема с автосохранением полей адреса доставки. Теперь адрес
сохраняется при заполнении любого поля, а не только при наличии улицы и
номера дома.

Изменения в Backend (address_service.py):
- Изменена логика валидации в process_address_from_form()
- Теперь адрес сохраняется если заполнено хотя бы одно поле
- Удалено жёсткое требование заполнения street и building_number
- Проверяем наличие данных во всех полях адреса

Изменения в Frontend (autosave.js):
- Переработана логика сбора данных адреса
- address_mode='new' устанавливается при заполнении любого поля адреса
- Все непустые поля адреса отправляются на сервер
- Используется более элегантный подход с Object.values() и .some()

Теперь автосохранение работает корректно:
- Заполнение поля "Улица" → автосохранение срабатывает
- Заполнение "Номер дома" → автосохранение срабатывает
- Заполнение любого другого поля адреса → автосохранение срабатывает
- После перезагрузки страницы все данные восстанавливаются

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:49:58 +03:00
fbc9d86a62 Fix: Set original price for existing order items on page load
Исправлена проблема с отображением бейджа "Изменена" для существующих
товаров в заказе. Теперь при загрузке страницы для всех существующих
позиций устанавливается атрибут data-original-price с актуальной ценой
из каталога, что позволяет корректно отслеживать изменения цены.

Изменения:
- Добавлена условная логика рендеринга поля price с атрибутом data-original-price
- Для товаров используется item_form.instance.product.actual_price
- Для комплектов используется item_form.instance.product_kit.actual_price
- Бейдж "Изменена" теперь работает одинаково для всех форм

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:42:18 +03:00
436cac28ed Feat: Add order items total sum display with real-time calculation
Добавлено отображение общей суммы всех товаров в заказе с автоматическим
обновлением в реальном времени при изменении количества, цены, добавлении
или удалении товаров.

Изменения:
- HTML: Добавлен блок отображения итоговой суммы товаров под списком позиций
- JavaScript: Реализованы функции calculateOrderItemsTotal() и updateOrderItemsTotal()
- Интеграция: Подключены слушатели событий на поля quantity и price
- Обновление суммы происходит при:
  * Изменении количества или цены товара
  * Добавлении новой позиции
  * Удалении позиции
  * Загрузке страницы

Сумма автоматически исключает удалённые формы и корректно обрабатывает
пустые значения. Форматирование: 2 знака после запятой.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 19:39:03 +03:00
22bf7e137d Feat: Add inline price editing for products in catalog
Implemented inline editing functionality for product prices directly in the catalog view with support for both regular and sale prices.

Features:
- Click-to-edit price fields with visual hover indicators
- Separate editing for price and sale_price fields
- Add/remove sale price with validation
- Real-time UI updates without page reload
- Permission-based access control
- Server-side validation for price constraints

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 01:23:46 +03:00
0f212bda69 модерн 2025-11-25 01:14:38 +03:00
b9e02af74a Improve: Auto-expand parent category and clarify expand/collapse buttons
Improvements to category tree UX:
- Auto-expand parent category after creating subcategory at any nesting level
- Recursive ancestor expansion using elegant DOM traversal with .closest()
- Smooth scroll to newly created category with visual feedback
- Replace icon buttons with text: "Развернуть все" / "Свернуть все"
- Eliminates confusion between "+" for adding category vs expanding tree

Technical implementation:
- URL parameter ?expand=<parent_id> to preserve state after page reload
- Recursive expandAncestors() function traverses up the DOM tree
- Uses :scope selector for precise parent-child relationship queries
- Auto-cleans URL parameter after expansion using history.replaceState()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 00:37:41 +03:00
d566819367 Feat: Add inline category creation in catalog with clickable product names
Added inline category creation functionality to catalog page with user-friendly interface:
- Inline input fields for creating root and nested categories
- '+' button in category tree header for root categories
- '+' icon on hover for each category node to create subcategories
- Clickable product/kit names in catalog grid and list views
- AJAX API endpoint for category creation with validation
- User-friendly error messages for duplicate names and constraints
- Clean implementation using clearTimeout pattern to prevent duplicate requests

Technical details:
- New API endpoint: POST /products/api/categories/create/
- Auto-generates slug and SKU for new categories
- Validates uniqueness, parent existence, and circular references
- Single-request submission with proper race condition handling
- Removes debug logging for production-ready code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 00:24:05 +03:00
03990292a5 Refactor: Show rename icon on hover instead of click on name
Changed category rename behavior - clicking name now expands/collapses,
pencil icon appears on hover for renaming.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 01:00:51 +03:00
6517643e0d Feat: Add catalog page with inline category renaming
- Create catalog view with category tree and product grid
- Add grid/list view toggle for products
- Implement inline category name editing (click to rename)
- Add API endpoint for category rename
- Extract JS to separate catalog.js file
- Remove unused partial templates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:54:34 +03:00
4549b2c2c2 Feat: Add catalog page with category tree and product grid
- Create catalog view with recursive category tree building
- Add left-side category tree with expand/collapse functionality
- Add right-side product/kit grid with filtering and search
- Include category navigation with product/kit counts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-24 00:31:37 +03:00
157bd50082 Refactor: Compact UI for product tags templates
Redesigned tag_form.html and tag_list.html with modern, compact layout:
- Narrower card width, inline form elements, simplified controls
- List-group layout instead of table for tag list
- Streamlined JavaScript with auto-hiding messages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 23:54:58 +03:00
addc5e0962 Feat: Автоматическая себестоимость товара (read-only)
- Удалено ручное редактирование себестоимости из формы товара
- Себестоимость теперь рассчитывается автоматически из партий (FIFO)
- Добавлена модель CostPriceHistory для логирования изменений
- Добавлен signal для автоматического логирования изменений cost_price
- Админ-панель: себестоимость read-only с детальной информацией о партиях
- Фронтенд: цены перемещены под название, теги под категории
- Поле cost_price сделано опциональным (default=0) для создания товаров

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 23:22:45 +03:00
493b6c212d Add bulk photo deletion feature for products.
Allows selecting and deleting multiple photos at once via checkboxes
and an AJAX endpoint. Key features:
- Checkboxes next to each photo in edit form
- Delete button that shows only when photos are selected
- AJAX request with JSON payload and success confirmation
- DOM removal and counter update after deletion
- Uses existing ImageProcessor cleanup logic

Files changed:
- product_form.html: Added checkboxes and delete button with JS handler
- photo_management.py: Added product_photos_delete_bulk AJAX view
- urls.py: Added /product/photos/delete-bulk/ endpoint
- views/__init__.py: Exported new function

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:49:50 +03:00
26146ac639 Add automatic cleanup of empty photo directories after deletion.
When photos are deleted, now automatically removes empty photo_id
directories after all image versions are removed. Uses safe empty
directory checks and handles tenant-aware file storage correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:42:21 +03:00
8079abe939 Feat: Add cleanup_tenant management command for improved tenant deletion
- Create new cleanup_tenant command with better tenant deletion workflow
- Handle TenantRegistration automatic processing (keep history or delete)
- Add --purge-registration flag to remove TenantRegistration records
- Add --delete-files flag to remove physical tenant files from /media/tenants/
- Provide detailed deletion summary with confirmation step
- Update УДАЛЕНИЕ_ТЕНАНТОВ.md documentation with:
  * Complete guide for new cleanup_tenant command
  * Explanation of TenantRegistration problem and solutions
  * Recommendations for different use cases (test vs production)
  * Examples of all command variants

Tested:
- Successfully deleted grach tenant (no registration)
- Successfully deleted bingo tenant with --purge-registration flag
- Verified registration records are properly managed
- All database and file operations work correctly

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 21:32:32 +03:00
30f21989d6 Fix: Use storage.url() for tenant-aware image URLs in frontend
Updated ImageService to use default_storage.url() instead of manually
constructing URLs. This ensures images displayed on the frontend correctly
include the tenant_id in the path, enabling proper file access within
multi-tenant environment.

Changes:
- ImageService.get_url() now delegates to default_storage.url()
- All image URLs now include /media/tenants/{tenant_id}/ path
- Ensures consistent behavior with TenantAwareFileSystemStorage
- Frontend photos now display correctly with tenant isolation

Result:
- Thumbnail URLs: /media/tenants/papa/products/4/28/thumb.webp
- Medium URLs: /media/tenants/papa/products/4/28/medium.webp
- Large URLs: /media/tenants/papa/products/4/28/large.webp
- Original URLs: /media/tenants/papa/products/4/28/original.jpg

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 20:55:02 +03:00
87cba63c47 Fix: Add _open() and path() methods to TenantAwareFileSystemStorage
Critical fix for Celery photo processing. The storage class now correctly
handles file reading operations by automatically adding tenant_id prefix
when opening files.

Problems fixed:
- Celery tasks could not open image files from storage
- PIL/Pillow couldn't locate files in tenant-specific directories
- temp file deletion was failing due to path validation

Changes:
- Added _open() method to add tenant_id prefix when opening files
- Added path() method to convert relative paths to full filesystem paths
- Updated delete() method to handle paths with or without tenant prefix
- All methods include security checks to prevent cross-tenant access

Testing:
- All 5 existing tests pass
- Verified photo processing task works end-to-end:
  * Reads temp image file from disk
  * Processes and creates all image versions
  * Saves processed files to tenant-specific directory
  * Cleans up temporary files correctly
- Files correctly stored in: media/tenants/{tenant_id}/products/{product_id}/{photo_id}/

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 20:30:52 +03:00
ff40a9c1f0 Fix: Implement tenant-aware file storage for photo isolation
Resolves critical bug where photos of products with the same ID in different
tenants were overwriting each other. Implemented complete isolation of media
files between tenants using custom Django storage backend.

## Changes

### New Files
- products/utils/storage.py: TenantAwareFileSystemStorage backend
  * Automatically adds tenant_id to file paths on disk
  * Prevents cross-tenant file access with security checks
  * Stores clean paths in DB for portability

- products/tests/test_multi_tenant_photos.py: Comprehensive tests
  * 5 tests covering isolation, security, and configuration
  * All tests passing 

- MULTITENANT_PHOTO_FIX.md: Complete documentation

### Modified Files
- settings.py: Configured DEFAULT_FILE_STORAGE to use TenantAwareFileSystemStorage
- products/models/photos.py:
  * Converted upload_to from strings to callable functions
  * Updated ProductPhoto, ProductKitPhoto, ProductCategoryPhoto
  * Added tenant isolation documentation

- products/tasks.py: Added documentation about file structure
- products/utils/image_processor.py: Added documentation
- products/utils/image_service.py: Added documentation

## Architecture

**On disk:** media/tenants/{tenant_id}/products/{entity_id}/{photo_id}/{size}.ext
**In DB:** products/{entity_id}/{photo_id}/{size}.ext

Tenant ID is automatically added/removed during file operations.

## Security
- Storage rejects cross-tenant file access
- Proper tenant context validation
- Integration with django-tenants schema system

## Testing
- All 5 multi-tenant photo tests pass
- Verified photo paths are isolated per tenant
- Verified storage rejects cross-tenant access
- Verified configuration is correct

## Future-proof
- Ready for S3 migration (just change storage backend)
- No breaking changes to existing code
- Clean separation of concerns

Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 20:05:20 +03:00
122ea807d2 Fix: Remove unused Product import from Customer model
The import was left over from the removed loyalty system and could
cause issues during tenant creation when products tables don't exist yet.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 18:06:21 +03:00
4a9df60f91 Auto-create order statuses on tenant activation
Add OrderStatusService.create_default_statuses() call during tenant
registration approval. Creates 8 system order statuses (draft, new,
confirmed, in_assembly, in_delivery, completed, return, cancelled).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 01:14:28 +03:00
d3d3c23695 Add stock availability display to product list and detail views
- Add total_available, total_reserved, total_free annotations to product queries
- Display free stock (green/red) with reserved count in product list
- Show detailed stock info in product detail page (moved to top)
- Make reservation count clickable to view filtered reservations
- Add product filter support to ReservationListView
- Add product link in reservation list for easy navigation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 00:31:38 +03:00
856e1ca4c1 Fix select_for_update with nullable FK outer join error
Remove select_related('locked_by_user') from select_for_update query
to avoid PostgreSQL error "FOR UPDATE cannot be applied to the
nullable side of an outer join". Username is now fetched via lazy load.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 23:33:52 +03:00
38ee2f5df7 Fix race condition and expired lock validation for showcase kit cart
- Add select_for_update() with transaction.atomic() to prevent race condition
  when multiple users try to add the same showcase kit simultaneously
- Validate cart lock expiration when loading cart from Redis - showcase kits
  with expired locks are now filtered out instead of being displayed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 19:00:48 +03:00
c856d5d50a миграц 2025-11-22 18:00:13 +03:00
fac3d55083 Удалена система лояльности из модели Customer
Удалены поля loyalty_tier, is_vip, get_loyalty_discount(), increment_total_spent().
Поле total_spent оставлено для будущего расчёта по заказам.
Обновлены admin, forms, views и шаблоны.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-22 17:05:18 +03:00
59a7152967 Add Celery Beat schedule files to .gitignore and remove from tracking
These files are automatically generated by Celery Beat and should not be
version controlled. They contain runtime schedule state and are specific
to each environment.

Files removed from tracking:
- celerybeat-schedule
- celerybeat-schedule-shm
- celerybeat-schedule-wal

Added to .gitignore to prevent future accidental commits.
2025-11-21 00:35:27 +03:00
c572cdcc26 Filter POS showcase kits by showcase__isnull=False
Fix issue where temporary kits created for orders (with order field set
but showcase=NULL) were appearing in POS terminal showcase list.

Problem:
- When creating temporary kit from order edit page, it has order=<Order>
  and showcase=NULL
- get_showcase_kits_for_pos() was showing ALL temporary kits with
  reserved components, regardless of showcase field
- This caused order kits to appear in POS showcase view
- Users couldn't add them to cart (showcase=NULL check failed)

Solution:
- Add showcase__isnull=False filter to ProductKit query
- This ensures only kits explicitly assigned to showcases are shown
- Order kits (showcase=NULL) are now excluded from POS showcase list

Clear separation:
- Temporary kits for orders: order != NULL, showcase = NULL
- Temporary kits for showcases: showcase != NULL

File: pos/views.py:85

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 00:32:49 +03:00
08a5527ba7 Fix cart lock validation and error handling improvements
## 1. Add cart lock validation to sell_from_showcase()
- Prevent selling showcase kits locked in another cashier's cart
- Check cart_lock_expires_at before allowing direct sales
- Return clear error message with lock holder's name and time remaining
- File: inventory/services/showcase_manager.py

## 2. Improve error handling in POS create_temp_kit_to_showcase()
- Add detailed logging for all error types (JSON, validation, generic)
- Provide user-friendly error messages instead of generic 500
- Log full context (kit name, showcase ID, items, user) for debugging
- Categorize errors: stock issues, integrity, locks, not found
- File: pos/views.py

## 3. Fix critical bug in create_temporary_kit()
- Replace non-existent is_active field with status='active'
- Affects 3 locations: kit creation, product lookup, kit duplication
- This was causing 500 errors when creating temporary kits from order edit
- File: products/services/kit_service.py

## 4. Improve error handling in create_temporary_kit_api()
- Add comprehensive logging for order creation endpoint
- Provide specific error messages for common failure scenarios
- Help diagnose issues when creating kits from order editing UI
- File: products/views/api_views.py

These changes complete the Soft Lock system and fix the 500 error issue.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-21 00:24:59 +03:00
33e33ecbac Добавлена система Soft Lock для витринных комплектов в POS-терминале
Реализована элегантная блокировка витринных букетов при добавлении в корзину,
предотвращающая многократную продажу одного физического комплекта.

## Изменения в БД:
- Добавлены поля в Reservation: cart_lock_expires_at, locked_by_user, cart_session_id
- Созданы индексы для оптимизации запросов блокировок
- Миграция 0006: добавление полей Soft Lock

## Backend (pos/views.py):
- add_showcase_kit_to_cart: создание блокировки на 30 минут с проверкой конфликтов
- remove_showcase_kit_from_cart: снятие блокировки при удалении из корзины
- get_showcase_kits_api: возврат статусов блокировок (is_locked, locked_by_me)

## Frontend (terminal.js):
- addToCart: AJAX запрос для создания блокировки, запрет qty > 1
- removeFromCart: автоматическое снятие блокировки
- renderCart: желтый фон, badge "1 шт (витрина)", скрыты кнопки +/−
- UI индикация: зеленый badge "В корзине" (свой), красный "Занят" (чужой)

## Автоматизация (inventory/tasks.py):
- cleanup_expired_cart_locks: Celery periodic task (каждые 5 минут)
- Автоматическое освобождение истекших блокировок (30 минут timeout)
- Логирование очистки для мониторинга

## Маршруты (pos/urls.py):
- POST /api/showcase-kits/<id>/add-to-cart/ - создание блокировки
- POST /api/showcase-kits/<id>/remove-from-cart/ - снятие блокировки

## Документация:
- ЗАПУСК.md: инструкция по запуску Celery Beat

Преимущества:
✓ Предотвращает конфликты между кассирами
✓ Автоматическое освобождение при таймауте
✓ Понятный UX с визуальной индикацией
✓ Совместимость с существующей логикой резервирования

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 23:45:34 +03:00
ff0756498c Fix Product filtering and add kit disassembly functionality
Fixed:
- Replace is_active with status='active' for Product filtering in IncomingModelForm
- Product model uses status field instead of is_active

Added:
- Showcase field to ProductKit for tracking showcase placement
- product_kit field to Reservation for tracking kit-specific reservations
- Disassemble button in POS terminal for showcase kits
- API endpoint for kit disassembly (release reservations, mark discontinued)
- Improved reservation filtering when dismantling specific kits

Changes:
- ShowcaseManager now links reservations to specific kit instances
- POS terminal modal shows disassemble button in edit mode
- Kit disassembly properly updates stock aggregates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 23:03:47 +03:00
d3060176c0 Fix ProductKit admin queryset error
Change from ProductKit.all_objects.all() to super().get_queryset()
since ProductKit model doesn't have an all_objects manager.

Fixes AttributeError: type object 'ProductKit' has no attribute 'all_objects'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 13:20:40 +03:00
82261cbba7 Remove direct reservation management from web interface
PROBLEM:
Direct deletion/creation of reservations via web interface bypassed
POS business logic, creating data inconsistencies (orphaned showcase kits,
incorrect stock calculations).

SOLUTION:
Make reservations read-only in web interface. All reservation management
now happens only through:
- POS (showcase kits)
- Orders module

CHANGES:
- Remove reservation-create and reservation-update URL routes
- Delete ReservationCreateView and ReservationUpdateView
- Remove ReservationForm (no longer needed)
- Delete reservation_form.html and reservation_update.html templates
- Update reservation_list.html to read-only view with info banner
- Add showcase and order columns to reservation list
- Clean up imports in urls.py and views/__init__.py

Reservations are now read-only for monitoring purposes only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 13:17:04 +03:00
cd037e8f6b Add is_default field to Showcase admin interface
- Add is_default to list_display and list_filter
- Include is_default in fieldsets for editing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 12:10:04 +03:00
dd184265ee Add default showcase selection per warehouse
- Add is_default field to Showcase model with unique constraint per warehouse
- Implement Showcase.save() to ensure only one default per warehouse
- Add SetDefaultShowcaseView for AJAX-based default selection
- Update ShowcaseForm to include is_default checkbox
- Add interactive checkbox UI in showcase list with AJAX functionality
- Update POS API to return showcase.is_default instead of warehouse.is_default
- Update terminal.js to auto-select showcase based on its is_default flag
- Add migration for is_default field

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 11:40:08 +03:00
766ca3c87c Add full CRUD interface for Showcase management
Implemented complete web interface for managing showcases (display areas for ready-made bouquets) with:

**Backend:**
- ShowcaseForm with validation (unique name per warehouse)
- ShowcaseListView with filtering by warehouse and status
- ShowcaseCreateView, ShowcaseUpdateView with success messages
- ShowcaseDeleteView with active reservation validation
- URL routes: list, create, edit, delete

**Frontend:**
- List page with warehouse grouping, active reservations count
- Responsive table with filters (warehouse, status)
- Create/edit form with Bootstrap styling
- Delete confirmation with active reservations check
- Breadcrumb navigation

**Features:**
 One warehouse can have multiple showcases (ForeignKey relationship)
 Unique showcase names within each warehouse
 Display active reservation counts for each showcase
 Prevent deletion if showcase has active reservations
 Auto-select default warehouse when creating showcase
 Navigation link added to main navbar between "Касса" and "Склад"
 Active state highlighting in navigation

**Files created:**
- inventory/forms_showcase.py (ShowcaseForm)
- inventory/views/showcase.py (4 CBV views)
- inventory/templates/inventory/showcase/ (list, form, delete templates)

**Files modified:**
- inventory/urls.py (added showcase routes)
- inventory/forms.py (added Showcase import)
- templates/navbar.html (added "Витрины" link)

URL structure:
/inventory/showcases/ - list
/inventory/showcases/create/ - create
/inventory/showcases/<id>/edit/ - edit
/inventory/showcases/<id>/delete/ - delete

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 10:52:53 +03:00
07c8819936 Add interactive customer selection to checkout modal
Replaced static customer display in the checkout/sale modal with the same interactive button functionality from the cart sidebar.

Changes:
- **HTML**: Replaced static div with interactive button + reset button in checkout modal
- **JavaScript**:
  - Updated updateCustomerDisplay() to handle both locations (cart + checkout modal)
  - Added event listeners for checkout modal customer buttons
  - Both buttons now synchronized and use the same selection modal

Benefits:
 Consistent UX across cart and checkout modal
 Full code reuse - same selection modal, search, and logic
 Both locations stay synchronized automatically
 Can search, select, and reset customer directly from checkout modal

Implementation:
- Cart sidebar button: customerSelectBtn, resetCustomerBtn
- Checkout modal button: checkoutCustomerSelectBtn, checkoutResetCustomerBtn
- Single updateCustomerDisplay() updates both locations
- Single selectCustomer() used by all buttons

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 10:31:42 +03:00
763ad2ce07 Add styled +/- quantity controls to POS cart
Implemented intuitive quantity management in the cart with:
- Minus button (-): Decreases quantity by 1, removes item if qty becomes 0
- Plus button (+): Increases quantity by 1
- Quantity input field: Centered, uniform styling with buttons
- All controls styled with Bootstrap outline-secondary (gray) for cohesive look
- Buttons feature Bootstrap Icons (dash-circle, plus-circle) at 1.2em size
- Auto-save to Redis after each quantity change

Benefits:
 Faster quantity adjustments without keyboard input
 Consistent gray styling across all quantity controls
 Mobile-friendly touch targets
 Automatic cart persistence maintained

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 10:19:28 +03:00
eac778b06d Add Redis-based persistence for POS cart and customer selection
Implemented Redis caching with 2-hour TTL for POS session data:

Backend changes:
- Added Redis cache configuration in settings.py
- Created save_cart() endpoint to persist cart state
- Added cart and customer loading from Redis in pos_terminal()
- Validates cart items (products/kits) still exist in DB
- Added REDIS_HOST, REDIS_PORT, REDIS_DB to .env

Frontend changes:
- Added saveCartToRedis() with 500ms debounce
- Cart auto-saves on add/remove/quantity change
- Added cart initialization from Redis on page load
- Enhanced customer button with two-line display and reset button
- Red X button appears only for non-system customers

Features:
- Cart persists across page reloads (2 hour TTL)
- Customer selection persists (2 hour TTL)
- Independent cart per user+warehouse combination
- Automatic cleanup of deleted items
- Debounced saves to reduce server load

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 09:55:03 +03:00
685c06d94d Добавлена функциональность системного клиента для анонимных покупок
- Добавлено поле is_system_customer в модель Customer с индексом
- Системный клиент создается автоматически при создании нового тенанта
- Реализована защита системного клиента от редактирования и удаления:
  - Защита на уровне модели (save/delete методы)
  - Защита на уровне формы (валидация)
  - Защита на уровне представлений (проверки с дружественными сообщениями)
  - Защита в админке (readonly поля, запрет удаления)
- Системный клиент скрыт из списков и поиска на фронтенде
- Создан информационный шаблон для отображения системного клиента
- Исправлена обработка NULL значений для полей email/phone (Django best practice)
- Добавлено отображение "Не указано" вместо None в карточке клиента

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 00:07:38 +03:00
755e4fc9d9 комит 2025-11-19 22:12:01 +03:00
fdd14804a7 Улучшена таблица статусов заказов: заменены иконки Font Awesome на Bootstrap Icons, увеличены бейджи, полные названия типов и итогов, кнопки действий только с иконками 2025-11-19 00:53:16 +03:00
a1888b7745 Optimize order statuses list page with compact card layout
- Changed from table to card-based design for better space efficiency
- Reduced padding and margins to fit 15+ statuses on screen without scrolling
- Minimized font sizes and icon sizes for compact display
- Added proper styling for edit and delete buttons with hover effects
- Improved visual hierarchy with color indicators and badges
- Maintained all functionality while improving UX

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 23:00:29 +03:00
67341b294f Remove temporary test scripts from git 2025-11-18 21:47:12 +03:00
29859503a7 Enforce parameter binding requirement for ConfigurableKitProduct variants
Changes:
1. Removed unused attributesMetadata container from configurablekit_form.html
   - Dead code from old formset-based attribute system
   - 10 lines of unused HTML and templating removed

2. Enhanced formset validation in BaseConfigurableKitOptionFormSet.clean():
   - If product HAS parameters: variants MUST select values for ALL parameters
   - If product HAS NO parameters: variants MUST NOT be created
   - Error message guides user to add parameters first

Business logic:
- ConfigurableKitProduct variants (options) are ALWAYS bound to attribute values
- You cannot create orphan variants without parameter selections
- Each variant must have a value for every product parameter

User experience:
- Clear error message if trying to add variant without parameters
- Enforces proper product structure: parameters first, then variants

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 21:46:58 +03:00
6cd7c0b7d3 Add kit binding display in ConfigurableKitProduct templates
Updated UI to show ProductKit associations for attribute values:

- configurablekit_detail.html:
  * Added 'Комплект' column to attributes table
  * Shows linked ProductKit as clickable badge
  * Shows '—' for unbound attributes

- configurablekit_list.html:
  * Added 'Атрибутов' column showing attribute count
  * Updated colspan for empty state message (6->7)

Now users can see which ProductKit each attribute value is bound to in:
1. Detail view: Click product -> view attributes with kit bindings
2. List view: See total attribute count for each product

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 21:34:25 +03:00
3f789785ca Add ProductKit binding to ConfigurableKitProductAttribute values
Implementation of kit binding feature for ConfigurableKitProduct variants:

- Added ForeignKey field `kit` to ConfigurableKitProductAttribute
  * References ProductKit with CASCADE delete
  * Optional field (blank=True, null=True)
  * Indexed for efficient queries

- Created migration 0007_add_kit_to_attribute
  * Handles existing data (NULL values for all current records)
  * Properly indexed for performance

- Updated template configurablekit_form.html
  * Injected available ProductKits into JavaScript
  * Added kit selector dropdown in card interface
  * Each value now has associated kit selection
  * JavaScript validates kit selection alongside values

- Updated JavaScript in card interface
  * serializeAttributeValues() now collects kit IDs
  * Creates parallel JSON arrays: values and kits
  * Stores in hidden fields: attributes-X-values and attributes-X-kits

- Updated views _save_attributes_from_cards() in both Create and Update
  * Reads kit IDs from POST JSON
  * Looks up ProductKit objects
  * Creates ConfigurableKitProductAttribute with FK populated
  * Gracefully handles missing kits

- Fixed _should_delete_form() method
  * More robust handling of formset deletion_field
  * Works with all formset types

- Updated __str__() method
  * Handles NULL kit case

Example workflow:
  Dlina: 50 -> Kit A, 60 -> Kit B, 70 -> Kit C
  Upakovka: BEZ -> Kit A, V_UPAKOVKE -> (no kit)

Tested with test_kit_binding.py - all tests passing
- Kit creation and retrieval
- Attribute creation with kit FK
- Mixed kit-bound and unbound attributes
- Querying attributes by kit
- Reverse queries (get kit for attribute value)

Added documentation: KIT_BINDING_IMPLEMENTATION.md

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 21:29:14 +03:00
a12f8f990d Fix: Remove readonly attribute from parameter name input field
The parameter name field had readonly='readonly' which prevented users from entering values.

This fix allows users to:
- Enter parameter name directly in the form field
- Modify parameter names during editing
- Type any parameter name they need

The readonly attribute was from a mistaken assumption that values would be pre-filled by JavaScript.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 20:57:13 +03:00
def795f0ad Implement card-based interface for ConfigurableKitProduct attributes
This commit introduces a new user-friendly interface for managing product attributes:

1. **Form Changes** (products/forms.py):
   - Removed 'option' field from ConfigurableKitOptionForm (values now inline)
   - Updated ConfigurableKitProductAttributeFormSetCreate to only include name, position, visible
   - Updated BaseConfigurableKitProductAttributeFormSet validation for new structure

2. **Template Updates** (products/templates/products/configurablekit_form.html):
   - Replaced row-based attribute interface with card-based design
   - Each card contains:
     - Parameter name field
     - Position field
     - Visibility toggle
     - Inline value inputs with add/remove buttons
   - "Add parameter" button creates new cards
   - "Add value" button adds inline value inputs

3. **JavaScript Enhancements**:
   - addValueField(): Creates new value input with delete button
   - initAddValueBtn(): Initializes add value button for each card
   - addParameterBtn: Dynamically generates new parameter cards
   - serializeAttributeValues(): Converts inline values to JSON for POST submission
   - Form submission intercept to serialize data before sending

4. **View Updates** (products/views/configurablekit_views.py):
   - Both Create and Update views now have _save_attributes_from_cards() method
   - Reads attributes-X-values JSON from POST data
   - Creates ConfigurableKitProductAttribute for each parameter+value combination
   - Handles parameter deletion and visibility toggling

**Key Features**:
✓ One-time parameter name entry with multiple inline values
✓ Add/remove values without reloading page
✓ Add/remove entire parameters with one click
✓ No database changes required
✓ Better UX: card layout more intuitive than rows
✓ Proper JSON serialization for value transmission

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 20:54:14 +03:00