Skip to content

Commit

Permalink
MODORDERS-1185. mod-orders 12.8.10 bug fix release
Browse files Browse the repository at this point in the history
  • Loading branch information
BKadirkhodjaev authored and SerhiiNosko committed Sep 18, 2024
1 parent f7ab95f commit 381c546
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## 12.9.0 - Unreleased

## 12.8.10 - Released (Quesnelia R1 2024)
The primary focus of this release was to fix issue with updating an encumbrance when exchange rate is edited
[Full Changelog](https://github.com/folio-org/mod-orders/compare/v12.8.9...v12.8.10)

### Bug Fixes
* [MODORDERS-1185](https://folio-org.atlassian.net/browse/MODORDERS-1185) - Encumbrance amount does not update when exchange rate is edited on open order


## 12.8.9 - Released (Quesnelia R1 2024)
The primary focus of this release was to provide support for mapping the order line donor information field during order import
[Full Changelog](https://github.com/folio-org/mod-orders/compare/v12.8.8...v12.8.9)
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/folio/helper/PurchaseOrderLineHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,19 +777,35 @@ private boolean isEncumbranceUpdateNeeded(CompositePurchaseOrder compOrder, Comp
List<FundDistribution> requestFundDistros = compositePoLine.getFundDistribution();
List<FundDistribution> storageFundDistros = storagePoLine.getFundDistribution();

if (compOrder.getWorkflowStatus() == CLOSED || (requestFundDistros.size() + storageFundDistros.size()) == 0 ) {
if (compOrder.getWorkflowStatus() == CLOSED || (requestFundDistros.size() + storageFundDistros.size()) == 0) {
return false;
}

if (!compositePoLine.getCost().getPoLineEstimatedPrice().equals(storagePoLine.getCost().getPoLineEstimatedPrice())
|| !compositePoLine.getCost().getCurrency().equals(storagePoLine.getCost().getCurrency())
|| hasAlteredExchangeRate(storagePoLine.getCost(), compositePoLine.getCost())
|| (requestFundDistros.size() != storageFundDistros.size())) {
return true;
}

return !CollectionUtils.isEqualCollection(requestFundDistros, storageFundDistros);
}

static boolean hasAlteredExchangeRate(Cost oldCost, Cost newCost) {
var oldExchangeRate = oldCost.getExchangeRate();
var newExchangeRate = newCost.getExchangeRate();
if (Objects.isNull(oldExchangeRate) && Objects.isNull(newExchangeRate)) {
return false;
}
if (Objects.isNull(oldExchangeRate) || Objects.isNull(newExchangeRate)) {
logger.info("hasAlteredExchangeRate:: Exchange rate is null in one of the costs");
return true;
}
var exchangeRateIsAltered = !newExchangeRate.equals(oldExchangeRate);
logger.info("hasAlteredExchangeRate:: Exchange rate is altered: {}", exchangeRateIsAltered);
return exchangeRateIsAltered;
}

private Future<Void> validateAccessProviders(CompositePoLine compOrderLine, RequestContext requestContext) {
return organizationService.validateAccessProviders(Collections.singletonList(compOrderLine), requestContext)
.map(errors -> {
Expand Down
54 changes: 21 additions & 33 deletions src/test/java/org/folio/helper/PurchaseOrderLineHelperTest.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
package org.folio.helper;

import static org.folio.TestConfig.clearServiceInteractions;
import static org.folio.TestConfig.initSpringContext;
import static org.folio.TestConfig.isVerticleNotDeployed;
import static org.folio.rest.impl.MockServer.BASE_MOCK_DATA_PATH;
import org.folio.rest.jaxrs.model.Cost;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;

import org.folio.ApiTestSuite;
import org.folio.config.ApplicationConfig;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class PurchaseOrderLineHelperTest {
private static final String ORDER_ID = "1ab7ef6a-d1d4-4a4f-90a2-882aed18af14";
private static final String ORDER_PATH = BASE_MOCK_DATA_PATH + "compositeOrders/" + ORDER_ID + ".json";

private static boolean runningOnOwn;

@BeforeAll
static void before() throws InterruptedException, ExecutionException, TimeoutException {
if (isVerticleNotDeployed()) {
ApiTestSuite.before();
runningOnOwn = true;
}
initSpringContext(ApplicationConfig.class);
}

@AfterEach
void afterEach() {
clearServiceInteractions();
private static Stream<Arguments> testHasAlteredExchangeRateArgs() {
return Stream.of(
Arguments.of(false, 0.7d, 0.7d),
Arguments.of(false, null, null),
Arguments.of(true, 0.7d, 0.8d),
Arguments.of(true, null, 0.8d),
Arguments.of(true, 0.7d, null)
);
}

@AfterAll
static void after() {
if (runningOnOwn) {
ApiTestSuite.after();
}
@ParameterizedTest
@MethodSource("testHasAlteredExchangeRateArgs")
void testHasAlteredExchangeRate(boolean expected, Double oldExchangeRate, Double newExchangeRate) {
var currencyCode = "AUD";
var oldCost = new Cost().withCurrency(currencyCode).withExchangeRate(newExchangeRate);
var newCost = new Cost().withCurrency(currencyCode).withExchangeRate(oldExchangeRate);
assertEquals(expected, PurchaseOrderLineHelper.hasAlteredExchangeRate(oldCost, newCost));
}

}

0 comments on commit 381c546

Please sign in to comment.