From e7240e1628a8b33e98122cafcb39127b0f1434b1 Mon Sep 17 00:00:00 2001 From: metas-rc Date: Fri, 20 Dec 2019 16:38:13 +0200 Subject: [PATCH] #5800 Support PaymentRule = DirectDebit in OLCand EndPoint https://github.com/metasfresh/metasfresh/issues/5800 --- .../impl/MasterdataProvider.java | 5 + ...OrderCandidatesRestControllerImplTest.java | 187 ++++++++++++++++++ .../request/JSONPaymentRule.java | 6 +- 3 files changed, 196 insertions(+), 2 deletions(-) diff --git a/de.metas.business.rest-api-impl/src/main/java/de/metas/rest_api/ordercandidates/impl/MasterdataProvider.java b/de.metas.business.rest-api-impl/src/main/java/de/metas/rest_api/ordercandidates/impl/MasterdataProvider.java index b671bcaff00..3707efe0a1a 100644 --- a/de.metas.business.rest-api-impl/src/main/java/de/metas/rest_api/ordercandidates/impl/MasterdataProvider.java +++ b/de.metas.business.rest-api-impl/src/main/java/de/metas/rest_api/ordercandidates/impl/MasterdataProvider.java @@ -352,6 +352,11 @@ public PaymentRule getPaymentRule(final JsonOLCandCreateRequest request) return PaymentRule.OnCredit; } + if (JSONPaymentRule.DirectDebit.equals(jsonPaymentRule)) + { + return PaymentRule.DirectDebit; + } + throw MissingResourceException.builder() .resourceName("paymentRule") .resourceIdentifier(jsonPaymentRule.getCode()) diff --git a/de.metas.business.rest-api-impl/src/test/java/de/metas/rest_api/ordercandidates/impl/OrderCandidatesRestControllerImplTest.java b/de.metas.business.rest-api-impl/src/test/java/de/metas/rest_api/ordercandidates/impl/OrderCandidatesRestControllerImplTest.java index 50da7a5b108..34aa7c75390 100644 --- a/de.metas.business.rest-api-impl/src/test/java/de/metas/rest_api/ordercandidates/impl/OrderCandidatesRestControllerImplTest.java +++ b/de.metas.business.rest-api-impl/src/test/java/de/metas/rest_api/ordercandidates/impl/OrderCandidatesRestControllerImplTest.java @@ -488,6 +488,84 @@ public void test_CreateProductPrice_WarehouseDestId() assertThat(olCand.getWarehouseDestId()).isEqualTo(testWarehouseDestId.getRepoId()); } + + @Test + public void test_CreateProductPrice_WarehouseDestId_DirectDebit() + { + // + // Masterdata: pricing + final TaxCategoryId taxCategoryId = testMasterdata.createTaxCategory(); + final PricingSystemId pricingSystemId = testMasterdata.createPricingSystem(); + final PriceListId priceListId = testMasterdata.createSalesPriceList(pricingSystemId, countryId_DE, currencyId_EUR, taxCategoryId); + testMasterdata.createPriceListVersion(priceListId, LocalDate.of(2019, Month.SEPTEMBER, 1)); + testMasterdata.createPricingRules(); + + // + // Masterdata: BPartner & Location + testMasterdata.prepareBPartnerAndLocation() + .bpValue("bpCode") + .salesPricingSystemId(pricingSystemId) + .countryId(countryId_DE) + .gln(GLN.ofString("gln1")) + .build(); + + // + // Masterdata: Warehouse + final WarehouseId testWarehouseDestId = testMasterdata.createWarehouse("testWarehouseDest"); + + startInterceptors(); + + final JsonOLCandCreateBulkRequest request = JsonOLCandCreateBulkRequest.of(JsonOLCandCreateRequest.builder() + .dataSource("int-" + DATA_SOURCE_INTERNALNAME) + .dataDest("int-" + DATA_DEST_INVOICECANDIDATE) + .dateOrdered(LocalDate.of(2019, Month.SEPTEMBER, 10)) + .dateRequired(LocalDate.of(2019, Month.SEPTEMBER, 15)) + .qty(new BigDecimal("66")) + .externalHeaderId("externalHeaderId") + .externalLineId("externalLineId") + .poReference("poRef") + .product(JsonProductInfo.builder() + .code("productCode") + .name("productName") + .type(Type.ITEM) + .uomCode(UOM_CODE) + .priceStd(new BigDecimal("13.24")) + .syncAdvise(SyncAdvise.JUST_CREATE_IF_NOT_EXISTS) + .build()) + .bpartner(JsonRequestBPartnerLocationAndContact.builder() + .bpartner(JsonRequestBPartner.builder() + .code("bpCode") + .build()) + .location(JsonRequestLocation.builder() + .gln("gln1") + .build()) + .build()) + .shipper("val-DPD") + .salesPartnerCode("SalesRep") + .paymentRule(JSONPaymentRule.DirectDebit) + .orderDocType(OrderDocType.PrepayOrder) + .shipper("val-DPD") + .warehouseDestCode("testWarehouseDest") + .invoiceDocType(JsonDocTypeInfo.builder() + .docBaseType("ARI") + .docSubType("KV") + .build()) + .build()); + + final JsonOLCandCreateBulkResponse response = orderCandidatesRestControllerImpl + .createOrderLineCandidates(request) + .getBody(); + + final List olCands = response.getResult(); + assertThat(olCands).hasSize(1); + + final JsonOLCand olCand = olCands.get(0); + System.out.println(olCand); + + assertThat(olCand.getPrice()).isEqualByComparingTo(new BigDecimal("13.24")); + assertThat(olCand.getWarehouseDestId()).isEqualTo(testWarehouseDestId.getRepoId()); + } + @Test public void test_sameBPartner_DifferentLocations() { @@ -682,6 +760,115 @@ public void test_no_location_specified() .contains(tuple(dropShipBpartnerAndLocation.getBpartnerId().getRepoId(), expectedDropShipLocation.getRepoId())); } + + @Test + public void test_no_location_specified_DirectDebit() + { + // + // Masterdata: pricing + final TaxCategoryId taxCategoryId = testMasterdata.createTaxCategory(); + final PricingSystemId pricingSystemId = testMasterdata.createPricingSystem(); + final PriceListId priceListId = testMasterdata.createSalesPriceList(pricingSystemId, countryId_DE, currencyId_EUR, taxCategoryId); + testMasterdata.createPriceListVersion(priceListId, LocalDate.of(2019, Month.SEPTEMBER, 1)); + testMasterdata.createPricingRules(); + + // + // Masterdata: BPartner & Location + final BPartnerLocationId bpartnerAndLocation = testMasterdata.prepareBPartnerAndLocation() + .bpValue("mainPartner") + .salesPricingSystemId(pricingSystemId) + .countryId(countryId_DE) + .build(); + + final BPartnerLocationId billBpartnerAndLocation = testMasterdata.prepareBPartnerAndLocation() + .bpValue("billPartner") + .salesPricingSystemId(pricingSystemId) + .countryId(countryId_DE) + .build(); + + final BPartnerLocationId dropShipBpartnerAndLocation = testMasterdata.prepareBPartnerAndLocation() + .bpValue("droptShipPartner") + .salesPricingSystemId(pricingSystemId) + .gln(GLN.ofString("redHerring!")) + .countryId(countryId_DE) + .build(); + final BPartnerLocationId expectedDropShipLocation = testMasterdata.prepareBPartnerLocation().bpartnerId(dropShipBpartnerAndLocation.getBpartnerId()) + .countryId(countryId_DE) + .gln(GLN.ofString("expectedDropShipLocation")) + .build(); + + startInterceptors(); + + final JsonOLCandCreateBulkRequest request = JsonOLCandCreateBulkRequest.of(JsonOLCandCreateRequest.builder() + .dataSource("int-" + DATA_SOURCE_INTERNALNAME) + .dataDest("int-" +DATA_DEST_INVOICECANDIDATE) + .dateOrdered(LocalDate.of(2019, Month.SEPTEMBER, 10)) + .dateRequired(LocalDate.of(2019, Month.SEPTEMBER, 15)) + .qty(new BigDecimal("66")) + .externalHeaderId("externalHeaderId") + .externalLineId("externalLineId") + .poReference("poRef") + .shipper("val-DPD") + .salesPartnerCode("SalesRep") + .paymentRule(JSONPaymentRule.DirectDebit) + .orderDocType(OrderDocType.PrepayOrder) + .shipper("val-DPD") + + + .product(JsonProductInfo.builder() + .code("productCode") + .name("productName") + .type(Type.ITEM) + .uomCode(UOM_CODE) + .priceStd(new BigDecimal("13.24")) + .syncAdvise(SyncAdvise.JUST_CREATE_IF_NOT_EXISTS) + .build()) + .bpartner(JsonRequestBPartnerLocationAndContact.builder() + .bpartner(JsonRequestBPartner.builder() + .code("mainPartner") + .build()) // no location specified! + .build()) + .billBPartner(JsonRequestBPartnerLocationAndContact.builder() + .bpartner(JsonRequestBPartner.builder() + .code("billPartner") + .build()) // again, no location specified! + .build()) + .dropShipBPartner(JsonRequestBPartnerLocationAndContact.builder() + .bpartner(JsonRequestBPartner.builder() + .code("droptShipPartner") + .build()) + .location(JsonRequestLocation.builder() + .gln("expectedDropShipLocation") + .build()) + .build()) + + .build()); + + final JsonOLCandCreateBulkResponse response = orderCandidatesRestControllerImpl + .createOrderLineCandidates(request) + .getBody(); + + final List olCands = response.getResult(); + assertThat(olCands).hasSize(1); + final JsonOLCand olCand = olCands.get(0); + + // assert That the OLCand record has the C_BPartner_Location_ID that was not specified in JSON, but looked up + final List olCandRecords = POJOLookupMap.get().getRecords(I_C_OLCand.class); + assertThat(olCandRecords).hasSize(1) + .extracting(COLUMNNAME_C_OLCand_ID) + .contains(olCand.getId()); + + assertThat(olCandRecords).extracting(COLUMNNAME_C_BPartner_ID, COLUMNNAME_C_BPartner_Location_ID) + .contains(tuple(bpartnerAndLocation.getBpartnerId().getRepoId(), bpartnerAndLocation.getRepoId())); + + assertThat(olCandRecords).extracting(COLUMNNAME_Bill_BPartner_ID, COLUMNNAME_Bill_Location_ID) + .contains(tuple(billBpartnerAndLocation.getBpartnerId().getRepoId(), billBpartnerAndLocation.getRepoId())); + + assertThat(olCandRecords).extracting(COLUMNNAME_DropShip_BPartner_ID, COLUMNNAME_DropShip_Location_ID) + .contains(tuple(dropShipBpartnerAndLocation.getBpartnerId().getRepoId(), expectedDropShipLocation.getRepoId())); + } + + private static class DummyOLCandWithUOMForTUsCapacityProvider implements IOLCandWithUOMForTUsCapacityProvider { @Override diff --git a/de.metas.business.rest-api/src/main/java/de/metas/rest_api/ordercandidates/request/JSONPaymentRule.java b/de.metas.business.rest-api/src/main/java/de/metas/rest_api/ordercandidates/request/JSONPaymentRule.java index a4aa9668694..9cec0ad55be 100644 --- a/de.metas.business.rest-api/src/main/java/de/metas/rest_api/ordercandidates/request/JSONPaymentRule.java +++ b/de.metas.business.rest-api/src/main/java/de/metas/rest_api/ordercandidates/request/JSONPaymentRule.java @@ -32,7 +32,10 @@ public enum JSONPaymentRule Paypal("L"), @ApiEnum("Specifies that the order will have paymentRule = On Credit") - OnCredit("P"); + OnCredit("P"), + + @ApiEnum("Specifies that the order will have paymentRule = Direct Debit") + DirectDebit("D"); @Getter private final String code; @@ -42,5 +45,4 @@ public enum JSONPaymentRule this.code = code; } - }