Skip to content

Commit

Permalink
Add param values provider for LU-PI parameter of WEBUI_M_HU_Transform
Browse files Browse the repository at this point in the history
Also add a bit of javadoc and rearrange methods a bit

FRESH-1504 #181 Transforming HU in Handling
Unit Editor
  • Loading branch information
metas-ts committed Mar 3, 2017
1 parent a829951 commit 888b2ea
Showing 1 changed file with 71 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Set;
import java.util.stream.Stream;

import org.adempiere.ad.dao.IQueryBL;
import org.adempiere.ad.service.IADReferenceDAO;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.FillMandatoryException;
Expand All @@ -25,6 +26,7 @@
import de.metas.handlingunits.model.I_M_HU_PI;
import de.metas.handlingunits.model.I_M_HU_PI_Item;
import de.metas.handlingunits.model.I_M_HU_PI_Item_Product;
import de.metas.handlingunits.model.I_M_HU_PI_Version;
import de.metas.handlingunits.model.X_M_HU_PI_Version;
import de.metas.process.IADProcessDAO;
import de.metas.process.IProcessDefaultParameter;
Expand Down Expand Up @@ -141,6 +143,11 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();

}
if (getSingleSelectedRow().isLU())
{
return ProcessPreconditionsResolution.reject("Only applicable for CUs and TUs");
}

return ProcessPreconditionsResolution.accept();
}

Expand Down Expand Up @@ -265,8 +272,8 @@ private void action_SplitTU_To_ExistingLU(
/**
* Split TU to new LU (only one LU!).
*
* @param tuRow
* @param QtyTU
* @param tuRow represents the TU (or TUs in the aggregate-HU-case) that is our split source
* @param qtyTU the number of TUs we want to split from the given {@code tuRow}
* @param tuPIItemProductId
* @param luPIItemId
* @param isOwnPackingMaterials
Expand Down Expand Up @@ -320,6 +327,10 @@ private final I_M_HU_PI_Item findLU_HU_PI_Item(final I_M_HU_PI_Item_Product tuPI
return luPI_Item;
}

/**
*
* @return the action that are available according to which row is currently selected and to also according to whether there are already existing TUs or LUs in the context.
*/
@ProcessParamLookupValuesProvider(parameterName = PARAM_Action, dependsOn = {}, numericKey = false)
private LookupValuesList getActions()
{
Expand Down Expand Up @@ -366,6 +377,32 @@ private LookupValuesList getActions()
.collect(LookupValuesList.collect());
}

/**
*
* @return existing TUs that are available in the current HU editor context.
*/
@ProcessParamLookupValuesProvider(parameterName = PARAM_M_TU_HU_ID, dependsOn = PARAM_Action, numericKey = true)
private LookupValuesList getTULookupValues()
{
final ActionType actionType = p_Action == null ? null : ActionType.valueOf(p_Action);
if (actionType == ActionType.CU_To_ExistingTU)
{
return getView()
.streamAllRecursive()
.filter(row -> row.isTU())
.map(row -> row.toLookupValue())
.collect(LookupValuesList.collect());
}
else
{
return LookupValuesList.EMPTY;
}
}

/**
*
* @return existing LUs that are available in the current HU editor context.
*/
@ProcessParamLookupValuesProvider(parameterName = PARAM_M_LU_HU_ID, dependsOn = PARAM_Action, numericKey = true)
private LookupValuesList getLULookupValues()
{
Expand Down Expand Up @@ -395,30 +432,15 @@ private LookupValuesList getM_HU_PI_Item_Products()

case TU_To_NewTUs:
return retrieveHUPItemProductsForNewTU();

case TU_To_NewLU:
return retrieveHUPItemProductsForNewTU(); // here we also create new TUs, in addition to the new LU

default:
return LookupValuesList.EMPTY;
}
}

@ProcessParamLookupValuesProvider(parameterName = PARAM_M_TU_HU_ID, dependsOn = PARAM_Action, numericKey = true)
private LookupValuesList getTULookupValues()
{
final ActionType actionType = p_Action == null ? null : ActionType.valueOf(p_Action);
if (actionType == ActionType.CU_To_ExistingTU)
{
return getView()
.streamAllRecursive()
.filter(row -> row.isTU())
.map(row -> row.toLookupValue())
.collect(LookupValuesList.collect());
}
else
{
return LookupValuesList.EMPTY;
}
}

private LookupValuesList retrieveHUPItemProductsForNewTU()
{
final IHUPIItemProductDAO hupiItemProductDAO = Services.get(IHUPIItemProductDAO.class);
Expand All @@ -432,4 +454,33 @@ private LookupValuesList retrieveHUPItemProductsForNewTU()
.map(huPIItemProduct -> IntegerLookupValue.of(huPIItemProduct.getM_HU_PI_Item_Product_ID(), huPIItemProduct.getName()))
.collect(LookupValuesList.collect());
}

/**
* Retrieves all LU packing instructions that can be used with the currently selected {@link #PARAM_M_HU_PI_Item_Product_ID}.
*
* @return
*/
@ProcessParamLookupValuesProvider(parameterName = PARAM_M_LU_HU_PI_ID, dependsOn = { PARAM_Action, PARAM_M_HU_PI_Item_Product_ID }, numericKey = true)
private LookupValuesList getM_LU_HU_PI_ID()
{
if (p_M_HU_PI_Item_Product == null)
{
return LookupValuesList.EMPTY;
}

final I_M_HU_PI tuPI = p_M_HU_PI_Item_Product.getM_HU_PI_Item().getM_HU_PI_Version().getM_HU_PI();
final List<I_M_HU_PI> luPIs = Services.get(IQueryBL.class).createQueryBuilder(I_M_HU_PI_Item.class, this)
.addOnlyActiveRecordsFilter()
.addEqualsFilter(I_M_HU_PI_Item.COLUMN_Included_HU_PI_ID, tuPI.getM_HU_PI_ID())
.andCollect(I_M_HU_PI_Item.COLUMN_M_HU_PI_Version_ID)
.addOnlyActiveRecordsFilter()
.andCollect(I_M_HU_PI_Version.COLUMN_M_HU_PI_ID)
.addOnlyActiveRecordsFilter()
.orderBy().addColumn(I_M_HU_PI.COLUMN_M_HU_PI_ID).endOrderBy()
.create()
.list();

return luPIs.stream().map(luPI -> IntegerLookupValue.of(luPI.getM_HU_PI_ID(), luPI.getName()))
.collect(LookupValuesList.collect());
}
}

0 comments on commit 888b2ea

Please sign in to comment.