From fef50fce380df395e43fb88456e0941821c7740f Mon Sep 17 00:00:00 2001 From: Teo Sarca Date: Sat, 4 Mar 2017 15:24:29 +0200 Subject: [PATCH] #208 WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam also refactored WEBUI_M_ReceiptSchedule_ReceiveCUs --- ...> WEBUI_M_ReceiptSchedule_ReceiveCUs.java} | 59 ++++++++++--- ..._ReceiptSchedule_ReceiveCUs_WithParam.java | 84 +++++++++++++++++++ 2 files changed, 130 insertions(+), 13 deletions(-) rename metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/{WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_MultiRow.java => WEBUI_M_ReceiptSchedule_ReceiveCUs.java} (77%) create mode 100644 metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam.java diff --git a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_MultiRow.java b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs.java similarity index 77% rename from metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_MultiRow.java rename to metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs.java index 39ab4a445..6ab432b07 100644 --- a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_MultiRow.java +++ b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs.java @@ -2,6 +2,7 @@ import java.math.BigDecimal; import java.util.List; +import java.util.stream.Stream; import org.adempiere.ad.trx.api.ITrx; import org.adempiere.model.InterfaceWrapperHelper; @@ -66,12 +67,25 @@ * */ @Profile(WebRestApiApplication.PROFILE_Webui) -public class WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_MultiRow extends JavaProcess implements IProcessPrecondition +public class WEBUI_M_ReceiptSchedule_ReceiveCUs extends JavaProcess implements IProcessPrecondition { private final transient IHUReceiptScheduleBL huReceiptScheduleBL = Services.get(IHUReceiptScheduleBL.class); private final transient IReceiptScheduleBL receiptScheduleBL = Services.get(IReceiptScheduleBL.class); private final transient IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class); + private boolean allowMultipleReceiptsSchedules = true; // by default we shall allow multiple lines + private boolean allowNoQuantityAvailable = false; // by default we shall not allow lines which have no quantity available + + protected final void setAllowMultipleReceiptsSchedules(final boolean allowMultipleReceiptsSchedules) + { + this.allowMultipleReceiptsSchedules = allowMultipleReceiptsSchedules; + } + + protected final void setAllowNoQuantityAvailable(final boolean allowNoQuantityAvailable) + { + this.allowNoQuantityAvailable = allowNoQuantityAvailable; + } + @Override public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProcessPreconditionsContext context) { @@ -86,13 +100,20 @@ public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProces // return ProcessPreconditionsResolution.rejectWithInternalReason("select more than one row"); // } + // + // Check if we are allowed to select multiple lines + if (!allowMultipleReceiptsSchedules && context.getSelectionSize() > 1) + { + return ProcessPreconditionsResolution.rejectWithInternalReason("select only one line"); + } + // // Fetch the receipt schedules which have some qty available for receiving final List receiptSchedules = context.getSelectedModels(I_M_ReceiptSchedule.class) .stream() - .filter(receiptSchedule -> getAvailableQtyToReceive(receiptSchedule).signum() > 0) + .filter(receiptSchedule -> allowNoQuantityAvailable || getDefaultAvailableQtyToReceive(receiptSchedule).signum() > 0) .collect(ImmutableList.toImmutableList()); - if(receiptSchedules.isEmpty()) + if (receiptSchedules.isEmpty()) { return ProcessPreconditionsResolution.reject("nothing to receive"); } @@ -100,7 +121,7 @@ public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProces // // Make sure each of them are eligible for receiving { - ProcessPreconditionsResolution rejectResolution = receiptSchedules.stream() + final ProcessPreconditionsResolution rejectResolution = receiptSchedules.stream() .map(receiptSchedule -> WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_Base.checkEligibleForReceivingHUs(receiptSchedule)) .filter(resolution -> !resolution.isAccepted()) .findFirst() @@ -130,14 +151,12 @@ public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProces // return ProcessPreconditionsResolution.accept(); } - + @Override @RunOutOfTrx - protected String doIt() throws Exception + protected final String doIt() throws Exception { - final List hus = retrieveSelectedRecordsQueryBuilder(I_M_ReceiptSchedule.class) - .create() - .stream(I_M_ReceiptSchedule.class) + final List hus = streamReceiptSchedulesToReceive() .map(this::createPlanningVHU) .filter(hu -> hu != null) .collect(GuavaCollectors.toImmutableList()); @@ -147,6 +166,13 @@ protected String doIt() throws Exception return MSG_OK; } + protected Stream streamReceiptSchedulesToReceive() + { + return retrieveSelectedRecordsQueryBuilder(I_M_ReceiptSchedule.class) + .create() + .stream(I_M_ReceiptSchedule.class); + } + private I_M_HU createPlanningVHU(final I_M_ReceiptSchedule receiptSchedule) { // @@ -188,17 +214,24 @@ private I_M_HU createPlanningVHU(final I_M_ReceiptSchedule receiptSchedule) InterfaceWrapperHelper.setTrxName(vhu, ITrx.TRXNAME_None); return vhu; } + + protected final BigDecimal getDefaultAvailableQtyToReceive(final I_M_ReceiptSchedule rs) + { + final BigDecimal qty = receiptScheduleBL.getQtyToMove(rs); + return qty == null || qty.signum() <= 0 ? BigDecimal.ZERO : qty; + } - private final BigDecimal getAvailableQtyToReceive(final I_M_ReceiptSchedule rs) + protected BigDecimal getEffectiveQtyToReceive(final I_M_ReceiptSchedule rs) { - return receiptScheduleBL.getQtyToMove(rs); + BigDecimal defaultAvailableQtyToReceive = getDefaultAvailableQtyToReceive(rs); + return defaultAvailableQtyToReceive; } private final IAllocationRequest createAllocationRequest(final I_M_ReceiptSchedule rs) { // Get Qty - final BigDecimal qty = getAvailableQtyToReceive(rs); - if (qty == null || qty.signum() <= 0) + final BigDecimal qty = getEffectiveQtyToReceive(rs); + if (qty.signum() <= 0) { // nothing to do return null; diff --git a/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam.java b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam.java new file mode 100644 index 000000000..8ed97c4a0 --- /dev/null +++ b/metasfresh-webui-api/src/main/java/de/metas/ui/web/handlingunits/process/WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam.java @@ -0,0 +1,84 @@ +package de.metas.ui.web.handlingunits.process; + +import java.math.BigDecimal; +import java.util.stream.Stream; + +import org.adempiere.exceptions.FillMandatoryException; + +import de.metas.handlingunits.model.I_M_ReceiptSchedule; +import de.metas.process.IProcessDefaultParameter; +import de.metas.process.IProcessDefaultParametersProvider; +import de.metas.process.Param; + +/* + * #%L + * metasfresh-webui-api + * %% + * Copyright (C) 2017 metas GmbH + * %% + * This program is free software: you can redistribute it and/or modify + * 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 + * . + * #L% + */ + +public class WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam extends WEBUI_M_ReceiptSchedule_ReceiveCUs implements IProcessDefaultParametersProvider +{ + private static final String PARAM_QtyCU = "QtyCU"; + @Param(parameterName = PARAM_QtyCU, mandatory = true) + private BigDecimal p_QtyCU; + + public WEBUI_M_ReceiptSchedule_ReceiveCUs_WithParam() + { + super(); + + // configure defaults + setAllowMultipleReceiptsSchedules(false); + setAllowNoQuantityAvailable(true); + } + + @Override + public Object getParameterDefaultValue(final IProcessDefaultParameter parameter) + { + if (PARAM_QtyCU.equals(parameter.getColumnName())) + { + final I_M_ReceiptSchedule receiptSchedule = getM_ReceiptSchedule(); + return getDefaultAvailableQtyToReceive(receiptSchedule); + } + else + { + return DEFAULT_VALUE_NOTAVAILABLE; + } + } + + @Override + protected Stream streamReceiptSchedulesToReceive() + { + return Stream.of(getM_ReceiptSchedule()); + } + + private I_M_ReceiptSchedule getM_ReceiptSchedule() + { + return getRecord(I_M_ReceiptSchedule.class); + } + + @Override + protected BigDecimal getEffectiveQtyToReceive(I_M_ReceiptSchedule rs) + { + if(p_QtyCU == null || p_QtyCU.signum() <= 0) + { + throw new FillMandatoryException(PARAM_QtyCU); + } + return p_QtyCU; + } +}