Skip to content

Commit

Permalink
start implementing unprocessing ( not-compiling WIP)
Browse files Browse the repository at this point in the history
commit the current not-compiling WIP

518: Picking prototype (v6) 

Task-Url: #518
  • Loading branch information
metas-ts committed Jul 24, 2017
1 parent d16e780 commit e6713ac
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 16 deletions.
19 changes: 13 additions & 6 deletions src/main/java/de/metas/ui/web/picking/PickingCandidateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import org.adempiere.uom.api.IUOMConversionBL;
import org.adempiere.uom.api.IUOMConversionContext;
import org.adempiere.util.Services;
import org.compiere.model.IQuery;
import org.compiere.model.I_C_UOM;
import org.compiere.model.I_M_Product;
import org.compiere.util.Env;
import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import de.metas.handlingunits.IHUContextFactory;
import de.metas.handlingunits.IHUPickingSlotBL;
import de.metas.handlingunits.IMutableHUContext;
import de.metas.handlingunits.allocation.IAllocationDestination;
import de.metas.handlingunits.allocation.IAllocationRequest;
Expand Down Expand Up @@ -278,15 +280,20 @@ public void setCandidatesClosed(@NonNull final List<Integer> shipmentScheduleIds
{
final IQueryBL queryBL = Services.get(IQueryBL.class);

// note that we only closed "processed" candidates. what's still open shall stay open.
final ICompositeQueryUpdater<I_M_Picking_Candidate> updater = queryBL.createCompositeQueryUpdater(I_M_Picking_Candidate.class)
.addSetColumnValue(I_M_Picking_Candidate.COLUMNNAME_Status, X_M_Picking_Candidate.STATUS_CL);

queryBL.createQueryBuilder(I_M_Picking_Candidate.class)
final IQuery<I_M_Picking_Candidate> query = queryBL.createQueryBuilder(I_M_Picking_Candidate.class)
.addOnlyActiveRecordsFilter()
.addEqualsFilter(I_M_Picking_Candidate.COLUMNNAME_Status, X_M_Picking_Candidate.STATUS_PR)
.addInArrayFilter(I_M_Picking_Candidate.COLUMN_M_ShipmentSchedule_ID, shipmentScheduleIds)
.create()
.updateDirectly(updater);
.create();


final IHUPickingSlotBL huPickingSlotBL = Services.get(IHUPickingSlotBL.class);
huPickingSlotBL.addToPickingSlotQueue(pickingSlot, hu);

final ICompositeQueryUpdater<I_M_Picking_Candidate> updater = queryBL.createCompositeQueryUpdater(I_M_Picking_Candidate.class)
.addSetColumnValue(I_M_Picking_Candidate.COLUMNNAME_Status, X_M_Picking_Candidate.STATUS_CL);
query.updateDirectly(updater);
// note that we only closed "processed" candidates. what's still open shall stay open.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public class WEBUI_Picking_M_Picking_Candidate_Processed
@Autowired
private PickingCandidateCommand pickingCandidateCommand;

private final IHUPickingSlotBL huPickingSlotBL = Services.get(IHUPickingSlotBL.class);

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
Expand Down Expand Up @@ -164,16 +162,10 @@ protected String doIt() throws Exception
.setFromHUs(ImmutableList.of(hu))
.allocate();

huPickingSlotBL.addToPickingSlotQueue(pickingSlot, hu);

pickingCandidateCommand.setCandidatesProcessed(ImmutableList.of(rowToProcess.getHuId()));

//getView().invalidateAll();

invalidateView();
invalidateParentView();

//invalidateView();

return MSG_OK;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package de.metas.ui.web.picking.process;

import static org.adempiere.model.InterfaceWrapperHelper.load;
import static org.adempiere.model.InterfaceWrapperHelper.loadOutOfTrx;

import java.math.BigDecimal;
import java.util.List;

import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.Loggables;
import org.adempiere.util.Services;
import org.adempiere.util.StringUtils;
import org.compiere.model.I_M_Product;
import org.springframework.beans.factory.annotation.Autowired;

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

import de.metas.adempiere.form.PackingItemsMap;
import de.metas.fresh.picking.form.FreshPackingItemHelper;
import de.metas.fresh.picking.form.IFreshPackingItem;
import de.metas.fresh.picking.service.IPackingContext;
import de.metas.fresh.picking.service.IPackingService;
import de.metas.fresh.picking.service.impl.HU2PackingItemsAllocator;
import de.metas.handlingunits.IHUPickingSlotBL;
import de.metas.handlingunits.IHandlingUnitsBL;
import de.metas.handlingunits.model.I_M_HU;
import de.metas.handlingunits.model.I_M_Picking_Candidate;
import de.metas.handlingunits.model.I_M_ShipmentSchedule;
import de.metas.handlingunits.storage.IHUProductStorage;
import de.metas.handlingunits.storage.IHUStorageFactory;
import de.metas.i18n.IMsgBL;
import de.metas.picking.model.I_M_PickingSlot;
import de.metas.process.IProcessPrecondition;
import de.metas.process.ProcessPreconditionsResolution;
import de.metas.ui.web.picking.PickingCandidateCommand;
import de.metas.ui.web.picking.PickingSlotRow;
import de.metas.ui.web.picking.PickingSlotView;
import de.metas.ui.web.picking.PickingSlotViewFactory;
import de.metas.ui.web.process.adprocess.ViewBasedProcessTemplate;

/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2017 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

/**
* Un-processes the unprocessed {@link I_M_Picking_Candidate} of the currently selected TU.<br>
* unprocessing means that
* <ul>
* <li>the HU is changed from status "picked" to "active" (even if it was only "planned" before the candidate was processed!)</li>
* <li>the HU is de-associated with its shipment schedule (changes QtyPicked and QtyToDeliver)</li>
* </ul>
*
* Note: this process is declared in the {@code AD_Process} table, but <b>not</b> added to it's respective window or table via application dictionary.<br>
* Instead it is assigned to it's place by {@link PickingSlotViewFactory}.
*
* @author metas-dev <dev@metasfresh.com>
*
*/
public class WEBUI_Picking_M_Picking_Candidate_UnProcessed
extends ViewBasedProcessTemplate
implements IProcessPrecondition
{
@Autowired
private PickingCandidateCommand pickingCandidateCommand;

private final IHUPickingSlotBL huPickingSlotBL = Services.get(IHUPickingSlotBL.class);

@Override
protected ProcessPreconditionsResolution checkPreconditionsApplicable()
{
if (!getSelectedDocumentIds().isSingleDocumentId())
{
return ProcessPreconditionsResolution.rejectBecauseNotSingleSelection();
}

final IMsgBL msgBL = Services.get(IMsgBL.class);

final PickingSlotRow pickingSlotRow = getSingleSelectedRow();
if (!pickingSlotRow.isHURow())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText("WEBUI_Picking_SelectHU"));
}
if(pickingSlotRow.getIncludedRows().isEmpty())
{
// we want a toplevel HU..this is kindof dirty, but should work in this context
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText("WEBUI_Picking_SelectHU"));
}

if (pickingSlotRow.getHuQtyCU().signum() <= 0)
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText("WEBUI_Picking_PickSomething"));
}

