Search in sources :

Example 46 with ProductId

use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.

the class ProductLookupDescriptor method explodeLookupValuesByAvailableStockGroups.

@VisibleForTesting
static LookupValuesList explodeLookupValuesByAvailableStockGroups(@NonNull final LookupValuesList initialLookupValues, @NonNull final List<Group> availableStockGroups, final boolean displayATPOnlyIfPositive, @NonNull final String adLanguage) {
    if (initialLookupValues.isEmpty()) {
        return initialLookupValues;
    }
    if (availableStockGroups.isEmpty()) {
        return initialLookupValues;
    }
    final ImmutableListMultimap<ProductId, Group> groupsByProductId = Multimaps.index(availableStockGroups, Group::getProductId);
    final ArrayList<ProductWithATP> productWithATPs = new ArrayList<>();
    for (final LookupValue productLookupValue : initialLookupValues) {
        final ProductId productId = productLookupValue.getIdAs(ProductId::ofRepoId);
        final ImmutableList<Group> groups = groupsByProductId.get(productId);
        productWithATPs.addAll(createProductWithATPs(productLookupValue, groups, displayATPOnlyIfPositive));
    }
    return productWithATPs.stream().map(productWithATP -> createProductLookupValue(productWithATP, adLanguage)).collect(LookupValuesList.collect());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ImmutableAttributeSet(org.adempiere.mm.attributes.api.ImmutableAttributeSet) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) MLookupFactory(org.compiere.model.MLookupFactory) PriceListId(de.metas.pricing.PriceListId) Default(lombok.Builder.Default) AvailableToPromiseQuery(de.metas.material.dispo.commons.repository.atp.AvailableToPromiseQuery) PriceListVersionId(de.metas.pricing.PriceListVersionId) ProductId(de.metas.product.ProductId) I_M_FreightCost(org.adempiere.model.I_M_FreightCost) ResultSet(java.sql.ResultSet) ISysConfigBL(org.adempiere.service.ISysConfigBL) Map(java.util.Map) BPartnerClassifier(de.metas.material.dispo.commons.repository.atp.BPartnerClassifier) AvailableToPromiseResultForWebui(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) ImmutableMap(com.google.common.collect.ImmutableMap) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) TranslatableStringBuilder(de.metas.i18n.TranslatableStringBuilder) Set(java.util.Set) PreparedStatement(java.sql.PreparedStatement) Objects(java.util.Objects) I_M_Product(de.metas.product.model.I_M_Product) AvailableToPromiseAdapter(de.metas.ui.web.material.adapter.AvailableToPromiseAdapter) DBException(org.adempiere.exceptions.DBException) List(java.util.List) Builder(lombok.Builder) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) AttributeSetDescriptionBuilderCommand(org.adempiere.mm.attributes.api.impl.AttributeSetDescriptionBuilderCommand) BPartnerId(de.metas.bpartner.BPartnerId) IMsgBL(de.metas.i18n.IMsgBL) Optional(java.util.Optional) StringUtils(de.metas.util.StringUtils) TranslatableStrings(de.metas.i18n.TranslatableStrings) SystemTime(de.metas.util.time.SystemTime) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) Joiner(com.google.common.base.Joiner) I_M_ProductPrice(org.compiere.model.I_M_ProductPrice) Getter(lombok.Getter) ArrayList(java.util.ArrayList) CtxName(org.compiere.util.CtxName) Multimaps(com.google.common.collect.Multimaps) Value(lombok.Value) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) CtxNames(org.compiere.util.CtxNames) DB(org.compiere.util.DB) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) ImmutableList(com.google.common.collect.ImmutableList) Quantity(de.metas.quantity.Quantity) DisplayType(org.compiere.util.DisplayType) InterfaceWrapperHelper.getModelTranslationMap(org.adempiere.model.InterfaceWrapperHelper.getModelTranslationMap) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) AttributesKey(de.metas.material.event.commons.AttributesKey) CoalesceUtil(de.metas.util.lang.CoalesceUtil) AttributeId(org.adempiere.mm.attributes.AttributeId) Nullable(javax.annotation.Nullable) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) Check(de.metas.util.Check) Properties(java.util.Properties) LookupSource(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor.LookupSource) I_C_UOM(org.compiere.model.I_C_UOM) WindowId(de.metas.ui.web.window.datatypes.WindowId) LanguageInfo(org.compiere.model.MLookupFactory.LanguageInfo) Services(de.metas.util.Services) Group(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LookupDataSourceFetcher(de.metas.ui.web.window.model.lookup.LookupDataSourceFetcher) IPriceListDAO(de.metas.pricing.service.IPriceListDAO) SqlParamsCollector(de.metas.ui.web.document.filter.sql.SqlParamsCollector) Group(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group) ArrayList(java.util.ArrayList) ProductId(de.metas.product.ProductId) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 47 with ProductId

use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.

the class ProductLookupDescriptor method toProductAndAttributes.

public static ProductAndAttributes toProductAndAttributes(@NonNull final LookupValue lookupValue) {
    final ProductId productId = lookupValue.getIdAs(ProductId::ofRepoId);
    final Map<Object, Object> valuesByAttributeIdMap = lookupValue.getAttribute(ATTRIBUTE_ASI);
    final ImmutableAttributeSet attributes = ImmutableAttributeSet.ofValuesByAttributeIdMap(valuesByAttributeIdMap);
    return ProductAndAttributes.builder().productId(productId).attributes(attributes).build();
}
Also used : ImmutableAttributeSet(org.adempiere.mm.attributes.api.ImmutableAttributeSet) ProductId(de.metas.product.ProductId)

Example 48 with ProductId

use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.

the class ProductLookupDescriptor method createProductWithATPs.

private static List<ProductWithATP> createProductWithATPs(@NonNull final LookupValue productLookupValue, @NonNull final ImmutableList<Group> atpGroups, final boolean displayATPOnlyIfPositive) {
    final ArrayList<ProductWithATP> result = new ArrayList<>();
    ProductWithATP productWithATP_ALL = null;
    ProductWithATP productWithATP_OTHERS = null;
    for (final Group atpGroup : atpGroups) {
        final ProductWithATP productWithATP = ProductWithATP.builder().productId(productLookupValue.getIdAs(ProductId::ofRepoId)).productDisplayName(productLookupValue.getDisplayNameTrl()).qtyATP(atpGroup.getQty()).attributesType(atpGroup.getType()).attributes(atpGroup.getAttributes()).build();
        result.add(productWithATP);
        if (productWithATP.getAttributesType() == Group.Type.ALL_STORAGE_KEYS) {
            productWithATP_ALL = productWithATP;
        } else if (productWithATP.getAttributesType() == Group.Type.OTHER_STORAGE_KEYS) {
            productWithATP_OTHERS = productWithATP;
        }
    }
    // If OTHERS has the same Qty as ALL, remove OTHERS because it's pointless
    if (productWithATP_ALL != null && productWithATP_OTHERS != null && Objects.equals(productWithATP_OTHERS.getQtyATP(), productWithATP_ALL.getQtyATP())) {
        result.remove(productWithATP_OTHERS);
        productWithATP_OTHERS = null;
    }
    // Remove non-positive quantities if asked
    if (displayATPOnlyIfPositive) {
        result.removeIf(productWithATP -> productWithATP.getQtyATP().signum() <= 0);
    }
    // Make sure we have at least one entry for each product
    if (result.isEmpty()) {
        result.add(ProductWithATP.builder().productId(productLookupValue.getIdAs(ProductId::ofRepoId)).productDisplayName(productLookupValue.getDisplayNameTrl()).qtyATP(null).build());
    }
    return result;
}
Also used : Group(de.metas.ui.web.material.adapter.AvailableToPromiseResultForWebui.Group) ArrayList(java.util.ArrayList) ProductId(de.metas.product.ProductId)

Example 49 with ProductId

use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.

the class MaterialCockpitRowFactory method createEmptyRowBuckets.

@VisibleForTesting
Map<MainRowBucketId, MainRowWithSubRows> createEmptyRowBuckets(@NonNull final ImmutableSet<ProductId> productIds, @NonNull final LocalDate timestamp, final boolean includePerPlantDetailRows) {
    final DimensionSpec dimensionSpec = MaterialCockpitUtil.retrieveDimensionSpec();
    final List<DimensionSpecGroup> groups = dimensionSpec.retrieveGroups();
    final List<I_S_Resource> plants = retrieveCountingPlants(includePerPlantDetailRows);
    final Builder<MainRowBucketId, MainRowWithSubRows> result = ImmutableMap.builder();
    for (final ProductId productId : productIds) {
        final MainRowBucketId key = MainRowBucketId.createPlainInstance(productId, timestamp);
        final MainRowWithSubRows mainRowBucket = MainRowWithSubRows.create(key);
        for (final I_S_Resource plant : plants) {
            mainRowBucket.addEmptyCountingSubrowBucket(plant.getS_Resource_ID());
        }
        for (final DimensionSpecGroup group : groups) {
            mainRowBucket.addEmptyAttributesSubrowBucket(group);
        }
        result.put(key, mainRowBucket);
    }
    return result.build();
}
Also used : DimensionSpec(de.metas.dimension.DimensionSpec) I_S_Resource(org.compiere.model.I_S_Resource) DimensionSpecGroup(de.metas.dimension.DimensionSpecGroup) ProductId(de.metas.product.ProductId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 50 with ProductId

use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.

the class PricingConditionsRowsLoader method getLastInOutDate.

private LocalDate getLastInOutDate(@NonNull final BPartnerId bpartnerId, @NonNull final SOTrx soTrx, @NonNull final PricingConditionsBreak pricingConditionsBreak) {
    final ProductId productId = pricingConditionsBreak.getMatchCriteria().getProductId();
    if (productId == null) {
        return null;
    }
    final LastInOutDateRequest request = LastInOutDateRequest.builder().bpartnerId(bpartnerId).productId(productId).soTrx(soTrx).build();
    try {
        return lastInOutDates.get(request).orElse(null);
    } catch (ExecutionException ex) {
        logger.warn("Failed fetching last InOut date for {}. Returning null.", request, ex);
        return null;
    }
}
Also used : ProductId(de.metas.product.ProductId) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ProductId (de.metas.product.ProductId)56 HUPIItemProductId (de.metas.handlingunits.HUPIItemProductId)8 BPartnerId (de.metas.bpartner.BPartnerId)7 HuId (de.metas.handlingunits.HuId)7 Quantity (de.metas.quantity.Quantity)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 I_M_HU (de.metas.handlingunits.model.I_M_HU)6 IHUProductStorage (de.metas.handlingunits.storage.IHUProductStorage)5 IHUStorage (de.metas.handlingunits.storage.IHUStorage)5 ITranslatableString (de.metas.i18n.ITranslatableString)5 BigDecimal (java.math.BigDecimal)5 I_C_UOM (org.compiere.model.I_C_UOM)5 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)4 ArrayList (java.util.ArrayList)4 ImmutableAttributeSet (org.adempiere.mm.attributes.api.ImmutableAttributeSet)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableList (com.google.common.collect.ImmutableList)3 IHandlingUnitsBL (de.metas.handlingunits.IHandlingUnitsBL)3 I_M_HU_PI_Item_Product (de.metas.handlingunits.model.I_M_HU_PI_Item_Product)3 IProductBL (de.metas.product.IProductBL)3