Search in sources :

Example 1 with PartialPriceChangeBuilder

use of de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder in project metasfresh-webui-api by metasfresh.

the class PricingConditionsRowActions method toPartialPriceChange.

private static PartialPriceChange toPartialPriceChange(final List<JSONDocumentChangedEvent> fieldChangeRequests, final CurrencyId defaultCurrencyId) {
    final PartialPriceChangeBuilder builder = PartialPriceChange.builder().defaultCurrencyId(defaultCurrencyId);
    for (final JSONDocumentChangedEvent fieldChangeRequest : fieldChangeRequests) {
        final String fieldName = fieldChangeRequest.getPath();
        builder.changedFieldName(fieldName);
        if (PricingConditionsRow.FIELDNAME_BasePriceType.equals(fieldName)) {
            final LookupValue priceTypeLookupValue = fieldChangeRequest.getValueAsStringLookupValue();
            final PriceSpecificationType priceType = priceTypeLookupValue != null ? PriceSpecificationType.ofCode(priceTypeLookupValue.getIdAsString()) : null;
            builder.priceType(priceType);
        } else if (PricingConditionsRow.FIELDNAME_BasePricingSystem.equals(fieldName)) {
            final LookupValue pricingSystem = fieldChangeRequest.getValueAsIntegerLookupValue();
            final PricingSystemId pricingSystemId = pricingSystem != null ? PricingSystemId.ofRepoIdOrNull(pricingSystem.getIdAsInt()) : null;
            builder.basePricingSystemId(Optional.ofNullable(pricingSystemId));
        } else if (PricingConditionsRow.FIELDNAME_PricingSystemSurcharge.equals(fieldName)) {
            builder.pricingSystemSurchargeAmt(fieldChangeRequest.getValueAsBigDecimal(BigDecimal.ZERO));
        } else if (PricingConditionsRow.FIELDNAME_BasePrice.equals(fieldName)) {
            builder.fixedPriceAmt(fieldChangeRequest.getValueAsBigDecimal(BigDecimal.ZERO));
        } else if (PricingConditionsRow.FIELDNAME_C_Currency_ID.equals(fieldName)) {
            final LookupValue currency = fieldChangeRequest.getValueAsIntegerLookupValue();
            final CurrencyId currencyId = currency != null ? CurrencyId.ofRepoIdOrNull(currency.getIdAsInt()) : null;
            builder.currencyId(currencyId);
            if (currencyId != null) {
                builder.defaultCurrencyId(currencyId);
            }
        }
    }
    return builder.build();
}
Also used : PartialPriceChangeBuilder(de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder) PriceSpecificationType(de.metas.pricing.conditions.PriceSpecificationType) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) PricingSystemId(de.metas.pricing.PricingSystemId) CurrencyId(de.metas.money.CurrencyId) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Aggregations

CurrencyId (de.metas.money.CurrencyId)1 PricingSystemId (de.metas.pricing.PricingSystemId)1 PriceSpecificationType (de.metas.pricing.conditions.PriceSpecificationType)1 PartialPriceChangeBuilder (de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 JSONDocumentChangedEvent (de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent)1