Skip to content

Commit

Permalink
#207 Prohibit Material Receipt w/ selection of multi BP
Browse files Browse the repository at this point in the history
also allow receiving CUs for only one selected line
  • Loading branch information
teosarca committed Mar 4, 2017
1 parent 1c62727 commit 58dec77
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,22 @@ public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProces
return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
}

final IReceiptScheduleBL receiptScheduleBL = Services.get(IReceiptScheduleBL.class);
final I_M_ReceiptSchedule receiptSchedule = context.getSelectedModel(I_M_ReceiptSchedule.class);

// guard against null (might happen if the selected ID is not valid)
if(receiptSchedule == null)
{
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

return checkEligibleForReceivingHUs(receiptSchedule);
}

/** @return true if given receipt schedule is eligible for receiving HUs */
public static final ProcessPreconditionsResolution checkEligibleForReceivingHUs(final I_M_ReceiptSchedule receiptSchedule)
{
// Receipt schedule shall not be already closed
final I_M_ReceiptSchedule receiptSchedule = context.getSelectedModel(I_M_ReceiptSchedule.class);
final IReceiptScheduleBL receiptScheduleBL = Services.get(IReceiptScheduleBL.class);
if (receiptScheduleBL.isClosed(receiptSchedule))
{
return ProcessPreconditionsResolution.reject("receipt schedule closed");
Expand All @@ -77,6 +89,7 @@ public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProces
}

return ProcessPreconditionsResolution.accept();

}

protected static I_M_HU_LUTU_Configuration getCurrentLUTUConfiguration(final I_M_ReceiptSchedule receiptSchedule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,62 @@ public class WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_MultiRow extends JavaPr
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(final IProcessPreconditionsContext context)
{
if (context.getSelectionSize() <= 1)
if (context.isNoSelection())
{
return ProcessPreconditionsResolution.rejectWithInternalReason("select more than one row");
return ProcessPreconditionsResolution.rejectBecauseNoSelection();
}

// TODO: make sure all rows are for same BPartner

// NOTE: we shall allow one line only
// if (context.getSelectionSize() <= 1)
// {
// return ProcessPreconditionsResolution.rejectWithInternalReason("select more than one row");
// }

//
// Fetch the receipt schedules which have some qty available for receiving
final List<I_M_ReceiptSchedule> receiptSchedules = context.getSelectedModels(I_M_ReceiptSchedule.class)
.stream()
.filter(receiptSchedule -> getAvailableQtyToReceive(receiptSchedule).signum() > 0)
.collect(ImmutableList.toImmutableList());
if(receiptSchedules.isEmpty())
{
return ProcessPreconditionsResolution.reject("nothing to receive");
}

//
// Make sure each of them are eligible for receiving
{
ProcessPreconditionsResolution rejectResolution = receiptSchedules.stream()
.map(receiptSchedule -> WEBUI_M_ReceiptSchedule_GeneratePlanningHUs_Base.checkEligibleForReceivingHUs(receiptSchedule))
.filter(resolution -> !resolution.isAccepted())
.findFirst()
.orElse(null);
if (rejectResolution != null)
{
return rejectResolution;
}
}

//
// If more than one line selected, make sure the lines make sense together
// * enforce same BPartner (task https://github.com/metasfresh/metasfresh-webui/issues/207)
if (receiptSchedules.size() > 1)
{
final long bpartnersCount = receiptSchedules
.stream()
.map(receiptSchedule -> receiptScheduleBL.getC_BPartner_Effective_ID(receiptSchedule))
.distinct()
.count();
if (bpartnersCount != 1)
{
return ProcessPreconditionsResolution.reject("select only one BPartner");
}
}

//
return ProcessPreconditionsResolution.accept();
}

@Override
@RunOutOfTrx
protected String doIt() throws Exception
Expand Down Expand Up @@ -142,11 +188,16 @@ private I_M_HU createPlanningVHU(final I_M_ReceiptSchedule receiptSchedule)
InterfaceWrapperHelper.setTrxName(vhu, ITrx.TRXNAME_None);
return vhu;
}

private final BigDecimal getAvailableQtyToReceive(final I_M_ReceiptSchedule rs)
{
return receiptScheduleBL.getQtyToMove(rs);
}

private final IAllocationRequest createAllocationRequest(final I_M_ReceiptSchedule rs)
{
// Get Qty
final BigDecimal qty = receiptScheduleBL.getQtyToMove(rs);
final BigDecimal qty = getAvailableQtyToReceive(rs);
if (qty == null || qty.signum() <= 0)
{
// nothing to do
Expand Down

1 comment on commit 58dec77

@teosarca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fixes #206

Please sign in to comment.