use of de.metas.handlingunits.model.I_M_HU in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformCommand method action_SplitTU_To_NewTUs.
/**
* Split a given number of TUs from current selected TU line to new TUs.
*
* @param tuRow
* @param qtyTU
* @param tuPI
* @return
*/
private WebuiHUTransformCommandResult action_SplitTU_To_NewTUs(final HUEditorRow tuRow, final BigDecimal qtyTU) {
final IHandlingUnitsBL handlingUnitsBL = Services.get(IHandlingUnitsBL.class);
// TODO: if qtyTU is the "maximum", then don't do anything, but show a user message
final I_M_HU fromTU = tuRow.getM_HU();
final I_M_HU fromTopLevelHU = handlingUnitsBL.getTopLevelParent(fromTU);
final List<I_M_HU> createdHUs = newHUTransformation().tuToNewTUs(fromTU, qtyTU);
final WebuiHUTransformCommandResultBuilder resultBuilder = WebuiHUTransformCommandResult.builder().huIdsToAddToView(createdHUs.stream().map(I_M_HU::getM_HU_ID).collect(ImmutableSet.toImmutableSet()));
if (handlingUnitsBL.isDestroyedRefreshFirst(fromTopLevelHU)) {
resultBuilder.huIdToRemoveFromView(fromTopLevelHU.getM_HU_ID());
} else {
resultBuilder.huIdChanged(fromTopLevelHU.getM_HU_ID());
}
return resultBuilder.build();
}
use of de.metas.handlingunits.model.I_M_HU in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformParametersFiller method getParentHUIdOfSelectedRow.
private int getParentHUIdOfSelectedRow() {
final HUEditorRow huRow = getSelectedRow();
final I_M_HU hu = huRow.getM_HU();
final int parentIdOfSelectedHU = handlingUnitsDAO.retrieveParentId(hu);
return parentIdOfSelectedHU;
}
use of de.metas.handlingunits.model.I_M_HU in project metasfresh-webui-api by metasfresh.
the class WebuiHUTransformParametersFiller method getM_HU_PI_Item_IDs.
public LookupValuesList getM_HU_PI_Item_IDs() {
final ActionType actionType = getActionType();
if (actionType != ActionType.TU_To_NewLUs) {
return LookupValuesList.EMPTY;
}
final HUEditorRow tuRow = getSelectedRow();
final I_M_HU tuHU = tuRow.getM_HU();
final I_M_HU_PI_Version effectivePIVersion = handlingUnitsBL.getEffectivePIVersion(tuHU);
Check.errorIf(effectivePIVersion == null, "tuHU is inconsistent; hu={}", tuHU);
final List<I_M_HU_PI_Item> luPIItems = handlingUnitsDAO.retrieveParentPIItemsForParentPI(effectivePIVersion.getM_HU_PI(), null, tuHU.getC_BPartner());
return luPIItems.stream().filter(luPIItem -> luPIItem.getM_HU_PI_Version().isCurrent() && luPIItem.getM_HU_PI_Version().isActive() && luPIItem.getM_HU_PI_Version().getM_HU_PI().isActive()).map(luPIItem -> IntegerLookupValue.of(luPIItem.getM_HU_PI_Item_ID(), WEBUI_ProcessHelper.buildHUPIItemString(luPIItem))).sorted(Comparator.comparing(IntegerLookupValue::getDisplayName)).collect(LookupValuesList.collect());
}
use of de.metas.handlingunits.model.I_M_HU in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_HU_Pick_ParametersFiller method createShipmentSchedulesValidationRule.
private static IValidationRule createShipmentSchedulesValidationRule(final int huId) {
final StringBuilder sqlWhereClause = new StringBuilder();
sqlWhereClause.append(I_M_ShipmentSchedule.COLUMNNAME_Processed).append("=").append(DB.TO_BOOLEAN(false));
final int productId = getSingleProductId(huId);
sqlWhereClause.append(" AND ").append(I_M_ShipmentSchedule.COLUMNNAME_M_Product_ID).append("=").append(productId);
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.handlingunits.model.I_M_HU in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_HU_Pick_ParametersFiller method getSingleProductId.
private static final int getSingleProductId(final int huId) {
final I_M_HU hu = InterfaceWrapperHelper.load(huId, I_M_HU.class);
final List<Integer> productIds = Services.get(IHUContextFactory.class).createMutableHUContext().getHUStorageFactory().getStorage(hu).getProductStorages().stream().map(IHUProductStorage::getM_Product_ID).distinct().collect(ImmutableList.toImmutableList());
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.get(0);
}
Aggregations