feat(v2-inventory): мигрировать систему расходников на V2 архитектуру
Переход от старой таблицы Supply к новой FulfillmentConsumableInventory: - Обновлен mySupplies resolver для чтения из V2 таблицы с корректными остатками - Добавлена V2 мутация updateFulfillmentInventoryPrice для обновления цен - Исправлен counterpartySupplies для показа актуальных V2 цен в рецептурах - Frontend использует новую мутацию UPDATE_FULFILLMENT_INVENTORY_PRICE - Цены расходников корректно сохраняются и отображаются после перезагрузки - Селлеры видят правильные цены при создании поставок товаров 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -10,7 +10,7 @@ import { toast } from 'sonner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { UPDATE_SUPPLY_PRICE } from '@/graphql/mutations'
|
||||
import { UPDATE_FULFILLMENT_INVENTORY_PRICE } from '@/graphql/mutations'
|
||||
import { GET_MY_SUPPLIES } from '@/graphql/queries'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
|
||||
@ -55,16 +55,16 @@ export function SuppliesTab() {
|
||||
const [isInitialized, setIsInitialized] = useState(false)
|
||||
|
||||
// Debug информация
|
||||
console.log('SuppliesTab - User:', user?.phone, 'Type:', user?.organization?.type)
|
||||
console.warn('SuppliesTab - User:', user?.phone, 'Type:', user?.organization?.type)
|
||||
|
||||
// GraphQL запросы и мутации
|
||||
const { data, loading, error, refetch } = useQuery(GET_MY_SUPPLIES, {
|
||||
skip: !user || user?.organization?.type !== 'FULFILLMENT',
|
||||
})
|
||||
const [updateSupplyPrice] = useMutation(UPDATE_SUPPLY_PRICE)
|
||||
const [updateFulfillmentInventoryPrice] = useMutation(UPDATE_FULFILLMENT_INVENTORY_PRICE)
|
||||
|
||||
// Debug GraphQL запроса
|
||||
console.log('SuppliesTab - Query:', {
|
||||
console.warn('SuppliesTab - Query:', {
|
||||
skip: !user || user?.organization?.type !== 'FULFILLMENT',
|
||||
loading,
|
||||
error: error?.message,
|
||||
@ -167,7 +167,7 @@ export function SuppliesTab() {
|
||||
// Проверяем валидность цены (может быть пустой)
|
||||
const pricePerUnit = supply.pricePerUnit.trim() ? parseFloat(supply.pricePerUnit) : null
|
||||
|
||||
if (supply.pricePerUnit.trim() && (isNaN(pricePerUnit!) || pricePerUnit! <= 0)) {
|
||||
if (supply.pricePerUnit.trim() && (pricePerUnit === null || isNaN(pricePerUnit) || pricePerUnit <= 0)) {
|
||||
toast.error('Введите корректную цену')
|
||||
setIsSaving(false)
|
||||
return
|
||||
@ -177,17 +177,18 @@ export function SuppliesTab() {
|
||||
pricePerUnit: pricePerUnit,
|
||||
}
|
||||
|
||||
await updateSupplyPrice({
|
||||
await updateFulfillmentInventoryPrice({
|
||||
variables: { id: supply.id, input },
|
||||
update: (cache, { data }) => {
|
||||
if (data?.updateSupplyPrice?.supply) {
|
||||
if (data?.updateFulfillmentInventoryPrice?.item) {
|
||||
const existingData = cache.readQuery({ query: GET_MY_SUPPLIES }) as { mySupplies: Supply[] } | null
|
||||
if (existingData) {
|
||||
const updatedItem = data.updateFulfillmentInventoryPrice.item
|
||||
cache.writeQuery({
|
||||
query: GET_MY_SUPPLIES,
|
||||
data: {
|
||||
mySupplies: existingData.mySupplies.map((s: Supply) =>
|
||||
s.id === data.updateSupplyPrice.supply.id ? data.updateSupplyPrice.supply : s,
|
||||
s.id === updatedItem.id ? updatedItem : s,
|
||||
),
|
||||
},
|
||||
})
|
||||
|
Reference in New Issue
Block a user