Skip to content

Commit

Permalink
Provide selected receipt schedules to HUTransferService
Browse files Browse the repository at this point in the history
FRESH-1504 #181 Transforming HU in Handling Unit Editor
  • Loading branch information
metas-ts committed Mar 14, 2017
1 parent 75afffa commit ae656ee
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.exceptions.FillMandatoryException;
import org.adempiere.model.InterfaceWrapperHelper;
import org.adempiere.util.GuavaCollectors;
import org.adempiere.util.Services;
import org.adempiere.util.StringUtils;
import org.adempiere.util.lang.impl.TableRecordReference;
import org.compiere.Adempiere;
import org.compiere.model.I_AD_Process_Para;
import org.compiere.model.I_AD_Ref_List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

import de.metas.handlingunits.IHUPIItemProductDAO;
Expand All @@ -43,6 +46,7 @@
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue;
import de.metas.ui.web.window.datatypes.LookupValuesList;
import de.metas.ui.web.window.model.DocumentCollection;

/*
* #%L
Expand Down Expand Up @@ -184,6 +188,9 @@ public static enum ActionType
@Param(parameterName = PARAM_HUPlanningReceiptOwnerPM_TU)
private boolean p_HUPlanningReceiptOwnerPM_TU;

@Autowired
private DocumentCollection documentsCollection;

public WEBUI_M_HU_Transform()
{
Adempiere.autowire(this);
Expand Down Expand Up @@ -299,7 +306,6 @@ protected String doIt() throws Exception
throw new AdempiereException("@Unknown@ @Action@ " + action);
}
}

return MSG_OK;
}

Expand All @@ -316,6 +322,14 @@ private void updatePlanningReceiptOwnerPM(final HUDocumentView row, final boolea
InterfaceWrapperHelper.save(hu);
}

private List<TableRecordReference> getM_ReceiptSchedules()
{
return getView()
.getReferencingDocumentPaths().stream()
.map(referencingDocumentPath -> documentsCollection.getTableRecordReference(referencingDocumentPath))
.collect(GuavaCollectors.toImmutableList());
}

/**
* Split selected CU to an existing TU.
*
Expand All @@ -326,6 +340,7 @@ private void updatePlanningReceiptOwnerPM(final HUDocumentView row, final boolea
private void action_SplitCU_To_ExistingTU(final HUDocumentView cuRow, final I_M_HU tuHU, final BigDecimal qtyCU)
{
HUTransferService.get(getCtx())
.withReferencedObjects(getM_ReceiptSchedules())
.cuToExistingTU(cuRow.getM_HU(), qtyCU, tuHU);

// Notify
Expand All @@ -340,8 +355,10 @@ private void action_SplitCU_To_ExistingTU(final HUDocumentView cuRow, final I_M_
*/
private void action_SplitCU_To_NewCU(final HUDocumentView cuRow, final BigDecimal qtyCU)
{

// TODO: if qtyCU is the "maximum", then don't do anything, but show a user message
final List<I_M_HU> createdHUs = HUTransferService.get(getCtx())
.withReferencedObjects(getM_ReceiptSchedules())
.cuToNewCU(cuRow.getM_HU(), qtyCU);

// Notify
Expand All @@ -363,6 +380,7 @@ private void action_SplitCU_To_NewTUs(
final boolean isOwnPackingMaterials)
{
final List<I_M_HU> createdHUs = HUTransferService.get(getCtx())
.withReferencedObjects(getM_ReceiptSchedules())
.cuToNewTUs(cuRow.getM_HU(), qtyCU, tuPIItemProduct, isOwnPackingMaterials);

// Notify
Expand All @@ -378,6 +396,7 @@ private void action_SplitTU_To_ExistingLU(
final BigDecimal qtyTU)
{
HUTransferService.get(getCtx())
.withReferencedObjects(getM_ReceiptSchedules())
.tuToExistingLU(tuRow.getM_HU(), qtyTU, luHU);

// Notify
Expand All @@ -400,6 +419,7 @@ private void action_SplitTU_To_NewLU(
final boolean isOwnPackingMaterials)
{
final List<I_M_HU> createdHUs = HUTransferService.get(getCtx())
.withReferencedObjects(getM_ReceiptSchedules())
.tuToNewLUs(tuRow.getM_HU(), qtyTU, huPIItem, isOwnPackingMaterials);

// Notify
Expand All @@ -421,6 +441,7 @@ private void action_SplitTU_To_NewTUs(
final I_M_HU sourceTuHU = tuRow.getM_HU();

final List<I_M_HU> createdHUs = HUTransferService.get(getCtx())
.withReferencedObjects(getM_ReceiptSchedules())
.tuToNewTUs(sourceTuHU, qtyTU, sourceTuHU.isHUPlanningReceiptOwnerPM());

// Notify
Expand Down

0 comments on commit ae656ee

Please sign in to comment.