コード例 #1
0
  @Override
  public void adjustForTotalQtyTUsAndCUs(
      final I_M_HU_LUTU_Configuration lutuConfiguration,
      final BigDecimal qtyTUsTotal,
      final BigDecimal qtyCUsTotal) {
    Check.assumeNotNull(qtyTUsTotal, "qtyTUsTotal not null");
    Check.assumeNotNull(qtyCUsTotal, "qtyCUsTotal not null");

    //
    // Case: Infinite Qty CU
    // e.g. we are receiving virtual PIs
    if (lutuConfiguration.isInfiniteQtyCU()) {
      lutuConfiguration.setIsInfiniteQtyCU(false);
      lutuConfiguration.setQtyCU(qtyCUsTotal);

      lutuConfiguration.setIsInfiniteQtyTU(false);
      lutuConfiguration.setQtyTU(BigDecimal.ONE);

      lutuConfiguration.setIsInfiniteQtyLU(false);
      if (isNoLU(lutuConfiguration)) {
        lutuConfiguration.setQtyLU(BigDecimal.ZERO);
      } else {
        lutuConfiguration.setQtyLU(BigDecimal.ONE);
      }

      // NOTE: we are returning here, because this is a corner case which we handled separatelly
      // from other cases
      return;
    }

    Check.assume(
        !lutuConfiguration.isInfiniteQtyCU(),
        "Infinite QtyCU not allowed for {}",
        lutuConfiguration);
    final BigDecimal qtyCUsPerTU = lutuConfiguration.getQtyCU();

    //
    // Case: QtyTUs/LU is finite
    if (!lutuConfiguration.isInfiniteQtyTU()) {
      final BigDecimal qtyTUsPerLU = lutuConfiguration.getQtyTU();
      Check.assume(qtyTUsPerLU.signum() > 0, "QtyTU shall be positive: {}", qtyTUsPerLU);

      //
      // Calculate how many LUs we will have based on Order's QtyTU
      final BigDecimal qtyLUs_Effective = qtyTUsTotal.divide(qtyTUsPerLU, 0, RoundingMode.UP);

      //
      // Calculate how many TUs we will have
      // NOTE: this is covering the case when for example your LU accepts 96xTUs but in your order
      // you have just 10xTUs.
      // In this case, QtyTUs shall be only 10.
      final BigDecimal qtyTUs_Effective = qtyTUsPerLU.min(qtyTUsTotal);

      //
      // Calculate how many CUs we will have
      // NOTE: this is covering the case when for example your TU accepts 50xCUs but you have only
      // 10xCUs.
      // In this case, QtyCUs shall only 10.
      final BigDecimal qtyCUs_Effective = qtyCUsPerTU.min(qtyCUsTotal);

      lutuConfiguration.setIsInfiniteQtyLU(
          false); // since we calculated it, we're not considering it infinite any longer
      lutuConfiguration.setQtyLU(qtyLUs_Effective);

      lutuConfiguration.setIsInfiniteQtyTU(
          false); // since we calculated it, we're not considering it infinite any longer
      lutuConfiguration.setQtyTU(qtyTUs_Effective);

      lutuConfiguration.setIsInfiniteQtyCU(
          false); // since we calculated it, we're not considering it infinite any longer
      lutuConfiguration.setQtyCU(qtyCUs_Effective);
    }
    //
    // Case: QtyTUs/LU is infinite
    else {
      Check.assume(
          !lutuConfiguration.isInfiniteQtyLU(),
          "LU cannot be infinite when TU already is infinite for {}",
          lutuConfiguration);

      final BigDecimal qtyTUs_Effective = qtyTUsTotal;
      final BigDecimal qtyCUs_Effective = qtyCUsPerTU.min(qtyCUsTotal);

      lutuConfiguration.setIsInfiniteQtyTU(
          false); // since we calculated it, we're not considering it infinite any longer
      lutuConfiguration.setQtyTU(qtyTUs_Effective);

      lutuConfiguration.setIsInfiniteQtyCU(
          false); // since we calculated it, we're not considering it infinite any longer
      lutuConfiguration.setQtyCU(qtyCUs_Effective);
    }
  }
