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());
}
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();
}
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;
}
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();
}
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;
}
}
Aggregations