import os import sys import django from decimal import Decimal 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 orders.models import Order from inventory.models import Reservation, Sale, SaleBatchAllocation grach = Client.objects.get(schema_name='grach') connection.set_tenant(grach) print("=== Order Signals Test with Existing Order ===\n") # Получаем существующий заказ try: order = Order.objects.get(order_number__contains='ORD-20251027') print("Found order: {}".format(order.order_number)) print("Customer: {}".format(order.customer.name)) print("Items in order: {}".format(order.items.count())) # Показываем items print("\nOrder items:") for item in order.items.all(): product_name = item.product.name if item.product else item.product_kit.name print(" - {} qty={} price={}".format(product_name, item.quantity, item.price)) # Проверяем резервирования print("\n--- Checking Reservations ---\n") reservations = Reservation.objects.filter(order_item__order=order) print("Total reservations: {}".format(reservations.count())) if reservations.exists(): for res in reservations: print(" - qty={}, status={}, warehouse={}".format( res.quantity, res.status, res.warehouse.name )) else: print(" No reservations found - might not have been created yet") # Меняем статус на in_delivery print("\n--- Changing status to in_delivery ---\n") order.status = 'in_delivery' order.save() print("Order status changed to: {}".format(order.status)) # Проверяем продажи print("\n--- Checking Sales ---\n") sales = Sale.objects.filter(order=order) print("Total sales: {}".format(sales.count())) if sales.exists(): for sale in sales: print("\nSale:") print(" qty={}, price={}".format(sale.quantity, sale.sale_price)) print(" processed={}".format(sale.processed)) # Проверяем allocations allocations = SaleBatchAllocation.objects.filter(sale=sale) print(" Allocations: {}".format(allocations.count())) for alloc in allocations: print(" - batch qty={}, cost={}".format( alloc.quantity, alloc.cost_price )) else: print(" No sales found") # Проверяем финальный статус резервирования print("\n--- Final Reservations Status ---\n") final_reservations = Reservation.objects.filter(order_item__order=order) for res in final_reservations: print(" Reservation status: {}".format(res.status)) except Order.DoesNotExist: print("ERROR: Order not found!") except Exception as e: print("ERROR: {}".format(str(e))) import traceback traceback.print_exc()