Search in sources :

Example 6 with ProductId

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;
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU) OrderLineId(de.metas.order.OrderLineId) HuId(de.metas.handlingunits.HuId) ProductId(de.metas.product.ProductId)

Example 7 with ProductId

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);
}
Also used : ProductId(de.metas.product.ProductId) BPartnerId(de.metas.bpartner.BPartnerId)

Example 8 with ProductId

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));
}
Also used : IHandlingUnitsBL(de.metas.handlingunits.IHandlingUnitsBL) LookupDataSourceFactory(de.metas.ui.web.window.model.lookup.LookupDataSourceFactory) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) Env(org.compiere.util.Env) HUEditorRowFilter(de.metas.ui.web.handlingunits.HUEditorRowFilter) I_M_HU_PI_Version(de.metas.handlingunits.model.I_M_HU_PI_Version) SqlLookupDescriptor(de.metas.ui.web.window.descriptor.sql.SqlLookupDescriptor) I_AD_Process_Para(org.compiere.model.I_AD_Process_Para) ProductId(de.metas.product.ProductId) HashSet(java.util.HashSet) ADRefListItem(org.adempiere.ad.service.IADReferenceDAO.ADRefListItem) Select(de.metas.ui.web.handlingunits.HUEditorRowFilter.Select) LookupDescriptor(de.metas.ui.web.window.descriptor.LookupDescriptor) DisplayType(org.compiere.util.DisplayType) AdProcessId(de.metas.process.AdProcessId) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) I_M_HU_PI_Item(de.metas.handlingunits.model.I_M_HU_PI_Item) IADReferenceDAO(org.adempiere.ad.service.IADReferenceDAO) I_M_HU(de.metas.handlingunits.model.I_M_HU) Nullable(javax.annotation.Nullable) IADProcessDAO(de.metas.process.IADProcessDAO) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow) LookupDataSource(de.metas.ui.web.window.model.lookup.LookupDataSource) LookupDataSourceContext(de.metas.ui.web.window.model.lookup.LookupDataSourceContext) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) I_M_HU_PI_Item_Product(de.metas.handlingunits.model.I_M_HU_PI_Item_Product) IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) HUTransformService(de.metas.handlingunits.allocation.transfer.HUTransformService) Services(de.metas.util.Services) List(java.util.List) WEBUI_ProcessHelper(de.metas.ui.web.handlingunits.util.WEBUI_ProcessHelper) StringLookupValue(de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue) HuId(de.metas.handlingunits.HuId) X_M_HU(de.metas.handlingunits.model.X_M_HU) Builder(lombok.Builder) Check(de.metas.printing.esb.base.util.Check) IProcessDefaultParametersProvider(de.metas.process.IProcessDefaultParametersProvider) BPartnerId(de.metas.bpartner.BPartnerId) Optional(java.util.Optional) ActionType(de.metas.ui.web.handlingunits.process.WebuiHUTransformCommand.ActionType) HUEditorView(de.metas.ui.web.handlingunits.HUEditorView) Comparator(java.util.Comparator) I_M_HU_PI_Item_Product(de.metas.handlingunits.model.I_M_HU_PI_Item_Product) ProductId(de.metas.product.ProductId) BPartnerId(de.metas.bpartner.BPartnerId) HUEditorRow(de.metas.ui.web.handlingunits.HUEditorRow)

Example 9 with ProductId

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());
}
Also used : I_M_HU(de.metas.handlingunits.model.I_M_HU) ProductId(de.metas.product.ProductId) IValidationRuleFactory(org.adempiere.ad.validationRule.IValidationRuleFactory)

Example 10 with ProductId

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();
}
Also used : IHandlingUnitsDAO(de.metas.handlingunits.IHandlingUnitsDAO) I_M_HU(de.metas.handlingunits.model.I_M_HU) AdempiereException(org.adempiere.exceptions.AdempiereException) ProductId(de.metas.product.ProductId) IHUProductStorage(de.metas.handlingunits.storage.IHUProductStorage)

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