Search in sources :

Example 1 with Metadata

use of org.folio.rest.acq.model.finance.Metadata in project mod-orders by folio-org.

the class PurchaseOrdersApiTest method testReopenOrderUnreleasesEncumbrancesUnlessInvoiceLineHasReleaseEncumbrance.

@Test
void testReopenOrderUnreleasesEncumbrancesUnlessInvoiceLineHasReleaseEncumbrance() {
    logger.info("=== Check encumbrances are unreleased when an order is reopened, except for po lines having a linked invoice line with releaseEncumbrance = true ===");
    String purchaseOrderId = "0fb18568-cf8d-442b-b74a-cad7cfa557a0";
    String poLineId1 = "0285a6b6-6693-4ea9-83e1-41d227063d88";
    String transactionId = "41fe8202-f038-4000-a969-4eee74ba8735";
    String fiscalYearId = "ac2164c7-ba3d-1bc2-a12c-e35ceccbfaf2";
    String fundId = "a89eccf0-57a6-495e-898d-32b9b2210f2f";
    List<String> transactionIds = Arrays.asList(transactionId);
    Cost cost = new Cost().withCurrency("USD").withListUnitPrice(10.00).withQuantityElectronic(1);
    FundDistribution fundDistribution = new FundDistribution().withFundId("fb7b70f1-b898-4924-a991-0e4b6312bb5f").withDistributionType(DistributionType.PERCENTAGE).withValue(100.00).withEncumbrance("eb506834-6c70-4239-8d1a-6414a5b08008");
    CompositePoLine poLines = new CompositePoLine().withId(poLineId1).withOrderFormat(OrderFormat.PHYSICAL_RESOURCE).withPoLineNumber("10233-1").withPhysical(new Physical().withCreateInventory(Physical.CreateInventory.NONE)).withPurchaseOrderId(purchaseOrderId).withAcquisitionMethod(TestUtils.PURCHASE_METHOD).withCollection(true).withCost(cost).withFundDistribution(Arrays.asList(fundDistribution));
    CompositePurchaseOrder reqData = new CompositePurchaseOrder().withId(purchaseOrderId).withApproved(true).withPoNumber("S60402").withOrderType(CompositePurchaseOrder.OrderType.ONE_TIME).withVendor("d0fb5aa0-cdf1-11e8-a8d5-f2801f1b9fd1").withWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
    Encumbrance encumbrance = new Encumbrance().withOrderType(Encumbrance.OrderType.ONE_TIME).withStatus(Encumbrance.Status.UNRELEASED).withSourcePoLineId(poLineId1).withReEncumber(false).withSubscription(false).withSourcePurchaseOrderId(purchaseOrderId).withInitialAmountEncumbered(10.00).withAmountAwaitingPayment(0.0).withAmountExpended(0.0);
    Metadata metadata = new Metadata().withCreatedByUserId("00000001-1111-5555-9999-999999999999").withUpdatedByUsername("00000001-1111-5555-9999-999999999999").withCreatedDate(new Date(2020, 05, 29, 11, 30)).withUpdatedDate(new Date(2020, 05, 30, 11, 30));
    Transaction transaction = new Transaction().withId(transactionId).withAmount(10.0).withSource(Transaction.Source.PO_LINE).withCurrency("USD").withToFundId(fundId).withEncumbrance(encumbrance).withFiscalYearId(fiscalYearId).withTransactionType(Transaction.TransactionType.ENCUMBRANCE).withMetadata(metadata);
    MockServer.addMockEntry(PO_LINES_STORAGE, JsonObject.mapFrom(poLines));
    MockServer.addMockEntry(PURCHASE_ORDER_STORAGE, JsonObject.mapFrom(reqData));
    assertThat(reqData.getWorkflowStatus(), is(CompositePurchaseOrder.WorkflowStatus.CLOSED));
    reqData.setWorkflowStatus(WorkflowStatus.OPEN);
    // NOTE: permissions are checked in another test
    verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData).encodePrettily(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID, REOPEN_PERMISSIONS_HEADER), "", 204);
    // check the order has been reopened, the first encumbrance has been unreleased but not the second one
    PurchaseOrder po = getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class);
    assertThat(po.getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.OPEN));
    List<Transaction> transactions = Arrays.asList(transaction);
    TransactionCollection transactionCollection = new TransactionCollection().withTransactions(Arrays.asList(transaction)).withTotalRecords(1);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            return null;
        }
    }).when(transactionService).updateTransactions(transactions, requestContext);
    doReturn(completedFuture(transactionCollection)).when(restClient).get(requestEntry, requestContext, TransactionCollection.class);
    doReturn(completedFuture(transactions)).when(transactionService).getTransactionsByIds(transactionIds, requestContext);
    List<Transaction> updatedTransactions = encumbranceService.getEncumbrancesByIds(transactionIds, requestContext).join();
    assertThat(updatedTransactions.size(), equalTo(1));
    Transaction updatedEncumbrance1 = updatedTransactions.get(0);
    assertThat(updatedEncumbrance1.getEncumbrance().getSourcePoLineId(), equalTo(poLineId1));
    assertThat(updatedEncumbrance1.getEncumbrance().getStatus(), equalTo(Encumbrance.Status.UNRELEASED));
}
Also used : TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) Metadata(org.folio.rest.acq.model.finance.Metadata) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Matchers.containsString(org.hamcrest.Matchers.containsString) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Cost(org.folio.rest.jaxrs.model.Cost) Date(java.util.Date) LocalDate(java.time.LocalDate) FundDistribution(org.folio.rest.jaxrs.model.FundDistribution) Physical(org.folio.rest.jaxrs.model.Physical) Transaction(org.folio.rest.acq.model.finance.Transaction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Aggregations

LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 TestUtils.getMinimalContentCompositePoLine (org.folio.TestUtils.getMinimalContentCompositePoLine)1 TestUtils.getMinimalContentCompositePurchaseOrder (org.folio.TestUtils.getMinimalContentCompositePurchaseOrder)1 Encumbrance (org.folio.rest.acq.model.finance.Encumbrance)1 Metadata (org.folio.rest.acq.model.finance.Metadata)1 Transaction (org.folio.rest.acq.model.finance.Transaction)1 TransactionCollection (org.folio.rest.acq.model.finance.TransactionCollection)1 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)1 CompositePurchaseOrder (org.folio.rest.jaxrs.model.CompositePurchaseOrder)1 Cost (org.folio.rest.jaxrs.model.Cost)1 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)1 Physical (org.folio.rest.jaxrs.model.Physical)1 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.jupiter.api.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1