コード例 #2
0
  @Override
  public I_M_HU_LUTU_Configuration createLUTUConfiguration(
      final I_M_HU_PI_Item_Product tuPIItemProduct,
      final I_M_Product cuProduct,
      final I_C_UOM cuUOM,
      final org.compiere.model.I_C_BPartner bpartner) {
    Check.assumeNotNull(tuPIItemProduct, "tuPIItemProduct not null");
    Check.assumeNotNull(cuProduct, "cuProduct not null");
    Check.assumeNotNull(cuUOM, "cuUOM not null");

    // Services used:
    final ITrxManager trxManager = Services.get(ITrxManager.class);
    final IHandlingUnitsDAO handlingUnitsDAO = Services.get(IHandlingUnitsDAO.class);
    final IHUCapacityBL huCapacityBL = Services.get(IHUCapacityBL.class);

    //
    // Context
    final Properties ctx = InterfaceWrapperHelper.getCtx(tuPIItemProduct);
    final IContextAware contextProvider;
    final String threadTrxName = trxManager.getThreadInheritedTrxName();
    if (trxManager.isNull(threadTrxName)) {
      contextProvider = new PlainContextAware(ctx, ITrx.TRXNAME_None);
    } else {
      contextProvider = trxManager.createThreadContextAware(ctx);
    }

    //
    // LU/TU configuration (draft)
    final I_M_HU_LUTU_Configuration lutuConfiguration =
        InterfaceWrapperHelper.newInstance(I_M_HU_LUTU_Configuration.class, contextProvider);
    lutuConfiguration.setC_BPartner(bpartner);
    lutuConfiguration.setIsActive(true);

    //
    // TU Configuration
    final I_M_HU_PI tuPI = tuPIItemProduct.getM_HU_PI_Item().getM_HU_PI_Version().getM_HU_PI();
    final IHUCapacityDefinition tuCapacity =
        huCapacityBL.getCapacity(tuPIItemProduct, cuProduct, cuUOM);
    //
    lutuConfiguration.setM_HU_PI_Item_Product(tuPIItemProduct);
    lutuConfiguration.setM_TU_HU_PI(tuPI);
    lutuConfiguration.setM_Product(cuProduct);
    lutuConfiguration.setC_UOM(cuUOM);
    if (tuCapacity.isInfiniteCapacity()) {
      lutuConfiguration.setIsInfiniteQtyCU(true);
      lutuConfiguration.setQtyCU(BigDecimal.ZERO);
    } else {
      lutuConfiguration.setIsInfiniteQtyCU(false);
      lutuConfiguration.setQtyCU(tuCapacity.getCapacity());
    }

    //
    // LU Configuration
    final I_M_HU_PI_Item luPIItem =
        handlingUnitsDAO.retrieveDefaultParentPIItem(
            tuPI, X_M_HU_PI_Version.HU_UNITTYPE_LoadLogistiqueUnit, bpartner);
    if (luPIItem != null) {
      final I_M_HU_PI luPI = luPIItem.getM_HU_PI_Version().getM_HU_PI();
      lutuConfiguration.setM_LU_HU_PI(luPI);
      lutuConfiguration.setM_LU_HU_PI_Item(luPIItem);

      lutuConfiguration.setIsInfiniteQtyLU(true); // we produce as many as needed
      lutuConfiguration.setQtyLU(BigDecimal.ZERO);

      final int qtyTU = luPIItem.getQty().intValueExact();
      lutuConfiguration.setIsInfiniteQtyTU(false);
      lutuConfiguration.setQtyTU(BigDecimal.valueOf(qtyTU));
    } else {
      lutuConfiguration.setM_LU_HU_PI(null);
      lutuConfiguration.setM_LU_HU_PI_Item(null);

      lutuConfiguration.setIsInfiniteQtyLU(false);
      lutuConfiguration.setQtyLU(BigDecimal.ZERO);

      lutuConfiguration.setIsInfiniteQtyTU(true); // as many as needed
      lutuConfiguration.setQtyTU(BigDecimal.ZERO);
    }

    return lutuConfiguration;
  }