fix(procurement): align correction actions with shipment state
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildPacking, buildPhysical, physicalForm, shippedCartons } from './procurementPhysicalForm'
|
||||
import { buildPacking, buildPhysical, physicalForm, shippedCartons, managementReason, receiptCorrectionReason } from './procurementPhysicalForm'
|
||||
import { readPendingProcurement } from './procurementPending'
|
||||
import type { PlatformProcurement } from './procurementTypes'
|
||||
const base = { version: 7, idempotencyKey: 'physical-one', reason: '现场核对' }
|
||||
@@ -65,11 +65,52 @@ describe('procurement physical request validation', () => {
|
||||
expect(payload).toMatchObject({ kind: 'SHORTAGE', decision: 'ACCEPT_SHORTAGE', quantity: 3 }); expect(payload).not.toHaveProperty('receiptId')
|
||||
})
|
||||
it('corrects an original receipt without counting it twice or moving its origin', () => {
|
||||
const value = detail(); const form = physicalForm(); form.receiptId = '11'; form.leg = 'DOMESTIC'; form.sourceCartonId = '31'; form.goodQuantity = 5; form.damagedQuantity = 1; form.receivedAt = '2020-01-02T10:00:00'
|
||||
const value = detail(); value.purchaseFacts.overseas_shipped_at = null; const form = physicalForm(); form.receiptId = '11'; form.leg = 'DOMESTIC'; form.sourceCartonId = '31'; form.goodQuantity = 5; form.damagedQuantity = 1; form.receivedAt = '2020-01-02T10:00:00'
|
||||
const payload = buildPhysical('receipts/correct', form, value, base, '20', '901')
|
||||
expect(payload).toMatchObject({ receiptId: '11', leg: 'OVERSEAS', goodQuantity: 5 }); expect(payload).not.toHaveProperty('sourceCartonId')
|
||||
expect(readPendingProcurement(JSON.stringify({ command: 'receipts/correct', payload }))).not.toBeNull()
|
||||
})
|
||||
it('blocks shipped receipt corrections while preserving domestic corrections before customer shipment', () => {
|
||||
const value = detail()
|
||||
expect(receiptCorrectionReason(value, 'OVERSEAS')).toContain('本段已实际交寄')
|
||||
expect(receiptCorrectionReason(value, 'DOMESTIC')).toBeNull()
|
||||
value.purchaseFacts.customer_shipped_at = '2020-01-05T10:00:00'
|
||||
expect(receiptCorrectionReason(value, 'DOMESTIC')).toContain('本段已实际交寄')
|
||||
value.purchaseFacts.overseas_shipped_at = null
|
||||
value.physical.packingStatus = 'CONFIRMED'
|
||||
expect(receiptCorrectionReason(value, 'OVERSEAS')).toContain('先撤回')
|
||||
value.physical.packingStatus = 'DRAFT'
|
||||
expect(receiptCorrectionReason(value, 'OVERSEAS')).toBeNull()
|
||||
})
|
||||
it.each(['REJECTED', 'CANCELLED', 'EXCEPTION_CLOSED', 'SHIPPED_TO_CUSTOMER'])('blocks physical changes for %s but leaves evidence and warehouse correction available', status => {
|
||||
const value = detail(); value.customerView.order.status = status
|
||||
expect(managementReason('receipts/correct', value)).toContain('订单已结束')
|
||||
expect(managementReason('dispositions', value)).toContain('订单已结束')
|
||||
expect(managementReason('packing/withdraw', value)).toContain('订单已结束')
|
||||
expect(managementReason('control-notes', value)).toBeNull()
|
||||
expect(managementReason('actual-warehouse/correct', value)).toBeNull()
|
||||
const form = physicalForm(); form.receiptId = '11'
|
||||
expect(() => buildPhysical('receipts/correct', form, value, base, '20', '901')).toThrow('订单已结束')
|
||||
})
|
||||
it('requires the correct physical source and unfinished receipt before recording differences', () => {
|
||||
const value = detail(); value.purchaseFacts = {}
|
||||
expect(managementReason('dispositions', value)).toContain('交寄来源')
|
||||
value.purchaseFacts.purchased_at = '2020-01-01'
|
||||
expect(managementReason('dispositions', value)).toBeNull()
|
||||
value.purchaseFacts.overseas_received_at = '2020-01-02'
|
||||
expect(managementReason('dispositions', value)).not.toBeNull()
|
||||
value.purchaseFacts.overseas_shipped_at = '2020-01-03'
|
||||
expect(managementReason('dispositions', value)).toBeNull()
|
||||
value.purchaseFacts.domestic_received_at = '2020-01-04'
|
||||
expect(managementReason('dispositions', value)).toContain('本段收货已完成')
|
||||
})
|
||||
it('rejects a shipped receipt even when another leg still offers a correctable receipt', () => {
|
||||
const value = detail()
|
||||
value.physical.receipts.push({ ...value.physical.receipts[0]!, id: '13', leg: 'DOMESTIC', sourceCartonId: '31' })
|
||||
expect(managementReason('receipts/correct', value)).toBeNull()
|
||||
const form = physicalForm(); form.receiptId = '11'
|
||||
expect(() => buildPhysical('receipts/correct', form, value, base, '20', '901')).toThrow('本段已实际交寄')
|
||||
})
|
||||
it('confirms the exact draft version and rejects malformed persisted packing before replay', () => {
|
||||
const value = detail(); const form = physicalForm(value)
|
||||
expect(buildPhysical('packing/confirm', form, value, base, '', '')).toEqual({ ...base, packingVersion: 2 })
|
||||
|
||||
Reference in New Issue
Block a user