Search in sources :

Example 6 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoiceLinesApiTest method testPutInvoiceLineUpdateTotalAndInvoice.

@Test
public void testPutInvoiceLineUpdateTotalAndInvoice() {
    logger.info("=== Test case when invoice line updates triggers also invoice update ===");
    InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_OUTDATED_TOTAL_PATH).mapTo(InvoiceLine.class);
    addMockEntry(INVOICE_LINES, invoiceLine);
    invoiceLine.setSubTotal(100.500d);
    verifyPut(invoiceLine.getId(), JsonObject.mapFrom(invoiceLine), "", 204);
    MatcherAssert.assertThat(getInvoiceLineRetrievals(), hasSize(1));
    MatcherAssert.assertThat(getInvoiceRetrievals(), hasSize(1));
    MatcherAssert.assertThat(getInvoiceLineUpdates(), hasSize(1));
    InvoiceLine updatedInvoiceLine = getInvoiceLineUpdates().get(0).mapTo(InvoiceLine.class);
    Assertions.assertEquals(100.5d, updatedInvoiceLine.getSubTotal());
    Assertions.assertEquals(10.15d, updatedInvoiceLine.getAdjustmentsTotal());
    Assertions.assertEquals(110.65d, updatedInvoiceLine.getTotal());
    MatcherAssert.assertThat(getInvoiceUpdates(), hasSize(1));
    Invoice updatedInvoice = getInvoiceUpdates().get(0).mapTo(Invoice.class);
    // invoice totals are using the line totals pre-update because the mock server is not actually modifying the line,
    // but we can check the total was correctly updated
    Assertions.assertEquals(4.2d, updatedInvoice.getSubTotal());
    Assertions.assertEquals(0.42d, updatedInvoice.getAdjustmentsTotal());
    Assertions.assertEquals(4.62d, updatedInvoice.getTotal());
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Test(org.junit.jupiter.api.Test)

Example 7 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoiceLinesApiTest method checkInvoiceLineUpdateUpdatesInvoicePoNumbers.

@Test
public void checkInvoiceLineUpdateUpdatesInvoicePoNumbers() {
    logger.info("=== Check an invoice line update triggers the update of the invoice's poNumbers field ===");
    InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_PO_NUMBER_PATH).mapTo(InvoiceLine.class);
    invoiceLine.setInvoiceId(OPEN_INVOICE_ID);
    addMockEntry(INVOICE_LINES, invoiceLine);
    verifyPut(INVOICE_LINE_WITH_PO_NUMBER, JsonObject.mapFrom(invoiceLine), "", 204);
    List<JsonObject> objects = serverRqRs.get(INVOICES, HttpMethod.PUT);
    assertThat(objects, notNullValue());
    Invoice updatedInvoice = objects.get(0).mapTo(Invoice.class);
    List<String> poNumbers = updatedInvoice.getPoNumbers();
    // that invoice already had a poNumber, it gets another one
    assertThat(poNumbers, hasSize(2));
    assertThat(poNumbers.get(1), equalTo("AB268758XYZ"));
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 8 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoiceLinesProratedAdjustmentsTest method testCreateFirstLineForInvoiceWithOneAdj.

