Permalink
Browse files

implement WEBUI_HUsToPick_PickCU.checkPreconditionsApplicated

  • Loading branch information...
teosarca committed Dec 11, 2017
1 parent 69e75ef commit 73793f7e73477f0face93deccfe19fb1db320b80
@@ -29,12 +29,13 @@
{
@Autowired
private PickingCandidateService pickingCandidateService;
@Autowired
private IViewsRepository viewsRepo;
private final SourceHUsService sourceHuService = SourceHUsService.get();
private final IHUPickingSlotDAO huPickingSlotDAO = Services.get(IHUPickingSlotDAO.class);
@Override
public final ProcessPreconditionsResolution checkPreconditionsApplicable()
public ProcessPreconditionsResolution checkPreconditionsApplicable()
{
final Optional<HUEditorRow> anyHU = retrieveEligibleHUEditorRows().findAny();
if (anyHU.isPresent())
@@ -48,14 +49,34 @@ public final ProcessPreconditionsResolution checkPreconditionsApplicable()
protected final Stream<HUEditorRow> retrieveEligibleHUEditorRows()
{
final IHUPickingSlotDAO huPickingSlotDAO = Services.get(IHUPickingSlotDAO.class);
final SourceHUsService sourceHuService = SourceHUsService.get();
return getView().streamByIds(getSelectedDocumentIds())
.filter(huRow -> huRow.isTopLevel())
.filter(huRow -> huRow.isHUStatusActive())
.filter(huRow -> !sourceHuService.isSourceHu(huRow.getM_HU_ID())) // may not yet be a source-HU
.filter(huRow -> !huPickingSlotDAO.isHuIdPicked(huRow.getM_HU_ID()));
return getView()
.streamByIds(getSelectedDocumentIds())
.filter(this::isEligible);
}
protected final boolean isEligible(final HUEditorRow huRow)
{
if (!huRow.isTopLevel())
{
return false;
}
if (!huRow.isHUStatusActive())
{
return false;
}
// may not yet be a source-HU
if (sourceHuService.isSourceHu(huRow.getM_HU_ID()))
{
return false;
}
if (huPickingSlotDAO.isHuIdPicked(huRow.getM_HU_ID()))
{
return false;
}
return true;
}
@Override
@@ -1,5 +1,6 @@
package de.metas.ui.web.picking.husToPick.process;
import static de.metas.ui.web.handlingunits.WEBUI_HU_Constants.MSG_WEBUI_SELECT_ACTIVE_UNSELECTED_HU;
import static org.adempiere.model.InterfaceWrapperHelper.load;
import static org.adempiere.model.InterfaceWrapperHelper.loadOutOfTrx;
@@ -21,12 +22,16 @@
import de.metas.handlingunits.allocation.transfer.impl.HUSplitBuilderCoreEngine;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.I_M_ShipmentSchedule;
import de.metas.i18n.IMsgBL;
import de.metas.i18n.ITranslatableString;
import de.metas.process.IProcessParametersCallout;
import de.metas.process.IProcessPrecondition;
import de.metas.process.Param;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.product.IProductBL;
import de.metas.ui.web.handlingunits.HUEditorRow;
import de.metas.ui.web.picking.pickingslot.PickingSlotView;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
/*
* #%L
@@ -74,6 +79,29 @@
private transient I_M_Product _shipmentScheduleProduct; // lazy
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable()
{
final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
if (selectedRowIds.isEmpty())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}
else if (selectedRowIds.isMoreThanOneDocumentId())
{
return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
}
final HUEditorRow huRow = getSingleSelectedRow();
if (!isEligible(huRow))
{
final ITranslatableString reason = Services.get(IMsgBL.class).getTranslatableMsgText(MSG_WEBUI_SELECT_ACTIVE_UNSELECTED_HU);
return ProcessPreconditionsResolution.reject(reason);
}
return ProcessPreconditionsResolution.accept();
}
@Override
public void onParameterChanged(final String parameterName)
{

0 comments on commit 73793f7

Please sign in to comment.