Search in sources :

Example 1 with PricingConditionsBreak

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

the class PricingConditionsView_CopyRowToEditable method createChangeRequest.

private PricingConditionsRowChangeRequest createChangeRequest(@NonNull final PricingConditionsRow templateRow) {
    final PricingConditionsBreak templatePricingConditionsBreak = templateRow.getPricingConditionsBreak();
    PriceSpecification price = templatePricingConditionsBreak.getPriceSpecification();
    if (price.isNoPrice()) {
        // In case row does not have a price then use BPartner's pricing system
        final BPartnerId bpartnerId = templateRow.getBpartnerId();
        final SOTrx soTrx = SOTrx.ofBoolean(templateRow.isCustomer());
        price = createBasePricingSystemPrice(bpartnerId, soTrx);
    }
    final Percent discount = templatePricingConditionsBreak.getDiscount();
    final PaymentTermId paymentTermIdOrNull = templatePricingConditionsBreak.getPaymentTermIdOrNull();
    final Percent paymentDiscountOverrideOrNull = templatePricingConditionsBreak.getPaymentDiscountOverrideOrNull();
    return PricingConditionsRowChangeRequest.builder().priceChange(CompletePriceChange.of(price)).discount(discount).paymentTermId(Optional.ofNullable(paymentTermIdOrNull)).paymentDiscount(Optional.ofNullable(paymentDiscountOverrideOrNull)).sourcePricingConditionsBreakId(templatePricingConditionsBreak.getId()).build();
}
Also used : PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak) PaymentTermId(de.metas.payment.paymentterm.PaymentTermId) Percent(de.metas.util.lang.Percent) SOTrx(de.metas.lang.SOTrx) PriceSpecification(de.metas.pricing.conditions.PriceSpecification) BPartnerId(de.metas.bpartner.BPartnerId)

Example 2 with PricingConditionsBreak

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

the class PricingConditionsView_SaveEditableRow method createPricingConditionsBreakChangeRequest.

private static PricingConditionsBreakChangeRequest createPricingConditionsBreakChangeRequest(final PricingConditionsRow row) {
    if (!row.isEditable()) {
        throw new AdempiereException("Saving not editable rows is not allowed").setParameter("row", row);
    }
    final PricingConditionsId pricingConditionsId = row.getPricingConditionsId();
    final PricingConditionsBreak pricingConditionsBreak = row.getPricingConditionsBreak();
    final PricingConditionsBreakId updateFromPricingConditionsBreakId = row.getCopiedFromPricingConditionsBreakId();
    return preparePricingConditionsBreakChangeRequest(pricingConditionsBreak).pricingConditionsId(pricingConditionsId).updateFromPricingConditionsBreakId(updateFromPricingConditionsBreakId).build();
}
Also used : PricingConditionsId(de.metas.pricing.conditions.PricingConditionsId) PricingConditionsBreakId(de.metas.pricing.conditions.PricingConditionsBreakId) PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 3 with PricingConditionsBreak

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

the class PricingConditionsRowReducers method copyAndChange.

public PricingConditionsRow copyAndChange(@NonNull final PricingConditionsRowChangeRequest request, @NonNull final PricingConditionsRow row) {
    row.assertEditable();
    boolean changed = false;
    final PricingConditionsBreak pricingConditionsBreakOld = row.getPricingConditionsBreak();
    final PricingConditionsBreak pricingConditionsBreak = applyRequestTo(request, pricingConditionsBreakOld).toTemporaryPricingConditionsBreakIfPriceRelevantFieldsChanged(pricingConditionsBreakOld);
    if (!Objects.equals(pricingConditionsBreak, pricingConditionsBreakOld)) {
        changed = true;
    }
    // 
    // Copied from ID
    PricingConditionsBreakId copiedFromPricingConditionsBreakId = row.getCopiedFromPricingConditionsBreakId();
    if (!Objects.equals(request.getSourcePricingConditionsBreakId(), copiedFromPricingConditionsBreakId)) {
        copiedFromPricingConditionsBreakId = request.getSourcePricingConditionsBreakId();
        changed = true;
    }
    // 
    if (!changed) {
        return row;
    }
    return row.toBuilder().pricingConditionsBreak(pricingConditionsBreak).copiedFromPricingConditionsBreakId(copiedFromPricingConditionsBreakId).build();
}
Also used : PricingConditionsBreakId(de.metas.pricing.conditions.PricingConditionsBreakId) PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak)

Example 4 with PricingConditionsBreak

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

the class PricingConditionsRowsLoader method createEditablePricingConditionsRowOrNull.

/**
 * On-the-fly create a PricingConditionsRow using this instance's {@link #sourceDocumentLine}.
 */
private PricingConditionsRow createEditablePricingConditionsRowOrNull() {
    if (sourceDocumentLine == null) {
        return null;
    }
    final int discountSchemaId = bpartnerBL.getDiscountSchemaId(sourceDocumentLine.getBpartnerId(), sourceDocumentLine.getSoTrx());
    final PricingConditionsId pricingConditionsId = PricingConditionsId.ofRepoIdOrNull(discountSchemaId);
    final Money priceEntered = sourceDocumentLine.getPriceEntered();
    final PricingConditionsBreak pricingConditionsBreak = PricingConditionsBreak.builder().id(// N/A
    null).matchCriteria(PricingConditionsBreakMatchCriteria.builder().breakValue(BigDecimal.ZERO).productId(sourceDocumentLine.getProductId()).productCategoryId(sourceDocumentLine.getProductCategoryId()).build()).priceSpecification(PriceSpecification.fixedPrice(priceEntered)).paymentTermIdOrNull(sourceDocumentLine.getPaymentTermId()).discount(sourceDocumentLine.getDiscount()).dateCreated(// N/A; the PricingConditionsBreak hasn't been created (i.e. persisted on DB) yet
    null).createdById(null).build();
    return PricingConditionsRow.builder().lookups(lookups).editable(true).bpartner(lookups.lookupBPartner(sourceDocumentLine.getBpartnerId())).customer(sourceDocumentLine.getSoTrx().isSales()).pricingConditionsId(pricingConditionsId).pricingConditionsBreak(pricingConditionsBreak).basePricingSystemPriceCalculator(basePricingSystemPriceCalculator).dateLastInOut(getLastInOutDate(sourceDocumentLine.getBpartnerId(), sourceDocumentLine.getSoTrx(), pricingConditionsBreak)).build();
}
Also used : PricingConditionsId(de.metas.pricing.conditions.PricingConditionsId) Money(de.metas.money.Money) PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak)

Example 5 with PricingConditionsBreak

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

the class PricingConditionsView_SaveEditableRow method doIt.

@Override
protected String doIt() {
    final PricingConditionsBreak pricingConditionsBreak = pricingConditionsRepo.changePricingConditionsBreak(createPricingConditionsBreakChangeRequest(getEditableRow()));
    patchEditableRow(PricingConditionsRowActions.saved(pricingConditionsBreak));
    return MSG_OK;
}
Also used : PricingConditionsBreak(de.metas.pricing.conditions.PricingConditionsBreak)

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