From 20fb452dfa3377cd4bf4b5a8c7a8c2e394c14684 Mon Sep 17 00:00:00 2001 From: Teo Sarca Date: Sat, 24 Aug 2019 01:07:47 +0300 Subject: [PATCH] shipment candidates view: save changes https://github.com/metasfresh/metasfresh/issues/5440 --- .../ShipmentCandidateRow.java | 38 ++++++++++++++++++- .../ShipmentCandidateRows.java | 24 +++++++++++- .../ShipmentCandidateRowsRepository.java | 10 +++-- .../ShipmentCandidatesView.java | 22 ++++++++++- .../ShipmentCandidatesViewFactory.java | 6 +-- 5 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRow.java b/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRow.java index edae61d21..84b78c863 100644 --- a/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRow.java +++ b/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRow.java @@ -2,6 +2,8 @@ import java.math.BigDecimal; import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.Optional; import java.util.Set; import javax.annotation.Nullable; @@ -11,6 +13,8 @@ import org.adempiere.mm.attributes.util.ASIEditingInfo.WindowType; import de.metas.inoutcandidate.api.ShipmentScheduleId; +import de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequest; +import de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequest.ShipmentScheduleUserChangeRequestBuilder; import de.metas.lang.SOTrx; import de.metas.product.ProductId; import de.metas.quantity.Quantity; @@ -50,7 +54,7 @@ * #L% */ -public class ShipmentCandidateRow implements IViewRow, WebuiASIEditingInfoAware +public final class ShipmentCandidateRow implements IViewRow, WebuiASIEditingInfoAware { @ViewColumn(seqNo = 10, widgetType = DocumentFieldWidgetType.Lookup, captionKey = "C_OrderSO_ID") private final LookupValue salesOrder; @@ -78,6 +82,7 @@ public class ShipmentCandidateRow implements IViewRow, WebuiASIEditingInfoAware private final ShipmentScheduleId shipmentScheduleId; private final DocumentId rowId; private final Quantity qtyToDeliverInitial; + private final AttributeSetInstanceId asiIdInitial; private final ViewRowFieldNameAndJsonValuesHolder values; @@ -89,8 +94,11 @@ private ShipmentCandidateRow( @NonNull final LookupValue warehouse, @NonNull final LookupValue product, @NonNull final ZonedDateTime preparationDate, + // @NonNull final Quantity qtyToDeliverInitial, @NonNull final BigDecimal qtyToDeliver, + // + @NonNull final AttributeSetInstanceId asiIdInitial, @NonNull final LookupValue asi) { this.salesOrder = salesOrder; @@ -98,8 +106,11 @@ private ShipmentCandidateRow( this.warehouse = warehouse; this.product = product; this.preparationDate = preparationDate; + this.qtyToDeliverInitial = qtyToDeliverInitial; this.qtyToDeliver = qtyToDeliver; + + this.asiIdInitial = asiIdInitial; this.asi = asi; this.shipmentScheduleId = shipmentScheduleId; @@ -172,4 +183,29 @@ public WebuiASIEditingInfo getWebuiASIEditingInfo(@NonNull final AttributeSetIns return WebuiASIEditingInfo.builder(info).build(); } + + Optional createShipmentScheduleUserChangeRequest() + { + final ShipmentScheduleUserChangeRequestBuilder builder = ShipmentScheduleUserChangeRequest.builder() + .shipmentScheduleId(shipmentScheduleId); + + boolean changes = false; + + if (qtyToDeliverInitial.getAsBigDecimal().compareTo(qtyToDeliver) != 0) + { + builder.qtyToDeliverOverride(qtyToDeliver); + changes = true; + } + + final AttributeSetInstanceId asiId = asi.getIdAs(AttributeSetInstanceId::ofRepoIdOrNone); + if (!Objects.equals(asiIdInitial, asiId)) + { + builder.asiId(asiId); + changes = true; + } + + return changes + ? Optional.of(builder.build()) + : Optional.empty(); + } } diff --git a/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRows.java b/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRows.java index 2468c7d22..1c9a5b05d 100644 --- a/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRows.java +++ b/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRows.java @@ -2,17 +2,22 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.function.UnaryOperator; import org.adempiere.util.lang.impl.TableRecordReferenceSet; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; +import de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequest; +import de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequestsList; import de.metas.ui.web.exceptions.EntityNotFoundException; import de.metas.ui.web.shipment_candidates_editor.ShipmentCandidateRowUserChangeRequest.ShipmentCandidateRowUserChangeRequestBuilder; import de.metas.ui.web.view.AbstractCustomView.IEditableRowsData; +import de.metas.ui.web.view.AbstractCustomView.IRowsData; import de.metas.ui.web.view.IEditableView.RowEditingContext; import de.metas.ui.web.window.datatypes.DocumentId; import de.metas.ui.web.window.datatypes.DocumentIdsSelection; @@ -46,6 +51,11 @@ final class ShipmentCandidateRows implements IEditableRowsData { + public static ShipmentCandidateRows cast(final IRowsData rowsData) + { + return (ShipmentCandidateRows)rowsData; + } + private final ImmutableList rowIds; // used to preserve the order private final ConcurrentHashMap rowsById; @@ -55,7 +65,7 @@ private ShipmentCandidateRows( { Check.assumeNotEmpty(rows, "rows is not empty"); - this.rowIds = rows.stream() + rowIds = rows.stream() .map(ShipmentCandidateRow::getId) .collect(ImmutableList.toImmutableList()); @@ -132,4 +142,16 @@ private void changeRow( }); } + Optional createShipmentScheduleUserChangeRequestsList() + { + final ImmutableList userChanges = rowsById.values() + .stream() + .map(row -> row.createShipmentScheduleUserChangeRequest().orElse(null)) + .filter(Predicates.notNull()) + .collect(ImmutableList.toImmutableList()); + + return !userChanges.isEmpty() + ? Optional.of(ShipmentScheduleUserChangeRequestsList.of(userChanges)) + : Optional.empty(); + } } diff --git a/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRowsRepository.java b/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRowsRepository.java index 0f889f0dc..c7fc86c29 100644 --- a/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRowsRepository.java +++ b/src/main/java/de/metas/ui/web/shipment_candidates_editor/ShipmentCandidateRowsRepository.java @@ -92,6 +92,7 @@ public ShipmentCandidateRows getByShipmentScheduleIds(final Set