Добавлено новое поле consumableType в модель SupplyOrder для классификации расходников. Обновлены компоненты и резолверы GraphQL для поддержки нового поля. Реализована валидация остатков и обновление данных о запасах при создании и отклонении заказов. Оптимизирован интерфейс для управления расходниками, добавлены уведомления о доступности товаров.
This commit is contained in:
@ -3829,6 +3829,7 @@ export const resolvers = {
|
||||
logisticsPartnerId?: string; // ID логистической компании
|
||||
items: Array<{ productId: string; quantity: number }>;
|
||||
notes?: string; // Дополнительные заметки к заказу
|
||||
consumableType?: string; // Классификация расходников
|
||||
};
|
||||
},
|
||||
context: Context
|
||||
@ -3983,6 +3984,7 @@ export const resolvers = {
|
||||
organizationId: currentUser.organization.id,
|
||||
fulfillmentCenterId: fulfillmentCenterId,
|
||||
logisticsPartnerId: args.input.logisticsPartnerId,
|
||||
consumableType: args.input.consumableType, // Классификация расходников
|
||||
status: initialStatus,
|
||||
items: {
|
||||
create: orderItems,
|
||||
@ -4022,6 +4024,23 @@ export const resolvers = {
|
||||
},
|
||||
});
|
||||
|
||||
// 📦 РЕЗЕРВИРУЕМ ТОВАРЫ У ПОСТАВЩИКА
|
||||
// Увеличиваем поле "ordered" для каждого заказанного товара
|
||||
for (const item of args.input.items) {
|
||||
await prisma.product.update({
|
||||
where: { id: item.productId },
|
||||
data: {
|
||||
ordered: {
|
||||
increment: item.quantity,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`📦 Зарезервированы товары для заказа ${supplyOrder.id}:`,
|
||||
args.input.items.map(item => `${item.productId}: +${item.quantity} шт.`).join(', '));
|
||||
|
||||
|
||||
// Создаем расходники на основе заказанных товаров
|
||||
// Расходники создаются в организации получателя (фулфилмент-центре)
|
||||
const suppliesData = args.input.items.map((item) => {
|
||||
@ -6109,6 +6128,22 @@ export const resolvers = {
|
||||
},
|
||||
});
|
||||
|
||||
// 📦 СНИМАЕМ РЕЗЕРВАЦИЮ ПРИ ОТКЛОНЕНИИ
|
||||
// Уменьшаем поле "ordered" для каждого отклоненного товара
|
||||
for (const item of updatedOrder.items) {
|
||||
await prisma.product.update({
|
||||
where: { id: item.productId },
|
||||
data: {
|
||||
ordered: {
|
||||
decrement: item.quantity,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`📦 Снята резервация при отклонении заказа ${updatedOrder.id}:`,
|
||||
updatedOrder.items.map(item => `${item.productId}: -${item.quantity} шт.`).join(', '));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: args.reason
|
||||
|
Reference in New Issue
Block a user