Search in sources :

Example 6 with PricingConditionsBreak

use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.

the class ProductPricingConditionsViewFactory method createPricingContext.

private IPricingContext createPricingContext(final BasePricingSystemPriceCalculatorRequest request) {
    final IPricingBL pricingBL = Services.get(IPricingBL.class);
    final PricingConditionsBreak pricingConditionsBreak = request.getPricingConditionsBreak();
    final IEditablePricingContext pricingCtx = pricingBL.createPricingContext();
    final ProductId productId = pricingConditionsBreak.getMatchCriteria().getProductId();
    pricingCtx.setProductId(productId);
    pricingCtx.setQty(BigDecimal.ONE);
    pricingCtx.setBPartnerId(request.getBpartnerId());
    pricingCtx.setSOTrx(SOTrx.ofBoolean(request.isSOTrx()));
    return pricingCtx;
}
Also used : PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak) IPricingBL(de.metas.pricing.service.IPricingBL) IEditablePricingContext(de.metas.pricing.IEditablePricingContext) ProductId(de.metas.product.ProductId)

Example 7 with PricingConditionsBreak

use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.

the class PricingConditionsRowReducers method applyRequestTo.

private PricingConditionsBreak applyRequestTo(@NonNull final PricingConditionsRowChangeRequest request, @NonNull final PricingConditionsBreak rowPricingConditionsBreak) {
    final PricingConditionsBreak pricingConditionsBreakEffective = coalesce(request.getPricingConditionsBreak(), rowPricingConditionsBreak);
    final PricingConditionsBreakBuilder builder = pricingConditionsBreakEffective.toBuilder();
    // Discount%
    if (request.getDiscount() != null) {
        builder.discount(request.getDiscount());
        builder.hasChanges(true);
    }
    // 
    // Payment Term
    final boolean paymentTermChangeRequested = request.getPaymentTermId() != null;
    final boolean paymentDiscountChangeRequested = request.getPaymentDiscount() != null;
    if (paymentTermChangeRequested || paymentDiscountChangeRequested) {
        final PaymentTermId paymentTermIdOrNull;
        if (paymentTermChangeRequested) {
            paymentTermIdOrNull = request.getPaymentTermId().orElse(null);
            builder.paymentTermIdOrNull(paymentTermIdOrNull);
        } else {
            // if no payment term change was requested, we use the old paymentTermId to get derivedPaymentTermIdOrNull.
            paymentTermIdOrNull = pricingConditionsBreakEffective.getPaymentTermIdOrNull();
        }
        final Percent paymentDiscountOrNull = paymentDiscountChangeRequested ? request.getPaymentDiscount().orElse(null) : null;
        builder.paymentDiscountOverrideOrNull(paymentDiscountOrNull);
        final PaymentTermService paymentTermService = SpringContextHolder.instance.getBean(PaymentTermService.class);
        final PaymentTermId derivedPaymentTermIdOrNull = paymentTermService.getOrCreateDerivedPaymentTerm(paymentTermIdOrNull, paymentDiscountOrNull);
        builder.derivedPaymentTermIdOrNull(derivedPaymentTermIdOrNull);
    }
    // Price
    if (request.getPriceChange() != null) {
        final PriceSpecification price = applyPriceChangeTo(request.getPriceChange(), rowPricingConditionsBreak.getPriceSpecification());
        builder.priceSpecification(price);
    }
    PricingConditionsBreak newPricingConditionsBreak = builder.build();
    if (!Objects.equals(newPricingConditionsBreak, pricingConditionsBreakEffective)) {
        newPricingConditionsBreak = newPricingConditionsBreak.toBuilder().hasChanges(true).build();
    }
    return newPricingConditionsBreak;
}
Also used : PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak) PaymentTermId(de.metas.payment.paymentterm.PaymentTermId) Percent(de.metas.util.lang.Percent) PriceSpecification(de.metas.pricing.conditions.PriceSpecification) PaymentTermService(de.metas.payment.paymentterm.PaymentTermService) PricingConditionsBreakBuilder(de.metas.pricing.conditions.PricingConditionsBreak.PricingConditionsBreakBuilder)

Example 8 with PricingConditionsBreak

use of de.metas.pricing.conditions.PricingConditionsBreak in project metasfresh-webui-api by metasfresh.

the class PricingConditionsView method updateSalesOrderLineIfPossible.

public void updateSalesOrderLineIfPossible() {
    if (!hasEditableRow()) {
        return;
    }
    final PricingConditionsRow editableRow = getEditableRow();
    final BigDecimal basePriceAmt = editableRow.getBasePriceAmt();
    final CurrencyId currencyId = editableRow.getCurrencyId();
    final Money basePriceFromRow = Money.ofOrNull(basePriceAmt, currencyId);
    final PricingConditionsBreak pricingConditionsBreak = editableRow.getPricingConditionsBreak();
    updateOrderLineRecord(pricingConditionsBreak, basePriceFromRow);
}
Also used : Money(de.metas.money.Money) PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak) BigDecimal(java.math.BigDecimal) CurrencyId(de.metas.money.CurrencyId)

Aggregations

PricingConditionsBreak (de.metas.pricing.conditions.PricingConditionsBreak)8 Money (de.metas.money.Money)2 PaymentTermId (de.metas.payment.paymentterm.PaymentTermId)2 PriceSpecification (de.metas.pricing.conditions.PriceSpecification)2 PricingConditionsBreakId (de.metas.pricing.conditions.PricingConditionsBreakId)2 PricingConditionsId (de.metas.pricing.conditions.PricingConditionsId)2 Percent (de.metas.util.lang.Percent)2 BPartnerId (de.metas.bpartner.BPartnerId)1 SOTrx (de.metas.lang.SOTrx)1 CurrencyId (de.metas.money.CurrencyId)1 PaymentTermService (de.metas.payment.paymentterm.PaymentTermService)1 IEditablePricingContext (de.metas.pricing.IEditablePricingContext)1 PricingConditionsBreakBuilder (de.metas.pricing.conditions.PricingConditionsBreak.PricingConditionsBreakBuilder)1 IPricingBL (de.metas.pricing.service.IPricingBL)1 ProductId (de.metas.product.ProductId)1 BigDecimal (java.math.BigDecimal)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1