const { PrismaClient } = require('@prisma/client') const prisma = new PrismaClient() async function createTestSupplyOrder() { console.log('🧪 Создаём тестовый заказ поставки с правильными данными...') try { // Найдем организацию фулфилмента const fulfillmentOrg = await prisma.organization.findFirst({ where: { type: 'FULFILLMENT' }, select: { id: true, name: true } }) if (!fulfillmentOrg) { console.log('❌ Организация фулфилмента не найдена') return } // Найдем поставщика (организацию не фулфилмента) const supplierOrg = await prisma.organization.findFirst({ where: { type: { not: 'FULFILLMENT' }, id: { not: fulfillmentOrg.id } }, select: { id: true, name: true } }) if (!supplierOrg) { console.log('❌ Организация поставщика не найдена') return } console.log(`🏢 Фулфилмент: ${fulfillmentOrg.name}`) console.log(`🚚 Поставщик: ${supplierOrg.name}`) // Создаем или находим тестовый товар с article let testProduct = await prisma.product.findFirst({ where: { organizationId: supplierOrg.id, type: 'CONSUMABLE' // Расходник } }) if (!testProduct) { console.log('📦 Создаём тестовый товар-расходник...') testProduct = await prisma.product.create({ data: { name: 'Тестовый Пакет', article: `ТП${Date.now()}`, // Уникальный артикул description: 'Тестовый расходник для проверки системы', price: 50.00, quantity: 1000, stock: 1000, type: 'CONSUMABLE', organizationId: supplierOrg.id, } }) console.log(`✅ Создан тестовый товар: ${testProduct.name} (артикул: ${testProduct.article})`) } else { console.log(`📦 Используем существующий товар: ${testProduct.name} (артикул: ${testProduct.article})`) } // Создаем заказ поставки console.log('📋 Создаём заказ поставки...') const supplyOrder = await prisma.supplyOrder.create({ data: { partnerId: supplierOrg.id, organizationId: supplierOrg.id, // Селлер-создатель fulfillmentCenterId: fulfillmentOrg.id, deliveryDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // +7 дней status: 'SHIPPED', // Готов для приема totalAmount: 250.00, // 5 штук по 50 totalItems: 5, consumableType: 'FULFILLMENT_CONSUMABLES', // Важно! } }) // Создаем элемент заказа await prisma.supplyOrderItem.create({ data: { supplyOrderId: supplyOrder.id, productId: testProduct.id, quantity: 5, price: 50.00, totalPrice: 250.00, } }) console.log(`✅ Создан заказ поставки:`) console.log(` ID: ${supplyOrder.id}`) console.log(` Статус: ${supplyOrder.status}`) console.log(` Товар: ${testProduct.name} x5`) console.log(` Артикул товара: ${testProduct.article}`) console.log(` Тип расходников: ${supplyOrder.consumableType}`) console.log('\n🎯 Теперь попробуйте принять этот заказ в интерфейсе и проверьте ошибки в консоли') } catch (error) { console.error('❌ Ошибка при создании заказа:', error) } finally { await prisma.$disconnect() } } createTestSupplyOrder()