Skip to content

Commit

Permalink
shipment candidates view: save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Aug 23, 2019
1 parent 676890a commit 20fb452
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 10 deletions.
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ShipmentCandidateRow> values;

Expand All @@ -89,17 +94,23 @@ 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;
this.customer = customer;
this.warehouse = warehouse;
this.product = product;
this.preparationDate = preparationDate;

this.qtyToDeliverInitial = qtyToDeliverInitial;
this.qtyToDeliver = qtyToDeliver;

this.asiIdInitial = asiIdInitial;
this.asi = asi;

this.shipmentScheduleId = shipmentScheduleId;
Expand Down Expand Up @@ -172,4 +183,29 @@ public WebuiASIEditingInfo getWebuiASIEditingInfo(@NonNull final AttributeSetIns

return WebuiASIEditingInfo.builder(info).build();
}

Optional<ShipmentScheduleUserChangeRequest> 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();
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -46,6 +51,11 @@

final class ShipmentCandidateRows implements IEditableRowsData<ShipmentCandidateRow>
{
public static ShipmentCandidateRows cast(final IRowsData<ShipmentCandidateRow> rowsData)
{
return (ShipmentCandidateRows)rowsData;
}

private final ImmutableList<DocumentId> rowIds; // used to preserve the order
private final ConcurrentHashMap<DocumentId, ShipmentCandidateRow> rowsById;

Expand All @@ -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());

Expand Down Expand Up @@ -132,4 +142,16 @@ private void changeRow(
});
}

Optional<ShipmentScheduleUserChangeRequestsList> createShipmentScheduleUserChangeRequestsList()
{
final ImmutableList<ShipmentScheduleUserChangeRequest> 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();
}
}
Expand Up @@ -92,6 +92,7 @@ public ShipmentCandidateRows getByShipmentScheduleIds(final Set<ShipmentSchedule
private ShipmentCandidateRow toShipmentCandidateRow(@NonNull final I_M_ShipmentSchedule record)
{
final Quantity qtyToDeliver = extractQtyToDeliver(record);
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(record.getM_AttributeSetInstance_ID());

return ShipmentCandidateRow.builder()
.shipmentScheduleId(ShipmentScheduleId.ofRepoId(record.getM_ShipmentSchedule_ID()))
Expand All @@ -100,9 +101,13 @@ private ShipmentCandidateRow toShipmentCandidateRow(@NonNull final I_M_ShipmentS
.warehouse(extractWarehouse(record))
.product(extractProduct(record))
.preparationDate(extractPreparationTime(record))
//
.qtyToDeliverInitial(qtyToDeliver)
.qtyToDeliver(qtyToDeliver.getAsBigDecimal())
.asi(extractASI(record))
//
.asiIdInitial(asiId)
.asi(toLookupValue(asiId))
//
.build();
}

Expand Down Expand Up @@ -132,9 +137,8 @@ private LookupValue extractProduct(@NonNull final I_M_ShipmentSchedule record)
return productsLookup.findById(productId);
}

private LookupValue extractASI(@NonNull final I_M_ShipmentSchedule record)
private LookupValue toLookupValue(@NonNull final AttributeSetInstanceId asiId)
{
final AttributeSetInstanceId asiId = AttributeSetInstanceId.ofRepoIdOrNone(record.getM_AttributeSetInstance_ID());
return asiId.isRegular()
? asiLookup.findById(asiId)
: IntegerLookupValue.of(asiId.getRepoId(), "");
Expand Down
Expand Up @@ -3,12 +3,16 @@
import javax.annotation.Nullable;

import de.metas.i18n.ITranslatableString;
import de.metas.inoutcandidate.api.IShipmentScheduleBL;
import de.metas.inoutcandidate.api.ShipmentScheduleUserChangeRequestsList;
import de.metas.ui.web.document.filter.provider.NullDocumentFilterDescriptorsProvider;
import de.metas.ui.web.view.AbstractCustomView;
import de.metas.ui.web.view.IEditableView;
import de.metas.ui.web.view.ViewCloseReason;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.LookupValuesList;
import de.metas.util.Services;
import lombok.Builder;
import lombok.NonNull;

Expand Down Expand Up @@ -54,14 +58,28 @@ public String getTableNameOrNull(final DocumentId documentId)
@Override
public LookupValuesList getFieldTypeahead(final RowEditingContext ctx, final String fieldName, final String query)
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

@Override
public LookupValuesList getFieldDropdown(final RowEditingContext ctx, final String fieldName)
{
// TODO Auto-generated method stub
throw new UnsupportedOperationException();
}

@Override
protected ShipmentCandidateRows getRowsData()
{
return ShipmentCandidateRows.cast(super.getRowsData());
}

@Override
public void close(final ViewCloseReason reason)
{
final ShipmentScheduleUserChangeRequestsList userChanges = getRowsData().createShipmentScheduleUserChangeRequestsList().orElse(null);
if (userChanges != null)
{
Services.get(IShipmentScheduleBL.class).applyUserChanges(userChanges);
}
}
}
Expand Up @@ -7,6 +7,7 @@
import de.metas.inoutcandidate.api.ShipmentScheduleId;
import de.metas.ui.web.view.CreateViewRequest;
import de.metas.ui.web.view.IViewFactory;
import de.metas.ui.web.view.ViewCloseAction;
import de.metas.ui.web.view.ViewFactory;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.view.ViewProfileId;
Expand Down Expand Up @@ -61,8 +62,8 @@ public ViewLayout getViewLayout(WindowId windowId, JSONViewDataType viewDataType
.setWindowId(WINDOWID)
.setCaption(Services.get(IMsgBL.class).translatable("M_ShipmentSchedule_ID"))
.setAllowOpeningRowDetails(false)
// .allowViewCloseAction(ViewCloseAction.CANCEL)
// .setFilters(getFilterDescriptorsProvider().getAll())
.allowViewCloseAction(ViewCloseAction.CANCEL)
.allowViewCloseAction(ViewCloseAction.DONE)
.addElementsFromViewRowClass(ShipmentCandidateRow.class, viewDataType)
.build();
}
Expand All @@ -79,7 +80,6 @@ public ShipmentCandidatesView createView(@NonNull final CreateViewRequest reques
return ShipmentCandidatesView.builder()
.viewId(viewId)
.rows(rows)
// .relatedProcessDescriptors(getRelatedProcessDescriptors())
.build();
}

Expand Down

0 comments on commit 20fb452

Please sign in to comment.