use of de.metas.handlingunits.inout.ReceiptCorrectHUsProcessor in project metasfresh-webui-api by metasfresh.
the class WEBUI_M_HU_ReverseReceipt method doIt.
@Override
@RunOutOfTrx
protected String doIt() throws Exception {
final List<I_M_ReceiptSchedule> receiptSchedules = getM_ReceiptSchedules();
final List<Integer> huIdsToReverse = retrieveHUsToReverse();
boolean hasChanges = false;
try {
for (final I_M_ReceiptSchedule receiptSchedule : receiptSchedules) {
final ReceiptCorrectHUsProcessor processor = ReceiptCorrectHUsProcessor.builder().setM_ReceiptSchedule(receiptSchedule).tolerateNoHUsFound().build();
if (processor.isNoHUsFound()) {
continue;
}
final List<I_M_InOut> receiptsToReverse = processor.getReceiptsToReverseFromHUIds(huIdsToReverse);
if (receiptsToReverse.isEmpty()) {
continue;
}
processor.reverseReceipts(receiptsToReverse);
hasChanges = true;
}
} finally {
if (hasChanges) {
// Reset the view's affected HUs
getView().removeHUIdsAndInvalidate(huIdsToReverse);
// Notify all active views that given receipt schedules were changed
viewsRepo.notifyRecordsChanged(TableRecordReference.ofSet(receiptSchedules));
}
}
if (!hasChanges) {
throw new AdempiereException("@NotFound@ @M_InOut_ID@");
}
return MSG_OK;
}
Aggregations