Skip to content

Commit

Permalink
Picking shall be possible for >1 orderline in Picking Terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Nov 16, 2017
1 parent 8b160cc commit aeb98e6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 27 deletions.
24 changes: 22 additions & 2 deletions src/main/java/de/metas/ui/web/picking/PickingConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package de.metas.ui.web.picking;

import java.util.Set;
import java.util.function.Supplier;

import org.springframework.context.annotation.Configuration;

import com.google.common.collect.ImmutableSet;

import de.metas.inoutcandidate.model.I_M_Packageable_V;
import de.metas.ui.web.view.SqlViewFactory;
import de.metas.ui.web.view.descriptor.SqlViewGroupingBinding;
import de.metas.ui.web.view.descriptor.SqlViewRowIdsConverter;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
import lombok.NonNull;

/*
Expand All @@ -19,12 +25,12 @@
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
Expand All @@ -48,8 +54,22 @@ private void configurePackageablesGrouping(@NonNull final SqlViewFactory sqlView
.columnSql(I_M_Packageable_V.COLUMNNAME_QtyPickedPlanned, "SUM(QtyPickedPlanned)")
.columnSql(I_M_Packageable_V.COLUMNNAME_DeliveryDate, "MIN(DeliveryDate)")
.columnSql(I_M_Packageable_V.COLUMNNAME_PreparationDate, "IF_MIN(DeliveryDate, PreparationDate)")
.rowIdsConverter(new PackageableSqlViewRowIdsConverter())
.build();

sqlViewFactory.registerGroupingSupplier(PickingConstants.WINDOWID_PackageableView, supplier);
}

private static final class PackageableSqlViewRowIdsConverter implements SqlViewRowIdsConverter
{
@Override
public Set<Integer> convertToRecordIds(final DocumentIdsSelection rowIds)
{
// filter out detail rows because this converter is mainly used to build the AD_PInstance.WhereClause
return rowIds.stream()
.filter(DocumentId::isInt) // filter out detail rows
.map(DocumentId::toInt)
.collect(ImmutableSet.toImmutableSet());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.metas.ui.web.picking.process;

import static de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_CANNOT_PICK_INCLUDED_ROWS;
import static de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_DIVERGING_LOCATIONS;
import static de.metas.ui.web.picking.PickingConstants.MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P;

Expand All @@ -20,6 +19,7 @@
import de.metas.ui.web.picking.PickingConstants;
import de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
import de.metas.ui.web.window.datatypes.json.JSONLookupValue;
import lombok.NonNull;
Expand Down Expand Up @@ -48,6 +48,7 @@

public class WEBUI_Picking_Launcher extends ViewBasedProcessTemplate implements IProcessPrecondition
{
private static final int MAX_ROWS_ALLOWED = 50;

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
Expand All @@ -66,54 +67,45 @@ protected String doIt() throws Exception
throw new AdempiereException(verifySelectedDocuments().getRejectReason().translate(Env.getAD_Language(getCtx())));
}

final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
final List<Integer> rowIds = getView().streamByIds(selectedRowIds)
final DocumentIdsSelection selectedRowIds = getSelectedRootDocumentIds();
final List<TableRecordReference> records = getView().streamByIds(selectedRowIds)
.flatMap(selectedRow -> selectedRow.getIncludedRows().stream())
.map(IViewRow::getId)
.map(rowId -> rowId.removeDocumentPrefixAndConvertToInt())
.map(DocumentId::removeDocumentPrefixAndConvertToInt)
.map(recordId -> TableRecordReference.of(I_M_Packageable_V.Table_Name, recordId))
.collect(ImmutableList.toImmutableList());

if (rowIds.isEmpty())
if (records.isEmpty())
{
throw new AdempiereException("@NoSelection@");
}

getResult()
.setRecordsToOpen(
TableRecordReference.ofRecordIds(I_M_Packageable_V.Table_Name, rowIds),
PickingConstants.WINDOWID_PickingView.toInt());
getResult().setRecordsToOpen(records, PickingConstants.WINDOWID_PickingView.toInt());

return MSG_OK;
}

private ProcessPreconditionsResolution verifySelectedDocuments()
{
final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();

final DocumentIdsSelection selectedRowIds = getSelectedRootDocumentIds();
if (selectedRowIds.isEmpty())
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

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

final boolean hasNonIntegerIds = selectedRowIds.stream().anyMatch(rowId -> !rowId.isInt());
if (hasNonIntegerIds)
final long selectionSize = getSelectionSize(selectedRowIds);
if (selectionSize > MAX_ROWS_ALLOWED)
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_WEBUI_PICKING_CANNOT_PICK_INCLUDED_ROWS));
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_WEBUI_PICKING_TOO_MANY_PACKAGEABLES_1P, MAX_ROWS_ALLOWED));
}

if (selectedRowIds.size() > 1)
// Make sure that they all have the same C_BPartner and location.
if (selectionSize > 1)
{
// make sure that they all have the same C_BPartner and location.
final Set<Integer> flatMap = getView().streamByIds(selectedRowIds)
final Set<Integer> bpartnerLocationIds = getView().streamByIds(selectedRowIds)
.flatMap(selectedRow -> selectedRow.getIncludedRows().stream())
.map(row -> getBPartnerLocationId(row))
.map(this::getBPartnerLocationId)
.collect(Collectors.toSet());
if (flatMap.size() > 1)
if (bpartnerLocationIds.size() > 1)
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText(MSG_WEBUI_PICKING_DIVERGING_LOCATIONS));
}
Expand All @@ -128,4 +120,33 @@ private int getBPartnerLocationId(@NonNull final IViewRow row)
return jsonLookupValue.getKeyAsInt();
}

private long getSelectionSize(final DocumentIdsSelection rowIds)
{
if (rowIds.isAll())
{
return getView().size();
}
else
{
return rowIds.size();
}
}

private DocumentIdsSelection getSelectedRootDocumentIds()
{
final DocumentIdsSelection selectedRowIds = getSelectedDocumentIds();
if (selectedRowIds.isAll())
{
return selectedRowIds;
}
else if (selectedRowIds.isEmpty())
{
return selectedRowIds;
}
else
{
return selectedRowIds.stream().filter(DocumentId::isInt).collect(DocumentIdsSelection.toDocumentIdsSelection());
}
}

}

0 comments on commit aeb98e6

Please sign in to comment.