From bc81ab4849aaefd847542dd24c3700e6ab15a792 Mon Sep 17 00:00:00 2001 From: Irakli Merabishvili Date: Mon, 18 Dec 2023 18:29:15 +0400 Subject: [PATCH] [MODORDERS-969] - Opening and editing POs with location-restricted funds --- .../flows/update/open/OpenCompositeOrderFlowValidator.java | 4 ++-- .../update/open/OpenCompositeOrderFlowValidatorTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidator.java b/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidator.java index 288830fe0..31a65b5a6 100644 --- a/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidator.java +++ b/src/main/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidator.java @@ -131,10 +131,10 @@ public Future checkFundLocationRestrictions(List poLines, private Future validateLocationRestrictions(CompositePoLine poLine, List funds) { List polLocationIds = poLine.getLocations().stream().map(Location::getLocationId).toList(); for (Fund fund : funds) { - if (Boolean.TRUE.equals(fund.getRestrictByLocations()) && CollectionUtils.containsAny(fund.getLocationIds(), polLocationIds)) { + if (Boolean.TRUE.equals(fund.getRestrictByLocations()) && !CollectionUtils.containsAll(fund.getLocationIds(), polLocationIds)) { String poLineId = poLine.getId(); String fundId = fund.getId(); - Collection restrictedLocations = CollectionUtils.intersection(fund.getLocationIds(), polLocationIds); + Collection restrictedLocations = CollectionUtils.subtract(polLocationIds, fund.getLocationIds()); logger.error("For POL {} fund {} is restricted to be used for locations {}", poLineId, fundId, restrictedLocations); List parameters = List.of( new Parameter().withKey("poLineId").withValue(poLineId), diff --git a/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidatorTest.java b/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidatorTest.java index b5223d120..7a70fa1bd 100644 --- a/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidatorTest.java +++ b/src/test/java/org/folio/service/orders/flows/update/open/OpenCompositeOrderFlowValidatorTest.java @@ -59,8 +59,8 @@ public void testCheckFundLocationRestrictions(VertxTestContext vertxTestContext) ); Mockito.when(fundService.getFunds(fundIds, requestContext)).thenReturn( Future.succeededFuture(List.of( - new Fund().withId("F1").withCode("FC").withRestrictByLocations(true).withLocationIds(List.of("L4")), - new Fund().withId("F2").withCode("FC").withRestrictByLocations(true).withLocationIds(List.of("L2", "L3")) + new Fund().withId("F1").withCode("FC").withRestrictByLocations(true).withLocationIds(List.of("L1", "L2", "L3", "L4")), + new Fund().withId("F2").withCode("FC").withRestrictByLocations(true).withLocationIds(List.of("L2")) )) ); @@ -78,7 +78,7 @@ public void testCheckFundLocationRestrictions(VertxTestContext vertxTestContext) new Parameter().withKey("poLineNumber").withValue(poLine.getPoLineNumber()), new Parameter().withKey("fundId").withValue("F2"), new Parameter().withKey("fundCode").withValue("FC"), - new Parameter().withKey("restrictedLocations").withValue("[L2, L3]") + new Parameter().withKey("restrictedLocations").withValue("[L1, L3]") ); assertEquals(FUND_LOCATION_RESTRICTION_VIOLATION.toError().withParameters(expectedParameters), exception.getError()); vertxTestContext.completeNow();