if (pickingSlotRow.isProcessed())
{
return ProcessPreconditionsResolution.reject(msgBL.getTranslatableMsgText("WEBUI_Picking_No_Unprocessed_Records"));
}

return ProcessPreconditionsResolution.accept();
}

@Override
protected String doIt() throws Exception
{
final PickingSlotRow rowToProcess = getSingleSelectedRow();

final IHUStorageFactory storageFactory = Services.get(IHandlingUnitsBL.class).getStorageFactory();
final IPackingService packingService = Services.get(IPackingService.class);

final I_M_PickingSlot pickingSlot = load(rowToProcess.getPickingSlotId(), I_M_PickingSlot.class);
final I_M_HU hu = loadOutOfTrx(rowToProcess.getHuId(), I_M_HU.class); // HU2PackingItemsAllocator wants them to be out of trx

final I_M_ShipmentSchedule shipmentSchedule = getView().getShipmentSchedule();
final I_M_Product product = shipmentSchedule.getM_Product();

BigDecimal qty = BigDecimal.ZERO;
final List<IHUProductStorage> huProductStorages = storageFactory.getHUProductStorages(ImmutableList.of(hu), product);
for (final IHUProductStorage storage : huProductStorages)
{
qty = qty.add(storage.getQty(product.getC_UOM()));
}

if (qty.signum() <= 0)
{
// should not happen due to our checkPreconditionsApplicable(), but happened in other processes, sometimes..we just were unable to reproduce
final String msg = StringUtils.formatMessage("The current HU has no quantity of the current product; hu={}; product={}", hu, product);
Loggables.get().addLog(msg);
throw new AdempiereException(msg);
}

final IFreshPackingItem itemToPack = FreshPackingItemHelper.create(ImmutableMap.of(shipmentSchedule, qty));

final PackingItemsMap packingItemsMap = new PackingItemsMap();
packingItemsMap.addUnpackedItem(itemToPack);

final IPackingContext packingContext = packingService.createPackingContext(getCtx());
packingContext.setPackingItemsMap(packingItemsMap); // don't know what to do with it, but i saw that it can't be null
packingContext.setPackingItemsMapKey(pickingSlot.getM_PickingSlot_ID());

// Allocate given HUs to "itemToPack"
new HU2PackingItemsAllocator()
.setItemToPack(itemToPack)
.setPackingContext(packingContext)
.setFromHUs(ImmutableList.of(hu))
.allocate();

huPickingSlotBL.addToPickingSlotQueue(pickingSlot, hu);

pickingCandidateCommand.setCandidatesProcessed(ImmutableList.of(rowToProcess.getHuId()));

//getView().invalidateAll();

invalidateView();
invalidateParentView();

//invalidateView();

return MSG_OK;
}

@Override
protected PickingSlotView getView()
{
return PickingSlotView.cast(super.getView());
}

@Override
protected PickingSlotRow getSingleSelectedRow()
{
return PickingSlotRow.cast(super.getSingleSelectedRow());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ protected String doIt() throws Exception
invalidateView();
invalidateParentView();

invalidateView();

return MSG_OK;
}

Expand Down

0 comments on commit e6713ac

Please sign in to comment.