@ParameterizedTest
@CsvSource({ "BY_AMOUNT, AMOUNT", "BY_AMOUNT, PERCENTAGE", "BY_LINE, AMOUNT", "BY_LINE, PERCENTAGE", "BY_QUANTITY, AMOUNT", "BY_QUANTITY, PERCENTAGE" })
public void testCreateFirstLineForInvoiceWithOneAdj(Adjustment.Prorate prorate, Adjustment.Type type) {
    logger.info("=== Creating first line for invoice with one prorated adjustment ===");
    // Prepare data "from storage"
    Invoice invoice = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withId(randomUUID().toString());
    Adjustment invoiceAdjustment = createAdjustment(prorate, type, 15d);
    invoice.withAdjustments(Collections.singletonList(invoiceAdjustment));
    addMockEntry(INVOICES, invoice);
    // Prepare request body
    InvoiceLine invoiceLineBody = getMockInvoiceLine(invoice.getId()).withSubTotal(25d).withQuantity(10);
    // Send update request
    InvoiceLine invoiceLine = verifySuccessPost(INVOICE_LINES_PATH, invoiceLineBody).as(InvoiceLine.class);
    // Verification
    assertThat(getInvoiceLineUpdates(), Matchers.hasSize(0));
    assertThat(getInvoiceUpdates(), Matchers.hasSize(1));
    compareRecordWithSentToStorage(invoiceLine);
    /*
     * Calculated adjustment value depends of type:
     * "Amount" - this is the same as adjustment value
     * "Percentage" - this is the percentage of subTotal i.e. 15% of 25$ = 3.75$
     */
    double expectedAdjTotal = (type == Adjustment.Type.AMOUNT) ? 15d : 3.75d;
    double expectedAdjValue = expectedAdjTotal;
    assertThat(invoiceLine.getAdjustments(), hasSize(1));
    assertThat(invoiceLine.getAdjustmentsTotal(), is(expectedAdjTotal));
    Adjustment lineAdjustment = invoiceLine.getAdjustments().get(0);
    verifyInvoiceLineAdjustmentCommon(invoiceAdjustment, lineAdjustment);
    assertThat(lineAdjustment.getValue(), is(expectedAdjValue));
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) Adjustment(org.folio.rest.jaxrs.model.Adjustment) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoiceLinesProratedAdjustmentsTest method testUpdateLineForInvoiceWithOneAdj.

@ParameterizedTest
@CsvSource({ "BY_AMOUNT, AMOUNT", "BY_AMOUNT, PERCENTAGE", "BY_LINE, AMOUNT", "BY_LINE, PERCENTAGE", "BY_QUANTITY, AMOUNT", "BY_QUANTITY, PERCENTAGE" })
public void testUpdateLineForInvoiceWithOneAdj(Adjustment.Prorate prorate, Adjustment.Type type) {
    logger.info("=== Updating line for invoice with only one line and one prorated adjustment ===");
    // Prepare data "from storage"
    Invoice invoice = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withId(randomUUID().toString());
    Adjustment invoiceAdjustment = createAdjustment(prorate, type, 15d);
    invoice.withAdjustments(Collections.singletonList(invoiceAdjustment));
    addMockEntry(INVOICES, invoice);
    InvoiceLine lineData = getMockInvoiceLine(invoice.getId()).withSubTotal(15d).withQuantity(5);
    lineData.setAdjustments(Collections.singletonList(createAdjustment(Adjustment.Prorate.NOT_PRORATED, type, 15d).withAdjustmentId(invoiceAdjustment.getId())));
    addMockEntry(INVOICE_LINES, lineData);
    // Prepare request body
    InvoiceLine invoiceLineBody = copyObject(lineData).withSubTotal(25d).withQuantity(10);
    String lineId = invoiceLineBody.getId();
    // Send update request
    verifySuccessPut(String.format(INVOICE_LINE_ID_PATH, lineId), invoiceLineBody);
    // Verification
    assertThat(getInvoiceLineUpdates(), Matchers.hasSize(1));
    assertThat(getInvoiceUpdates(), Matchers.hasSize(1));
    InvoiceLine lineToStorage = getLineToStorageById(lineId);
    assertThat(lineToStorage.getAdjustments(), hasSize(1));
    /*
     * Calculated adjustment value depends of type:
     * "Amount" - this is the same as adjustment value
     * "Percentage" - this is the percentage of subTotal i.e. 15% of 25$ = 3.75$
     */
    double expectedAdjTotal = (type == Adjustment.Type.AMOUNT) ? 15d : 3.75d;
    double expectedAdjValue = expectedAdjTotal;
    assertThat(lineToStorage.getAdjustments(), hasSize(1));
    assertThat(lineToStorage.getAdjustmentsTotal(), is(expectedAdjTotal));
    Adjustment lineAdjustment = lineToStorage.getAdjustments().get(0);
    verifyInvoiceLineAdjustmentCommon(invoiceAdjustment, lineAdjustment);
    assertThat(lineAdjustment.getValue(), is(expectedAdjValue));
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) Adjustment(org.folio.rest.jaxrs.model.Adjustment) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoiceLinesProratedAdjustmentsTest method testDeleteLineForInvoiceWithOneAdj.

