Skip to content

Commit

Permalink
Merge pull request #807 from folio-org/MODORDERS-969-2
Browse files Browse the repository at this point in the history
[MODORDERS-969] - Opening and editing POs with location-restricted funds
  • Loading branch information
imerabishvili authored Dec 18, 2023
2 parents 10c04b0 + bc81ab4 commit 8115281
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public Future<Void> checkFundLocationRestrictions(List<CompositePoLine> poLines,
private Future<Void> validateLocationRestrictions(CompositePoLine poLine, List<Fund> funds) {
List<String> 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<String> restrictedLocations = CollectionUtils.intersection(fund.getLocationIds(), polLocationIds);
Collection<String> restrictedLocations = CollectionUtils.subtract(polLocationIds, fund.getLocationIds());
logger.error("For POL {} fund {} is restricted to be used for locations {}", poLineId, fundId, restrictedLocations);
List<Parameter> parameters = List.of(
new Parameter().withKey("poLineId").withValue(poLineId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
))
);

Expand All @@ -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();
Expand Down

0 comments on commit 8115281

Please sign in to comment.