Skip to content

Commit

Permalink
fix: cannot reverse an issued HU
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed May 18, 2017
1 parent 390d739 commit 4bee39e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 38 deletions.
56 changes: 34 additions & 22 deletions src/main/java/de/metas/ui/web/pporder/PPOrderLineRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import java.util.function.Supplier;

import org.adempiere.model.InterfaceWrapperHelper;
import org.adempiere.util.Check;
import org.compiere.model.I_C_UOM;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.handlingunits.WEBUI_HU_Constants;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.IViewRowAttributes;
import de.metas.ui.web.window.datatypes.DocumentId;
Expand Down Expand Up @@ -50,9 +50,9 @@
@ToString
public class PPOrderLineRow implements IViewRow, IPPOrderBOMLine
{
public static final Builder builder(final WindowId windowId)
public static final Builder builder(final WindowId viewWindowId, final DocumentId rowId)
{
return new Builder(windowId);
return new Builder(viewWindowId, rowId);
}

public static final PPOrderLineRow cast(final IViewRow viewRecord)
Expand All @@ -72,6 +72,7 @@ public static final PPOrderLineRow cast(final IViewRow viewRecord)
private final int ppOrderId;
private final int ppOrderBOMLineId;
private final int ppOrderQtyId;
private final int huId;

private final ImmutableMap<String, Object> values;
private final JSONLookupValue product;
Expand All @@ -90,6 +91,7 @@ private PPOrderLineRow(final Builder builder)
ppOrderId = builder.ppOrderId;
ppOrderBOMLineId = builder.ppOrderBOMLineId;
ppOrderQtyId = builder.ppOrderQtyId;
huId = builder.huId;

processed = builder.processed;

Expand Down Expand Up @@ -128,6 +130,22 @@ public DocumentPath getDocumentPath()
return documentPath;
}

/**
* The effective document path of this row.
* i.e. in case HUs that will be "HU's window" and "M_HU_ID".
*/
public DocumentPath getDocumentPathEffective()
{
if (huId > 0)
{
return DocumentPath.rootDocumentPath(WEBUI_HU_Constants.WEBUI_HU_Window_ID, DocumentId.of(huId));
}
else
{
return getDocumentPath();
}
}

