Skip to content

Commit

Permalink
#377 refactoring, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-rc committed Apr 10, 2018
1 parent d0d9e66 commit 0a467ee
Showing 1 changed file with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.metas.material.dispo.commons.repository.AvailableToPromiseMultiQuery;
import de.metas.material.dispo.commons.repository.AvailableToPromiseQuery;
import de.metas.material.dispo.commons.repository.AvailableToPromiseQuery.AvailableToPromiseQueryBuilder;
import de.metas.material.dispo.commons.repository.AvailableToPromiseQueryBL;
import de.metas.material.dispo.commons.repository.AvailableToPromiseRepository;
import de.metas.product.IProductBL;
import de.metas.purchasecandidate.PurchaseCandidate;
Expand Down Expand Up @@ -58,6 +59,13 @@
@Service
public class PurchaseRowFactory
{
private final AvailableToPromiseRepository availableToPromiseRepository;

public PurchaseRowFactory(@NonNull AvailableToPromiseRepository availableToPromiseRepository)
{
this.availableToPromiseRepository = availableToPromiseRepository;
}

@Builder(builderMethodName = "rowFromPurchaseCandidateBuilder", builderClassName = "RowFromPurchaseCandidateBuilder")
private PurchaseRow buildRowFromPurchaseCandidate(@NonNull final PurchaseCandidate purchaseCandidate,
@Nullable final VendorProductInfo vendorProductInfo, @NotNull final Date datePromised)
Expand Down Expand Up @@ -86,38 +94,53 @@ private PurchaseRow buildRowFromPurchaseCandidate(@NonNull final PurchaseCandida
return PurchaseRow.builder()
.rowId(PurchaseRowId.lineId(purchaseCandidate.getSalesOrderLineId(), bpartnerId,
processedPurchaseCandidateId))
.salesOrderId(purchaseCandidate.getSalesOrderId()).rowType(PurchaseRowType.LINE).product(product)
.uomOrAvailablility(uom).qtyToPurchase(purchaseCandidate.getQtyToPurchase())
.purchasedQty(purchaseCandidate.getPurchasedQty()).datePromised(datePromised)
.vendorBPartner(vendorBPartner).purchaseCandidateId(purchaseCandidate.getPurchaseCandidateId())
.orgId(purchaseCandidate.getOrgId()).warehouseId(purchaseCandidate.getWarehouseId())
.readonly(purchaseCandidate.isProcessedOrLocked()).build();
.salesOrderId(purchaseCandidate.getSalesOrderId())
.rowType(PurchaseRowType.LINE).product(product)
.uomOrAvailablility(uom)
.qtyToPurchase(purchaseCandidate.getQtyToPurchase())
.purchasedQty(purchaseCandidate.getPurchasedQty())
.datePromised(datePromised)
.vendorBPartner(vendorBPartner)
.purchaseCandidateId(purchaseCandidate.getPurchaseCandidateId())
.orgId(purchaseCandidate.getOrgId())
.warehouseId(purchaseCandidate.getWarehouseId())
.readonly(purchaseCandidate.isProcessedOrLocked())
.build();
}

public PurchaseRow createGroupRow(final I_C_OrderLine salesOrderLine, final List<PurchaseRow> rows)
{


final JSONLookupValue product = createProductLookupValue(salesOrderLine.getM_Product_ID());
final BigDecimal qtyToDeliver = salesOrderLine.getQtyOrdered().subtract(salesOrderLine.getQtyDelivered());
final String uom = createUOMLookupValueForProductId(product.getKeyAsInt());

final AvailableToPromiseQueryBuilder atpQueryBuilder = AvailableToPromiseQuery.builder();

atpQueryBuilder.productId(salesOrderLine.getM_Product_ID());
atpQueryBuilder.date(salesOrderLine.getDatePromised());
atpQueryBuilder.date(salesOrderLine.getC_Order().getPreparationDate());

AvailableToPromiseQueryBL.addStorageAttributeKeysToQueryBuilder(atpQueryBuilder);

final BigDecimal qtyAvailable = new AvailableToPromiseRepository()
final BigDecimal qtyAvailableToPromise = availableToPromiseRepository
.retrieveAvailableStockQtySum(AvailableToPromiseMultiQuery.of(atpQueryBuilder.build()));

final PurchaseRow groupRow = PurchaseRow.builder()
.rowId(PurchaseRowId.groupId(salesOrderLine.getC_OrderLine_ID()))
.salesOrderId(salesOrderLine.getC_Order_ID()).rowType(PurchaseRowType.GROUP).product(product)
.uomOrAvailablility(uom).qtyAvailable(qtyAvailable).qtyToDeliver(qtyToDeliver)
.datePromised(salesOrderLine.getDatePromised()).orgId(salesOrderLine.getAD_Org_ID())
.warehouseId(salesOrderLine.getM_Warehouse_ID()).includedRows(rows).readonly(true) // grouping lines are
// always readonly
.salesOrderId(salesOrderLine.getC_Order_ID())
.rowType(PurchaseRowType.GROUP).product(product)
.uomOrAvailablility(uom)
.qtyAvailableToPromise(qtyAvailableToPromise)
.qtyToDeliver(qtyToDeliver)
.datePromised(salesOrderLine.getDatePromised())
.orgId(salesOrderLine.getAD_Org_ID())
.warehouseId(salesOrderLine.getM_Warehouse_ID())
.includedRows(rows).readonly(true) // grouping lines are always readonly
.build();
return groupRow;
}


@Builder(builderMethodName = "rowFromAvailabilityResultBuilder", builderClassName = "RowFromAvailabilityResultBuilder")
private PurchaseRow buildRowFromFromAvailabilityResult(@NonNull PurchaseRow parentRow,
Expand Down

0 comments on commit 0a467ee

Please sign in to comment.