use of de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow in project metasfresh-webui-api by metasfresh.
the class WEBUI_SalesOrder_Apply_Availability_Row method extractLineRow2availabilityRows.
private Multimap<PurchaseRow, PurchaseRow> extractLineRow2availabilityRows() {
final PurchaseView view = getView();
final ListMultimap<PurchaseRow, PurchaseRow> lineRow2AvailabilityRows = getSelectedRowIds().stream().map(// map to PurchaseRowIds
PurchaseRowId::fromDocumentId).filter(PurchaseRowId::isAvailabilityRowId).filter(availabilityRowId -> availabilityRowId.getAvailabilityType().equals(Type.AVAILABLE)).map(availabilityRowId -> // map to pair (availabilityRowId, availabilityRow)
ImmutablePair.of(availabilityRowId, view.getById(availabilityRowId.toDocumentId()))).filter(availabilityRowId2row -> Util.coalesce(availabilityRowId2row.getRight().getQtyToPurchase(), BigDecimal.ZERO).signum() > 0).map(availabilityRowId2row -> // map to pair (lineRow, availabilityRow)
ImmutablePair.of(view.getById(availabilityRowId2row.getLeft().toLineRowId().toDocumentId()), availabilityRowId2row.getRight())).filter(lineRow2availabilityRow -> !lineRow2availabilityRow.getLeft().isProcessed()).collect(Multimaps.toMultimap(IPair::getLeft, IPair::getRight, MultimapBuilder.hashKeys().arrayListValues()::build));
return ImmutableMultimap.copyOf(lineRow2AvailabilityRows);
}
use of de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow in project metasfresh-webui-api by metasfresh.
the class WEBUI_SalesOrder_Apply_Availability_Row method doIt.
@Override
protected String doIt() throws Exception {
final //
Multimap<PurchaseRow, PurchaseRow> lineRows2availabilityRows = extractLineRow2availabilityRows();
Check.errorIf(hasMultipleAvailabilityRowsPerLineRow(lineRows2availabilityRows), "The selected rows contain > 1 availability row for one line row; lineRows2availabilityRows={}", lineRows2availabilityRows);
final Set<DocumentId> documentIdsToUpdate = new HashSet<>();
for (final Entry<PurchaseRow, PurchaseRow> lineRow2availabilityRow : lineRows2availabilityRows.entries()) {
final DocumentId groupRowDocumentId = updateLineAndGroupRow(lineRow2availabilityRow);
documentIdsToUpdate.add(groupRowDocumentId);
}
ViewChangesCollector.getCurrentOrAutoflush().collectRowsChanged(getView(), DocumentIdsSelection.of(documentIdsToUpdate));
return MSG_OK;
}
use of de.metas.ui.web.order.sales.purchasePlanning.view.PurchaseRow in project metasfresh-webui-api by metasfresh.
the class WEBUI_SalesOrder_Apply_Availability_Row method updateLineAndGroupRow.
public DocumentId updateLineAndGroupRow(@NonNull final Entry<PurchaseRow, PurchaseRow> lineRow2availabilityRow) {
final PurchaseRow lineRow = lineRow2availabilityRow.getKey();
final PurchaseRowId lineRowId = PurchaseRowId.fromDocumentId(lineRow.getId());
final DocumentId groupRowDocumentId = lineRowId.toGroupRowId().toDocumentId();
final PurchaseRow groupRow = getView().getById(groupRowDocumentId);
final PurchaseRow availabilityRow = lineRow2availabilityRow.getValue();
if (availabilityRow.getDatePromised() != null) {
groupRow.changeDatePromised(lineRowId, availabilityRow.getDatePromised());
}
groupRow.changeQtyToPurchase(lineRowId, availabilityRow.getQtyToPurchase());
return groupRowDocumentId;
}
Aggregations