Skip to content

Commit

Permalink
Export PP_Orders with extended infos (#12988)
Browse files Browse the repository at this point in the history
* Export PPOrder sqaushed (#12985)

* Export PPOrder & pass it to FTP server

* export PPOrder refactoring

* Cucumber testing - minor refactor

Co-authored-by: av-ps <alexandra.vezendan@pevesoft.ro>

* small refactor

* Minor refactor

* refs: #12931

* refs: #12931

* Fix cucumber test

Co-authored-by: cp-ps <77785468+cp-ps@users.noreply.github.com>
Co-authored-by: cp-ps <cp-ps@pevesoft.ro>
Co-authored-by: fp-ps <fp-ps@pevesoft.ro>
  • Loading branch information
4 people committed May 23, 2022
1 parent 5acfccc commit 10adbd3
Show file tree
Hide file tree
Showing 108 changed files with 7,231 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@

package de.metas.location;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import de.metas.util.Check;
import lombok.Builder;
import lombok.Value;

@Value
@JsonDeserialize(builder = CountryCode.CountryCodeBuilder.class)
public class CountryCode
{
@JsonProperty("alpha2")
String alpha2;

@JsonProperty("alpha3")
String alpha3;

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.metas.util.Services;
import lombok.NonNull;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_M_PriceList_Version;
import org.compiere.model.I_M_ProductPrice;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -93,20 +94,38 @@ public PriceListVersionId getPriceListVersionId(final PriceListId priceListId, f
return priceListsRepo.retrievePriceListVersionId(priceListId, date);
}

public I_M_PriceList_Version getPriceListVersionOrNull(final PriceListId priceListId, final ZonedDateTime date, final Boolean processedPLVFiltering)
{
return priceListsRepo.retrievePriceListVersionOrNull(priceListId, date, processedPLVFiltering);
}

public ImmutableList<I_M_ProductPrice> getProductPrices(PriceListVersionId priceListVersionId)
{
return priceListsRepo.retrieveProductPrices(priceListVersionId)
.collect(ImmutableList.toImmutableList());
}

public ImmutableMap<ProductId, String> getProductValues(ImmutableSet<ProductId> productIds)
@NonNull
public ImmutableList<I_M_ProductPrice> getProductPricesByPLVAndProduct(@NonNull final PriceListVersionId priceListVersionId, @NonNull final ProductId productId)
{
return priceListsRepo.retrieveProductPrices(priceListVersionId, productId);
}

@NonNull
public ImmutableMap<ProductId, String> getProductValues(final ImmutableSet<ProductId> productIds)
{
return productsService.getProductValues(productIds);
}

@NonNull
public String getProductValue(@NonNull final ProductId productId)
{
return productsService.getProductValue(productId);
}

// TODO move this method to de.metas.bpartner.service.IBPartnerDAO since it has nothing to do with price list
// TODO: IdentifierString must also be moved to the module containing IBPartnerDAO
public Optional<BPartnerId> getBPartnerId(final IdentifierString bpartnerIdentifier, OrgId orgId)
public Optional<BPartnerId> getBPartnerId(final IdentifierString bpartnerIdentifier, final OrgId orgId)
{
final BPartnerQuery query = createBPartnerQuery(bpartnerIdentifier,orgId);
return bpartnersRepo.retrieveBPartnerIdBy(query);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package de.metas.rest_api.bpartner_pricelist.command;

import java.time.LocalDate;

import de.metas.common.util.time.SystemTime;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_M_PriceList;
import org.compiere.model.I_M_ProductPrice;
import org.compiere.util.TimeUtil;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

import de.metas.bpartner.BPartnerId;
import de.metas.common.util.time.SystemTime;
import de.metas.currency.CurrencyCode;
import de.metas.lang.SOTrx;
import de.metas.location.CountryId;
Expand All @@ -30,6 +22,12 @@
import lombok.Builder;
import lombok.NonNull;
import lombok.ToString;
import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_M_PriceList;
import org.compiere.model.I_M_ProductPrice;
import org.compiere.util.TimeUtil;

import java.time.LocalDate;

/*
* #%L
Expand Down Expand Up @@ -127,17 +125,11 @@ private JsonResponsePriceList execute0()
{
countryId = servicesFacade.getCountryIdByCountryCode(countryCode);

bpartnerId = servicesFacade.getBPartnerId(bpartnerIdentifier, null).orElse(null);
if (bpartnerId == null)
{
throw new AdempiereException("No BPartner found for " + bpartnerIdentifier);
}
bpartnerId = servicesFacade.getBPartnerId(bpartnerIdentifier, null)
.orElseThrow(() -> new AdempiereException("No BPartner found for " + bpartnerIdentifier));

pricingSystemId = servicesFacade.getPricingSystemId(bpartnerId, soTrx).orElse(null);
if (pricingSystemId == null)
{
throw new AdempiereException("No pricing system defined for " + bpartnerId);
}
pricingSystemId = servicesFacade.getPricingSystemId(bpartnerId, soTrx)
.orElseThrow(() -> new AdempiereException("No pricing system defined for " + bpartnerId));

final PriceListsCollection priceLists = servicesFacade.getPriceListsCollection(pricingSystemId);
final I_M_PriceList priceList = priceLists.getPriceList(countryId, soTrx).orElse(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package de.metas.rest_api.bpartner_pricelist.response;

import java.math.BigDecimal;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;

import de.metas.currency.CurrencyCode;
import de.metas.product.ProductId;
import de.metas.tax.api.TaxCategoryId;
Expand All @@ -13,6 +10,8 @@
import lombok.NonNull;
import lombok.Value;

import java.math.BigDecimal;

/*
* #%L
* de.metas.business.rest-api-impl
Expand All @@ -23,12 +22,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
Expand All @@ -45,13 +44,13 @@ public class JsonResponsePrice
dataType = "java.lang.Integer", //
value = "This translates to `M_Product.M_Product_ID`.")
@NonNull
private ProductId productId;
ProductId productId;

@NonNull
private String productCode;
String productCode;

@NonNull
private BigDecimal price;
BigDecimal price;

@ApiModelProperty( //
allowEmptyValue = false, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class JsonResponsePriceList
{
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Singular
private List<JsonResponsePrice> prices;
List<JsonResponsePrice> prices;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Singular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import de.metas.Profiles;
import de.metas.common.pricing.v2.pricelist.request.JsonRequestPriceListVersionUpsert;
import de.metas.common.pricing.v2.productprice.JsonRequestProductPriceQuery;
import de.metas.common.pricing.v2.productprice.JsonRequestProductPriceUpsert;
import de.metas.common.pricing.v2.productprice.JsonResponseProductPriceQuery;
import de.metas.common.rest_api.v2.JsonResponseUpsert;
import de.metas.util.web.MetasfreshRestAPIConstants;
import io.swagger.annotations.ApiOperation;
Expand All @@ -33,13 +35,17 @@
import io.swagger.annotations.ApiResponses;
import lombok.NonNull;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Nullable;

import static de.metas.common.pricing.v2.constants.SwaggerDocConstants.PRICE_LIST_IDENTIFIER;
import static de.metas.common.pricing.v2.constants.SwaggerDocConstants.PRICE_LIST_VERSION_IDENTIFIER;

Expand Down Expand Up @@ -111,6 +117,32 @@ public ResponseEntity<JsonResponseUpsert> putProductPriceByPriceListIdentifier(

return ResponseEntity.ok().body(responseUpsert);
}

@ApiOperation("Search product prices by a given `JsonProductPriceSearchRequest`")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully processed the request"),
@ApiResponse(code = 401, message = "You are not authorized to consume this resource"),
@ApiResponse(code = 403, message = "Accessing a related resource is forbidden"),
@ApiResponse(code = 422, message = "The request body could not be processed")
})
@PostMapping("{orgCode}/product/search")
public ResponseEntity<?> productPriceSearch(
@PathVariable("orgCode") @Nullable final String orgCode,
@RequestBody @NonNull final JsonRequestProductPriceQuery request)
{
try
{
final JsonResponseProductPriceQuery result = productPriceRestService.productPriceSearch(request, orgCode);

return ResponseEntity.ok(result);
}
catch (final Exception ex)
{
return ResponseEntity
.status(HttpStatus.UNPROCESSABLE_ENTITY)
.body(ex.getMessage());
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import de.metas.common.externalreference.v2.JsonExternalReferenceLookupItem;
import de.metas.common.externalsystem.JsonExternalSystemName;
import de.metas.common.pricing.v2.productprice.JsonRequestProductPrice;
import de.metas.common.pricing.v2.productprice.JsonRequestProductPriceQuery;
import de.metas.common.pricing.v2.productprice.JsonRequestProductPriceUpsert;
import de.metas.common.pricing.v2.productprice.JsonRequestProductPriceUpsertItem;
import de.metas.common.pricing.v2.productprice.JsonResponseProductPriceQuery;
import de.metas.common.pricing.v2.productprice.TaxCategory;
import de.metas.common.rest_api.common.JsonMetasfreshId;
import de.metas.common.rest_api.v2.JsonResponseUpsert;
Expand All @@ -47,6 +49,11 @@
import de.metas.pricing.productprice.ProductPriceRepository;
import de.metas.product.IProductBL;
import de.metas.product.ProductId;
import de.metas.rest_api.bpartner_pricelist.BpartnerPriceListServicesFacade;
import de.metas.rest_api.v2.bpartner.bpartnercomposite.JsonRetrieverService;
import de.metas.rest_api.v2.bpartner.bpartnercomposite.JsonServiceFactory;
import de.metas.rest_api.v2.pricing.command.SearchProductPricesCommand;
import de.metas.rest_api.v2.product.ProductRestService;
import de.metas.tax.api.ITaxBL;
import de.metas.tax.api.TaxCategoryId;
import de.metas.uom.IUOMDAO;
Expand All @@ -60,6 +67,7 @@
import org.compiere.util.Env;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -77,15 +85,24 @@ public class ProductPriceRestService
private final ExternalReferenceRestControllerService externalReferenceRestControllerService;
private final ProductPriceRepository productPriceRepository;
private final PriceListRestService priceListRestService;
private final ProductRestService productRestService;
private final BpartnerPriceListServicesFacade bpartnerPriceListServicesFacade;
private final JsonRetrieverService jsonRetrieverService;

public ProductPriceRestService(
final ExternalReferenceRestControllerService externalReferenceRestControllerService,
final ProductPriceRepository productPriceRepository,
final PriceListRestService priceListRestService)
@NonNull final ExternalReferenceRestControllerService externalReferenceRestControllerService,
@NonNull final ProductPriceRepository productPriceRepository,
@NonNull final PriceListRestService priceListRestService,
@NonNull final ProductRestService productRestService,
@NonNull final BpartnerPriceListServicesFacade bpartnerPriceListServicesFacade,
@NonNull final JsonServiceFactory jsonServiceFactory)
{
this.externalReferenceRestControllerService = externalReferenceRestControllerService;
this.productPriceRepository = productPriceRepository;
this.priceListRestService = priceListRestService;
this.productRestService = productRestService;
this.bpartnerPriceListServicesFacade = bpartnerPriceListServicesFacade;
this.jsonRetrieverService = jsonServiceFactory.createRetriever();
}

@NonNull
Expand All @@ -106,6 +123,21 @@ public JsonResponseUpsert upsertProductPricesForPriceList(
return upsertProductPrices(String.valueOf(priceListVersionId.getRepoId()), request);
}

@NonNull
public JsonResponseProductPriceQuery productPriceSearch(@NonNull final JsonRequestProductPriceQuery request, @Nullable final String orgCode)
{
return SearchProductPricesCommand.builder()
.productRestService(productRestService)
.bpartnerPriceListServicesFacade(bpartnerPriceListServicesFacade)
.jsonRetrieverService(jsonRetrieverService)
.bpartnerIdentifier(ExternalIdentifier.of(request.getBpartnerIdentifier()))
.productIdentifier(ExternalIdentifier.of(request.getProductIdentifier()))
.targetDate(request.getTargetDate())
.orgCode(orgCode)
.build()
.execute();
}

@NonNull
private JsonResponseUpsert upsertProductPricesWithinTrx(
@NonNull final String priceListVersionIdentifier,
Expand All @@ -116,7 +148,7 @@ private JsonResponseUpsert upsertProductPricesWithinTrx(
final List<JsonResponseUpsertItem> responseList =
request.getRequestItems()
.stream()
.map(reqItem -> upsertProductPricesItem(priceListVersionIdentifier, reqItem, syncAdvise))
.map(reqItem -> upsertProductPricesItem(priceListVersionIdentifier, reqItem, syncAdvise))
.collect(Collectors.toList());

return JsonResponseUpsert.builder().responseItems(responseList).build();
Expand Down

0 comments on commit 10adbd3

Please sign in to comment.