Skip to content

Commit

Permalink
WEBUI_M_HU_MoveTUsToDirectWarehouse: avoid the LU-VHU case
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Sep 4, 2017
1 parent 9f188e7 commit d743b3c
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.List;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.FillMandatoryException;
import org.springframework.beans.factory.annotation.Autowired;

import de.metas.handlingunits.allocation.transfer.HUTransformService;
Expand Down Expand Up @@ -43,6 +45,8 @@
*/
public class WEBUI_M_HU_MoveTUsToDirectWarehouse extends HUEditorProcessTemplate implements IProcessPrecondition
{
private static final String MSG_NotEnoughTUsFound = "WEBUI_M_HU_MoveTUsToDirectWarehouse.NotEnoughTUsFound";

@Autowired
private DocumentCollection documentsCollection;

Expand All @@ -60,7 +64,18 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()

final DocumentId rowId = selectedRowIds.getSingleDocumentId();
final HUEditorRow huRow = getView().getById(rowId);
if (!huRow.isLU() && !huRow.isTU())
if (huRow.isLU())
{
if (!huRow.hasIncludedTUs())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("no TUs");
}
}
else if (huRow.isTU())
{
// OK
}
else
{
return ProcessPreconditionsResolution.rejectWithInternalReason("not a LU or TU");
}
Expand All @@ -72,11 +87,20 @@ protected ProcessPreconditionsResolution checkPreconditionsApplicable()
// @RunOutOfTrx // run in transaction!
protected String doIt()
{
if (p_QtyTU <= 0)
{
throw new FillMandatoryException("QtyTU");
}

final I_M_HU topLevelHU = getRecord(I_M_HU.class);

final boolean isOwnPackingMaterials = true;
final List<I_M_HU> tus = HUTransformService.getWithThreadInheritedTrx()
.huExtractTUs(topLevelHU, p_QtyTU, isOwnPackingMaterials);
if (tus.size() != p_QtyTU)
{
throw new AdempiereException(MSG_NotEnoughTUsFound, new Object[] { p_QtyTU, tus.size() });
}

HUMoveToDirectWarehouseService.newInstance()
.setDocumentsCollection(documentsCollection)
Expand Down

0 comments on commit d743b3c

Please sign in to comment.