From 888b2ea45c6eb2f016c5725e94a1dd6917d4b5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Sch=C3=B6neberg?= Date: Fri, 3 Mar 2017 17:33:44 +0100 Subject: [PATCH] Add param values provider for LU-PI parameter of WEBUI_M_HU_Transform Also add a bit of javadoc and rearrange methods a bit FRESH-1504 metasfresh/metasfresh-webui#181 Transforming HU in Handling Unit Editor --- .../process/WEBUI_M_HU_Transform.java | 91 +++++++++++++++---- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_HU_Transform.java b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_HU_Transform.java index b17d86d50..c205c47ad 100644 --- a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_HU_Transform.java +++ b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_HU_Transform.java @@ -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; @@ -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; @@ -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(); } @@ -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 @@ -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() { @@ -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() { @@ -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); @@ -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 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()); + } }