@ParameterizedTest
@CsvSource({ "BY_AMOUNT, AMOUNT", "BY_AMOUNT, PERCENTAGE", "BY_LINE, AMOUNT", "BY_LINE, PERCENTAGE", "BY_QUANTITY, AMOUNT", "BY_QUANTITY, PERCENTAGE" })
public void testDeleteLineForInvoiceWithOneAdj(Adjustment.Prorate prorate, Adjustment.Type type) {
    logger.info("=== Deleting line for invoice with 2 lines and one prorated adjustment ===");
    // Prepare data "from storage"
    Invoice invoice = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withId(randomUUID().toString());
    Adjustment invoiceAdjustment = createAdjustment(prorate, type, 15d);
    invoice.withAdjustments(Collections.singletonList(invoiceAdjustment));
    addMockEntry(INVOICES, invoice);
    InvoiceLine line1 = getMockInvoiceLine(invoice.getId()).withSubTotal(25d).withQuantity(10);
    addMockEntry(INVOICE_LINES, line1);
    InvoiceLine line2 = getMockInvoiceLine(invoice.getId()).withSubTotal(15d).withQuantity(5);
    addMockEntry(INVOICE_LINES, line2);
    // Send update request
    verifyDeleteResponse(String.format(INVOICE_LINE_ID_PATH, line2.getId()), "", 204);
    // Verification
    assertThat(getInvoiceLineUpdates(), Matchers.hasSize(1));
    assertThat(getInvoiceUpdates(), Matchers.hasSize(1));
    InvoiceLine lineToStorage = getLineToStorageById(line1.getId());
    assertThat(lineToStorage.getAdjustments(), hasSize(1));
    /*
     * Calculated adjustment value depends of type:
     * "Amount" - this is the same as adjustment value
     * "Percentage" - this is the percentage of subTotal i.e. 15% of 25$ = 3.75$
     */
    double expectedAdjTotal = (type == Adjustment.Type.AMOUNT) ? 15d : 3.75d;
    double expectedAdjValue = expectedAdjTotal;
    assertThat(lineToStorage.getAdjustments(), hasSize(1));
    assertThat(lineToStorage.getAdjustmentsTotal(), is(expectedAdjTotal));
    Adjustment lineAdjustment = lineToStorage.getAdjustments().get(0);
    verifyInvoiceLineAdjustmentCommon(invoiceAdjustment, lineAdjustment);
    assertThat(lineAdjustment.getValue(), is(expectedAdjValue));
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) Adjustment(org.folio.rest.jaxrs.model.Adjustment) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Invoice (org.folio.rest.jaxrs.model.Invoice)128 Test (org.junit.jupiter.api.Test)99 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)87 Matchers.containsString (org.hamcrest.Matchers.containsString)56 Adjustment (org.folio.rest.jaxrs.model.Adjustment)47 JsonObject (io.vertx.core.json.JsonObject)43 Headers (io.restassured.http.Headers)40 Errors (org.folio.rest.jaxrs.model.Errors)37 Error (org.folio.rest.jaxrs.model.Error)32 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)29 InvoiceLineCollection (org.folio.rest.jaxrs.model.InvoiceLineCollection)29 List (java.util.List)28 Voucher (org.folio.rest.jaxrs.model.Voucher)28 RequestContext (org.folio.rest.core.models.RequestContext)27 HashMap (java.util.HashMap)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Vertx (io.vertx.core.Vertx)23 Fund (org.folio.rest.acq.model.finance.Fund)23 ArrayList (java.util.ArrayList)22 Collections (java.util.Collections)21