@Override
public DocumentId getId()
{
Expand Down Expand Up @@ -246,8 +264,8 @@ public IViewRowAttributes getAttributes() throws EntityNotFoundException
//
public static final class Builder
{
private final WindowId windowId;
private DocumentId _rowId;
private final WindowId viewWindowId;
private final DocumentId rowId;
private PPOrderLineType type;

private List<PPOrderLineRow> includedDocuments = null;
Expand All @@ -257,6 +275,7 @@ public static final class Builder
private int ppOrderId;
private int ppOrderBOMLineId;
private int ppOrderQtyId;
private int huId;
private boolean processed = false;

private JSONLookupValue product;
Expand All @@ -267,9 +286,10 @@ public static final class Builder
private BigDecimal qty;
private boolean qtyAsSumOfIncludedQtys = false;

private Builder(@NonNull final WindowId windowId)
private Builder(@NonNull final WindowId viewWindowId, @NonNull final DocumentId rowId)
{
this.windowId = windowId;
this.viewWindowId = viewWindowId;
this.rowId = rowId;
}

public PPOrderLineRow build()
Expand Down Expand Up @@ -320,29 +340,21 @@ public Builder ppOrderQtyId(final int ppOrderQtyId)
return this;
}

public Builder processed(final boolean processed)
public Builder huId(final int huId)
{
this.processed = processed;
this.huId = huId;
return this;
}

private DocumentPath getDocumentPath()
{
final DocumentId rowId = getRowId();
return DocumentPath.rootDocumentPath(windowId, rowId);
}

public Builder setRowId(final DocumentId rowId)
public Builder processed(final boolean processed)
{
_rowId = rowId;
this.processed = processed;
return this;
}

/** @return view row ID */
private DocumentId getRowId()
private DocumentPath getDocumentPath()
{
Check.assumeNotNull(_rowId, "Parameter rowId is not null");
return _rowId;
return DocumentPath.rootDocumentPath(viewWindowId, rowId);
}

private PPOrderLineType getType()
Expand Down Expand Up @@ -473,7 +485,7 @@ public <T> Builder addIncludedDocumentFrom(final Collection<T> includedDocObjs,
includedDocObjs.stream()
.map(includedDocumentMapper)
.forEach(this::addIncludedDocument);

return this;
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/java/de/metas/ui/web/pporder/PPOrderLinesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@

public class PPOrderLinesLoader
{
public static final PPOrderLinesLoaderBuilder builder(final WindowId windowId)
public static final PPOrderLinesLoaderBuilder builder(final WindowId viewWindowId)
{
return new PPOrderLinesLoaderBuilder().windowId(windowId);
return new PPOrderLinesLoaderBuilder().viewWindowId(viewWindowId);
}

//
Expand All @@ -78,22 +78,22 @@ public static final PPOrderLinesLoaderBuilder builder(final WindowId windowId)
private final transient IHUPPOrderBL huPPOrderBL = Services.get(IHUPPOrderBL.class);

//
private final WindowId windowId;
private final WindowId viewWindowId;
private final transient HUEditorViewRepository huEditorRepo;
private final HUEditorRowAttributesProvider huAttributesProvider;
private final ASIViewRowAttributesProvider asiAttributesProvider;

@Builder
public PPOrderLinesLoader(final WindowId windowId, final ASIViewRowAttributesProvider asiAttributesProvider)
public PPOrderLinesLoader(final WindowId viewWindowId, final ASIViewRowAttributesProvider asiAttributesProvider)
{
this.windowId = windowId;
this.viewWindowId = viewWindowId;

huAttributesProvider = HUEditorRowAttributesProvider.builder()
.readonly(false)
.build();

huEditorRepo = HUEditorViewRepository.builder()
.windowId(windowId)
.windowId(viewWindowId)
.referencingTableName(I_PP_Order.Table_Name)
.attributesProvider(huAttributesProvider)
.build();
Expand Down Expand Up @@ -166,8 +166,7 @@ private PPOrderLineRow createForMainProduct(final I_PP_Order ppOrder, final bool
final BigDecimal qtyPlan = ppOrder.getQtyOrdered();
final I_M_HU_LUTU_Configuration lutuConfig = huPPOrderBL.createReceiptLUTUConfigurationManager(ppOrder).getCreateLUTUConfiguration();

return PPOrderLineRow.builder(windowId)
.setRowId(documentId)
return PPOrderLineRow.builder(viewWindowId, documentId)
.ppOrder(ppOrder.getPP_Order_ID())
.setType(PPOrderLineType.MainProduct)
.setProcessed(readonly)
Expand Down Expand Up @@ -209,8 +208,7 @@ private PPOrderLineRow createForBOMLine(final I_PP_Order ppOrder, final I_PP_Ord
qtyPlan = ppOrderBOMLine.getQtyRequiered();
}

final PPOrderLineRow.Builder builder = PPOrderLineRow.builder(windowId)
.setRowId(documentId)
final PPOrderLineRow.Builder builder = PPOrderLineRow.builder(viewWindowId, documentId)
.ppOrderBOMLineId(ppOrderBOMLine.getPP_Order_ID(), ppOrderBOMLine.getPP_Order_BOMLine_ID())
.setType(lineType)
.setProcessed(readonly)
Expand Down Expand Up @@ -268,8 +266,8 @@ private PPOrderLineRow createForHUViewRecordRecursivelly(final I_PP_Order_Qty pp
}

//
return PPOrderLineRow.builder(windowId)
.setRowId(huEditorRow.getId())
return PPOrderLineRow.builder(viewWindowId, huEditorRow.getId())
.huId(huEditorRow.getM_HU_ID())
.ppOrderQtyId(ppOrderQty.getPP_Order_Qty_ID())
.processed(readonly || ppOrderQty.isProcessed())
.setType(type)
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/de/metas/ui/web/pporder/PPOrderLinesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ private PPOrderLinesView( //

this.asiAttributesProvider = asiAttributesProvider;

final WindowId windowId = viewId.getWindowId();
dataSupplier = ExtendedMemorizingSupplier.of(() -> PPOrderLinesLoader.builder(windowId)
final WindowId viewWindowId = viewId.getWindowId();
dataSupplier = ExtendedMemorizingSupplier.of(() -> PPOrderLinesLoader.builder(viewWindowId)
.asiAttributesProvider(asiAttributesProvider)
.build()
.retrieveData(ppOrderId));
Expand Down Expand Up @@ -141,7 +141,7 @@ public JSONViewDataType getViewType()
{
return viewType;
}

@Override
public ImmutableSet<DocumentPath> getReferencingDocumentPaths()
{
Expand Down Expand Up @@ -290,6 +290,13 @@ private PPOrderLinesViewData getData()
return dataSupplier.get();
}

@Override
public DocumentPath getDocumentPathEffective(final DocumentId rowId)
{
final PPOrderLineRow row = getData().getById(rowId);
return row.getDocumentPathEffective();
}

@ViewAction(caption = "PPOrderLinesView.openViewsToIssue", precondition = IsSingleIssueLine.class)
public OpenIncludedViewAction actionOpenViewForHUsToIssue(final DocumentIdsSelection selectedDocumentIds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import de.metas.ui.web.process.json.JSONProcessInstanceResult;
import de.metas.ui.web.process.json.JSONProcessLayout;
import de.metas.ui.web.session.UserSession;
import de.metas.ui.web.view.IView;
import de.metas.ui.web.view.IViewsRepository;
import de.metas.ui.web.view.ViewId;
import de.metas.ui.web.window.controller.Execution;
import de.metas.ui.web.window.datatypes.DocumentId;
Expand Down Expand Up @@ -78,6 +80,10 @@ public class ProcessRestController

@Autowired
private UserSession userSession;

@Autowired
private IViewsRepository viewsRepo;


private final ConcurrentHashMap<String, IProcessInstancesRepository> pinstancesRepositoriesByHandlerType = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -151,7 +157,8 @@ public JSONProcessInstance createInstanceFromRequest(@PathVariable("processId")
DocumentPath singleDocumentPath = jsonRequest.getSingleDocumentPath();
if (singleDocumentPath == null && viewDocumentIds.isSingleDocumentId())
{
singleDocumentPath = DocumentPath.rootDocumentPath(viewId.getWindowId(), viewDocumentIds.getSingleDocumentId());
final IView view = viewsRepo.getView(viewId);
singleDocumentPath = view.getDocumentPathEffective(viewDocumentIds.getSingleDocumentId());
}

final CreateProcessInstanceRequest request = CreateProcessInstanceRequest.builder()
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/metas/ui/web/view/IView.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,16 @@ default ViewActionDescriptorsList getActions()
{
return ViewActionDescriptorsList.EMPTY;
}

/**
* Gets row's document path.
* Usually the row's document path consist of view's WindowId and row's ID.
* But there are views which mix data from multiple windows/tables and in that case this method will use row's actual WindowId instead of view's WindowId.
*
* @return row's document path
*/
default DocumentPath getDocumentPathEffective(final DocumentId rowId)
{
return DocumentPath.rootDocumentPath(getViewId().getWindowId(), rowId);
}
}

0 comments on commit 4bee39e

Please sign in to comment.