fix: reserve locations from measured volume

This commit is contained in:
2026-09-04 15:05:44 +08:00
parent 5e013489e0
commit 8a0366af5b
2 changed files with 39 additions and 3 deletions
@@ -144,6 +144,7 @@ class MeasurementLocationOccupationServiceTest {
InboundOrderEntity inbound = inbound();
inbound.setActualVolumeCbm(null);
InboundMeasurementEntity measurement = new InboundMeasurementEntity();
measurement.setTotalVolumeCbm(new BigDecimal("1.0000"));
measurement.setOriginalVolumeCbm(new BigDecimal("2.5000"));
when(workflow.findOwned(BUSINESS_TENANT, INBOUND)).thenReturn(inbound);
when(measurements.findLatestMeasurement(BUSINESS_TENANT, INBOUND)).thenReturn(measurement);
@@ -162,6 +163,32 @@ class MeasurementLocationOccupationServiceTest {
20, new BigDecimal("2.5000"), block("OCCUPIED", 3));
}
@Test
void reservesByCurrentMeasuredVolumeBeforeFrozenDeclaredVolume() {
InboundOrderEntity inbound = inbound();
inbound.setActualVolumeCbm(null);
InboundMeasurementEntity measurement = new InboundMeasurementEntity();
measurement.setTotalVolumeCbm(new BigDecimal("2.5000"));
measurement.setOriginalVolumeCbm(new BigDecimal("1.0000"));
when(workflow.findOwned(BUSINESS_TENANT, INBOUND)).thenReturn(inbound);
when(measurements.findLatestMeasurement(BUSINESS_TENANT, INBOUND)).thenReturn(measurement);
when(measurements.listWeights(BUSINESS_TENANT, INBOUND))
.thenReturn(confirmedWeights().subList(0, 1));
when(warehouse.reserveBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
org.mockito.ArgumentMatchers.any())).thenReturn(ApiResponse.success(block("RESERVED", 3)));
when(warehouse.confirmBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
org.mockito.ArgumentMatchers.any())).thenReturn(ApiResponse.success(block("OCCUPIED", 3)));
service.ensureForConfirmedWeight(BUSINESS_TENANT, INBOUND, OPERATOR, MEASUREMENT, 3);
verify(orderCargo, never()).measurementDeclaration(org.mockito.ArgumentMatchers.anyString(),
org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.anyLong());
verify(warehouse).reserveBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
org.mockito.ArgumentMatchers.argThat(request -> request.requiredSlotCount() == 3));
verify(allocations).replaceBlock(BUSINESS_TENANT, INBOUND, WAREHOUSE,
20, new BigDecimal("2.5000"), block("OCCUPIED", 3));
}
@Test
void fallsBackToLatestOrderDeclarationWhenNoMeasurementBatchExists() {
InboundOrderEntity inbound = inbound();