Skip to content

Commit

Permalink
Change picking start process to only allow good selections
Browse files Browse the repository at this point in the history
also add ad_messages; 

518: Picking prototype (v6) 

Task-Url: #518
  • Loading branch information
metas-ts committed Jul 26, 2017
1 parent 6a07be3 commit 4838ef7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ private AD_Message_Values()
static final String MSG_WEBUI_PICKING_NOT_TOP_LEVEL_HU = "WEBUI_Picking_Not_TopLevelHU";

static final String MSG_WEBUI_PICKING_WRONG_HU_STATUS_3P = "WEBUI_Picking_Wrong_HU_Status";

static final String MSG_WEBUI_PICKING_ALREADY_SHIPPED_2P = "WEBUI_Picking_Already_Shipped";

static final String MSG_WEBUI_PICKING_DIVERGING_LOCATIONS = "WEBUI_Picking_Diverging_Locations";

static final String MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P = "WEBUI_Picking_Too_Many_Packageables";

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package de.metas.ui.web.picking.process;

import static de.metas.ui.web.picking.process.AD_Message_Values.MSG_WEBUI_PICKING_DIVERGING_LOCATIONS;
import static de.metas.ui.web.picking.process.AD_Message_Values.MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.lang.impl.TableRecordReference;
import org.compiere.util.Env;

import com.google.common.collect.ImmutableList;

Expand All @@ -14,6 +20,8 @@
import de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
import de.metas.ui.web.window.datatypes.json.JSONLookupValue;
import lombok.NonNull;

/*
* #%L
Expand All @@ -39,20 +47,24 @@

public class WEBUI_Picking_Start extends ViewBasedProcessTemplate implements IProcessPrecondition
{

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if (getSelectedDocumentIds().isEmpty())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

return ProcessPreconditionsResolution.accept();
return verifySelectedDocuments();
}

@Override
protected String doIt() throws Exception
{
// repeat the verification from checkPreconditionsApplicable() just to be sure.
// We had cases where the selected rows of checkPreconditionsApplicable() were not the selected rows of doIt()
final ProcessPreconditionsResolution verifySelectedDocuments = verifySelectedDocuments();
if (verifySelectedDocuments.isRejected())
{
throw new AdempiereException(verifySelectedDocuments().getRejectReason().translate(Env.getAD_Language(getCtx())));
}

final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
final List<Integer> rowIds = getView().getByIds(selectedRowIds)
.stream()
Expand All @@ -69,4 +81,40 @@ protected String doIt() throws Exception
return MSG_OK;
}

private ProcessPreconditionsResolution verifySelectedDocuments()
{
if (getSelectedDocumentIds().isEmpty())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

if (getSelectedDocumentIds().size() > 50)
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P, 50));
}

if (getSelectedDocumentIds().size() > 1)
{
// make sure that they all have the same C_BPartner and location.
final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
final Set<Integer> flatMap = getView().getByIds(selectedRowIds)
.stream()
.flatMap(selectedRow -> selectedRow.getIncludedRows().stream())
.map(row -> getBPartnerLocationId(row))
.collect(Collectors.toSet());
if (flatMap.size() > 1)
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_WEBUI_PICKING_DIVERGING_LOCATIONS));
}
}

return ProcessPreconditionsResolution.accept();
}

private int getBPartnerLocationId(@NonNull final IViewRow row)
{
final JSONLookupValue jsonLookupValue = (JSONLookupValue)row.getFieldNameAndJsonValues().get(I_M_Packageable_V.COLUMNNAME_C_BPartner_Location_ID);
return jsonLookupValue.getKeyAsInt();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected ViewBasedProcessTemplate()
/**
* Please implement {@link #checkPreconditionsApplicable()} instead of this.
*
* WARNING: The preconditions will be checked only if the extending class implements IProcessPrecondition class.
* WARNING: The preconditions will be checked only if the extending class implements the {@link de.metas.process.IProcessPrecondition} interface.
*
* @param context
*/
Expand Down

0 comments on commit 4838ef7

Please sign in to comment.