use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.
the class SqlHUEditorViewRepository method createHUEditorRow.
private HUEditorRow createHUEditorRow(final HuId parentHUId, final HuId topLevelHUId, @NonNull final IHUProductStorage huStorage, final boolean processed) {
// final Stopwatch stopwatch = Stopwatch.createStarted();
final I_M_HU hu = huStorage.getM_HU();
final HuId huId = HuId.ofRepoId(hu.getM_HU_ID());
final ProductId productId = huStorage.getProductId();
final HUEditorRowAttributesProvider attributesProviderEffective = !huId.equals(parentHUId) ? attributesProvider : null;
final Optional<OrderLineId> reservedForOrderLineId = huReservationService.getOrderLineIdByReservedVhuId(huId);
final HUEditorRow huEditorRow = HUEditorRow.builder(windowId).setRowId(HUEditorRowId.ofHUStorage(huId, topLevelHUId, productId)).setType(HUEditorRowType.HUStorage).setTopLevel(false).setProcessed(processed).setAttributesProvider(attributesProviderEffective).setHUUnitType(JSONLookupValue.of(X_M_HU_PI_Version.HU_UNITTYPE_VirtualPI, "CU")).setHUStatus(hu.getHUStatus()).setReservedForOrderLine(reservedForOrderLineId.orElse(null)).setHUStatusDisplay(createHUStatusDisplayLookupValue(hu)).setProduct(createProductLookupValue(productId)).setUOM(createUOMLookupValue(huStorage.getC_UOM())).setQtyCU(huStorage.getQty().toBigDecimal()).build();
// System.out.println("createHUEditorRow: created " + huEditorRow + " (storage) in " + stopwatch);
return huEditorRow;
}
use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformParametersFiller method retrieveHUPItemProductsForNewTU.
private static LookupValuesList retrieveHUPItemProductsForNewTU(final HUEditorRow cuRow) {
final ProductId productId = cuRow.getProductId();
final BPartnerId bpartnerId = IHandlingUnitsBL.extractBPartnerIdOrNull(cuRow.getM_HU());
return WEBUI_ProcessHelper.retrieveHUPIItemProducts(Env.getCtx(), productId, bpartnerId, // includeVirtualItem = false..moving a cu onto a "virtual" TU makes no sense. Instead, the user can just leave the CU as it is, or take it out of a physical TU
false);
}
use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformParametersFiller method getDefaultM_HU_PI_Item_Product.
public Optional<I_M_HU_PI_Item_Product> getDefaultM_HU_PI_Item_Product() {
final HUEditorRow cuRow = getSelectedRow();
final ProductId productId = cuRow.getProductId();
final BPartnerId bpartnerId = IHandlingUnitsBL.extractBPartnerIdOrNull(cuRow.getM_HU());
final List<I_M_HU_PI_Item_Product> allPIs = WEBUI_ProcessHelper.retrieveHUPIItemProductRecords(Env.getCtx(), productId, bpartnerId, false);
return allPIs.stream().filter(hu -> hu.isActive() && hu.isDefaultForProduct()).min(Comparator.comparingInt(I_M_HU_PI_Item_Product::getM_HU_PI_Item_Product_ID));
}
use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_HU_Pick_ParametersFiller method createShipmentSchedulesValidationRule.
private static IValidationRule createShipmentSchedulesValidationRule(final HuId huId) {
final StringBuilder sqlWhereClause = new StringBuilder();
sqlWhereClause.append(I_M_ShipmentSchedule.COLUMNNAME_Processed).append("=").append(DB.TO_BOOLEAN(false));
final ProductId productId = getSingleProductId(huId);
sqlWhereClause.append(" AND ").append(I_M_ShipmentSchedule.COLUMNNAME_M_Product_ID).append("=").append(productId.getRepoId());
final I_M_HU hu = load(huId, I_M_HU.class);
if (hu.getC_BPartner_ID() > 0) {
sqlWhereClause.append(" AND COALESCE(").append(I_M_ShipmentSchedule.COLUMNNAME_C_BPartner_Override_ID).append(", ").append(I_M_ShipmentSchedule.COLUMNNAME_C_BPartner_ID).append(") = ").append(hu.getC_BPartner_ID());
}
return Services.get(IValidationRuleFactory.class).createSQLValidationRule(sqlWhereClause.toString());
}
use of de.metas.product.ProductId in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_HU_Pick_ParametersFiller method getSingleProductId.
private static ProductId getSingleProductId(final HuId huId) {
final I_M_HU hu = Services.get(IHandlingUnitsDAO.class).getById(huId);
final Set<ProductId> productIds = Services.get(IHUContextFactory.class).createMutableHUContext().getHUStorageFactory().getStorage(hu).getProductStorages().stream().map(IHUProductStorage::getProductId).distinct().collect(ImmutableSet.toImmutableSet());
if (productIds.isEmpty()) {
throw new AdempiereException("Empty HUs are not allowed");
}
if (productIds.size() > 1) {
throw new AdempiereException("Multi product HUs are not allowed");
}
return productIds.iterator().next();
}
Aggregations