Files
octopus/test_order_signals.py
Andrey Smakotin 6c8af5ab2c fix: Улучшения системы ценообразования комплектов
Исправлены 4 проблемы:
1. Расчёт цены первого товара - улучшена валидация в getProductPrice и calculateFinalPrice
2. Отображение actual_price в Select2 вместо обычной цены
3. Количество по умолчанию = 1 для новых форм компонентов
4. Auto-select текста при клике на поле количества для удобства редактирования

Изменённые файлы:
- products/forms.py: добавлен __init__ в KitItemForm для quantity.initial = 1
- products/templates/includes/select2-product-init.html: обновлена formatSelectResult
- products/templates/productkit_create.html: добавлен focus handler для auto-select
- products/templates/productkit_edit.html: добавлен focus handler для auto-select

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 19:04:03 +03:00

117 lines
3.5 KiB
Python

import os
import sys
import django
from decimal import Decimal
from datetime import datetime, timedelta
sys.path.insert(0, 'C:/Users/team_/Desktop/test_qwen/myproject')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
django.setup()
from tenants.models import Client
from django.db import connection
from products.models import Product
from inventory.models import Warehouse, Incoming, Reservation, Sale
from orders.models import Order, OrderItem
from customers.models import Customer
grach = Client.objects.get(schema_name='grach')
connection.set_tenant(grach)
print("=== Order Signals Test ===\n")
# Получаем товар и склад
product = Product.objects.get(sku='FLOWER-001')
warehouse = Warehouse.objects.get(name='Main Warehouse')
# Создаем приходы
print("Step 1: Creating incoming batches\n")
Incoming.objects.create(
product=product,
warehouse=warehouse,
quantity=Decimal('50'),
cost_price=Decimal('100.00')
)
print(" Incoming: qty=50, cost=100.00")
# Создаем клиента
print("\nStep 2: Creating customer\n")
customer, created = Customer.objects.get_or_create(
phone='+375291234567',
defaults={
'name': 'Test Customer',
'email': 'test@example.com'
}
)
print(" Customer: {} ({})".format(customer.name, customer.phone))
# Создаем заказ
print("\nStep 3: Creating order\n")
try:
delivery_date = datetime.now() + timedelta(days=1)
order = Order.objects.create(
order_number='ORD-001',
customer=customer,
status='pending',
delivery_type='courier',
delivery_date=delivery_date
)
print(" Order created: ORD-001, status=pending")
# Создаем позицию заказа
order_item = OrderItem.objects.create(
order=order,
product=product,
quantity=Decimal('5'),
price=Decimal('200.00')
)
print(" OrderItem: 5 units")
# Проверяем резервирование
print("\nStep 4: Checking reservations\n")
reservations = Reservation.objects.filter(order_item=order_item, status='reserved')
print("Reservations count: {}".format(reservations.count()))
if reservations.exists():
for res in reservations:
print(" PASS: Reservation created - qty={}, status={}".format(res.quantity, res.status))
else:
print(" FAIL: No reservations found!")
# Меняем статус на in_delivery
print("\nStep 5: Changing order status to in_delivery\n")
order.status = 'in_delivery'
order.save()
print(" Order status changed to in_delivery")
# Проверяем продажу
print("\nStep 6: Checking sales\n")
sales = Sale.objects.filter(order=order)
print("Sales count: {}".format(sales.count()))
if sales.exists():
for sale in sales:
print(" PASS: Sale created - qty={}, price={}".format(sale.quantity, sale.sale_price))
print(" processed={}".format(sale.processed))
else:
print(" FAIL: No sales found!")
# Проверяем обновленное резервирование
print("\nStep 7: Checking updated reservations\n")
updated_reservations = Reservation.objects.filter(order_item=order_item)
for res in updated_reservations:
print(" Reservation status: {}".format(res.status))
except Exception as e:
print("ERROR: {}".format(str(e)))
import traceback
traceback.print_exc()