Search in sources :

Example 1 with PurchaseCandidatesGroupBuilder

use of de.metas.purchasecandidate.PurchaseCandidatesGroup.PurchaseCandidatesGroupBuilder in project metasfresh-webui-api by metasfresh.

the class PurchaseRow method changeRow.

private void changeRow(@NonNull final PurchaseRowChangeRequest request) {
    assertRowType(PurchaseRowType.LINE);
    assertRowEditable();
    // 
    final PurchaseCandidatesGroup candidatesGroup = getPurchaseCandidatesGroup();
    final PurchaseCandidatesGroupBuilder newCandidatesGroup = candidatesGroup.toBuilder();
    boolean hasChanges = false;
    // 
    // QtyToPurchase
    final Quantity qtyToPurchase = request.getQtyToPurchase(this::getCurrentUOM);
    boolean qtyToPurchaseChanged = false;
    if (qtyToPurchase != null && !Objects.equals(candidatesGroup.getQtyToPurchase(), qtyToPurchase)) {
        newCandidatesGroup.qtyToPurchase(qtyToPurchase);
        qtyToPurchaseChanged = true;
        hasChanges = true;
    }
    // 
    // PurchaseDatePromised
    final ZonedDateTime purchaseDatePromised = request.getPurchaseDatePromised();
    if (purchaseDatePromised != null) {
        newCandidatesGroup.purchaseDatePromised(purchaseDatePromised);
        hasChanges = true;
    }
    // Recompute Profit Info
    if (qtyToPurchaseChanged) {
        final PurchaseProfitInfo profitInfo = purchaseProfitInfoService.calculateNoFail(PurchaseProfitInfoRequest.builder().salesOrderAndLineIds(candidatesGroup.getSalesOrderAndLineIds()).qtyToPurchase(qtyToPurchase).vendorProductInfo(candidatesGroup.getVendorProductInfo()).build());
        newCandidatesGroup.profitInfoOrNull(profitInfo);
        hasChanges = true;
    }
    // Stop here if there were no changes
    if (!hasChanges) {
        return;
    }
    // 
    setPurchaseCandidatesGroup(newCandidatesGroup.build());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) PurchaseCandidatesGroupBuilder(de.metas.purchasecandidate.PurchaseCandidatesGroup.PurchaseCandidatesGroupBuilder) PurchaseCandidatesGroup(de.metas.purchasecandidate.PurchaseCandidatesGroup) Quantity(de.metas.quantity.Quantity) PurchaseProfitInfo(de.metas.purchasecandidate.grossprofit.PurchaseProfitInfo)

Aggregations

PurchaseCandidatesGroup (de.metas.purchasecandidate.PurchaseCandidatesGroup)1 PurchaseCandidatesGroupBuilder (de.metas.purchasecandidate.PurchaseCandidatesGroup.PurchaseCandidatesGroupBuilder)1 PurchaseProfitInfo (de.metas.purchasecandidate.grossprofit.PurchaseProfitInfo)1 Quantity (de.metas.quantity.Quantity)1 ZonedDateTime (java.time.ZonedDateTime)1