Skip to content

Commit

Permalink
Flush HuContext to have the attributes available from sql
Browse files Browse the repository at this point in the history
#10365
Signed-off-by: TheBestPessimist <cristian@tbp.land>
  • Loading branch information
TheBestPessimist committed Dec 9, 2020
1 parent e1c211d commit ede4ac4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public void updateHUAttributeRecursive(@NonNull final HuId huId, @NonNull final
final I_M_Attribute attribute = attributeDAO.retrieveAttributeByValue(attributeCode);
final I_M_HU hu = handlingUnitsDAO.getById(huId);
updateHUAttributeRecursive(hu, attribute, attributeValue, onlyHUStatus);
// TODO tbp: check what happens if the attribute doesn't exist?
}

@Override
Expand All @@ -87,8 +86,7 @@ public void updateHUAttributeRecursive(final I_M_HU hu,
final ILoggable loggable = Loggables.get();

final IHUStorageFactory storageFactory = handlingUnitsBL.getStorageFactory();
final IAttributeStorageFactory huAttributeStorageFactory = attributeStorageFactoryService
.createHUAttributeStorageFactory(storageFactory);
final IAttributeStorageFactory huAttributeStorageFactory = attributeStorageFactoryService.createHUAttributeStorageFactory(storageFactory);

final HUIterator iterator = new HUIterator();
// I'm not 100% sure which time to pick, but i think for the iterator itself it makes no difference, and i also don't need it in the beforeHU implementation.
Expand All @@ -103,10 +101,13 @@ public Result beforeHU(final IMutable<I_M_HU> currentHUMutable)
{
final IAttributeStorage attributeStorage = huAttributeStorageFactory.getAttributeStorage(currentHU);

attributeStorage.setValueNoPropagate(attribute, attributeValue);
attributeStorage.saveChangesIfNeeded();
final String msg = "Updated IAttributeStorage " + attributeStorage + " of M_HU " + currentHU;
loggable.addLog(msg);
if (attributeStorage.hasAttribute(attribute))
{
attributeStorage.setValueNoPropagate(attribute, attributeValue);
attributeStorage.saveChangesIfNeeded();
final String msg = "Updated IAttributeStorage " + attributeStorage + " of M_HU " + currentHU;
loggable.addLog(msg);
}
}

return Result.CONTINUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ private HuId packToHU(

addShipmentScheduleQtyPickedAndUpdateHU(shipmentSchedule, packedToHU, qtyPicked, huContext);

huContext.flush();

return HuId.ofRepoId(packedToHU.getM_HU_ID());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import de.metas.inoutcandidate.model.I_M_ShipmentSchedule;
import de.metas.quantity.StockQtyAndUOMQty;
import de.metas.util.ISingletonService;
import lombok.NonNull;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.util.agg.key.IAggregationKeyBuilder;
import org.adempiere.warehouse.LocatorId;

import javax.annotation.Nullable;
import java.time.LocalDate;

public interface IHUShipmentScheduleBL extends ISingletonService
Expand Down Expand Up @@ -52,7 +54,7 @@ public interface IHUShipmentScheduleBL extends ISingletonService
* @param movementDate shipment's movement date (used to filter only if we have an consolidation period set)
* @return shipment which is still open for the shipment schedule (first) and it's HU specifications (shipper transportation) or null if none is found
*/
I_M_InOut getOpenShipmentOrNull(ShipmentScheduleWithHU candidate, LocalDate movementDate);
@Nullable I_M_InOut getOpenShipmentOrNull(@NonNull ShipmentScheduleWithHU candidate, @NonNull LocalDate movementDate);

/**
* Update all allocations from given TU and call {@link I_M_ShipmentSchedule_QtyPicked#setM_LU_HU(I_M_HU)} by setting the current TU's LU.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.compiere.model.X_M_InOut;
import org.slf4j.Logger;

import javax.annotation.Nullable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.ArrayList;
Expand Down Expand Up @@ -187,6 +188,7 @@ public ShipmentScheduleWithHU addQtyPickedAndUpdateHU(
setHUStatusToPicked(topLevelHU);
setHUPartnerAndLocationFromSched(topLevelHU, sched);
handlingUnitsRepo.saveHU(topLevelHU);
huContext.flush();

return ShipmentScheduleWithHU.ofShipmentScheduleQtyPicked(schedQtyPickedHU, huContext);
}
Expand Down Expand Up @@ -334,8 +336,10 @@ public IInOutProducerFromShipmentScheduleWithHU createInOutProducerFromShipmentS
/**
* NOTE: KEEP IN SYNC WITH {@link de.metas.handlingunits.shipmentschedule.spi.impl.InOutProducerFromShipmentScheduleWithHU#createShipmentHeader(I_M_ShipmentSchedule)}
*/
@Nullable
@SuppressWarnings("JavadocReference")
@Override
public I_M_InOut getOpenShipmentOrNull(final ShipmentScheduleWithHU candidate, final LocalDate movementDate)
public I_M_InOut getOpenShipmentOrNull(final @NonNull ShipmentScheduleWithHU candidate, final @NonNull LocalDate movementDate)
{
final I_M_ShipmentSchedule shipmentSchedule = create(candidate.getM_ShipmentSchedule(), I_M_ShipmentSchedule.class);

Expand Down Expand Up @@ -467,8 +471,7 @@ public HUPIItemProductId getEffectivePackingMaterialId(@NonNull final de.metas.i
}

// if is not set in shipment schedule, return the one form order line or null
final HUPIItemProductId orderLinePIPOrNull = extractOrderLinePackingMaterialIdOrNull(shipmentSchedule);
return orderLinePIPOrNull;
return extractOrderLinePackingMaterialIdOrNull(shipmentSchedule);
}

private HUPIItemProductId extractOrderLinePackingMaterialIdOrNull(@NonNull final de.metas.inoutcandidate.model.I_M_ShipmentSchedule shipmentSchedule)
Expand Down

0 comments on commit ede4ac4

Please sign in to comment.