コード例 #1
0
  /**
   * Set the default locator if this field is mandatory and we have a warehouse restriction.
   *
   * @since 3.1.4
   */
  private void setDefault_Locator_ID() {
    // teo_sarca, FR [ 1661546 ] Mandatory locator fields should use defaults

    if (!isMandatory() || m_mLocator == null) {
      return;
    }

    int M_Warehouse_ID = getOnly_Warehouse_ID();

    if (M_Warehouse_ID <= 0) {
      return;
    }

    MWarehouse wh = MWarehouse.get(Env.getCtx(), M_Warehouse_ID);

    if (wh == null || wh.get_ID() <= 0) {
      return;
    }

    MLocator loc = wh.getDefaultLocator();

    if (loc == null || loc.get_ID() <= 0) {
      return;
    }

    setValue(Integer.valueOf(loc.get_ID()));
  }
コード例 #2
0
  /** Create Inventory Movements */
  private void createMovements() {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MMovement move = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
    for (int i = 0; i < replenishs.length; i++) {
      X_T_Replenish replenish = replenishs[i];
      if (whSource == null
          || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
        whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
      if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
        wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
      if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
        client = MClient.get(getCtx(), whSource.getAD_Client_ID());
      //
      if (move == null
          || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID()
          || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
        M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
        M_Warehouse_ID = replenish.getM_Warehouse_ID();

        move = new MMovement(getCtx(), 0, get_TrxName());
        move.setC_DocType_ID(p_C_DocType_ID);
        move.setDescription(
            Msg.getMsg(getCtx(), "Replenishment")
                + ": "
                + whSource.getName()
                + "->"
                + wh.getName());
        //	Set Org
        move.setAD_Org_ID(whSource.getAD_Org_ID());
        if (!move.save()) return;
        log.debug(move.toString());
        noMoves++;
        info += " - " + move.getDocumentNo();
      }
      //	To
      int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
      //	From: Look-up Storage
      MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
      String MMPolicy = product.getMMPolicy();
      MStorage[] storages =
          MStorage.getWarehouse(
              getCtx(),
              whSource.getM_Warehouse_ID(),
              replenish.getM_Product_ID(),
              0,
              0,
              true,
              null,
              MClient.MMPOLICY_FiFo.equals(MMPolicy),
              get_TrxName());
      //
      BigDecimal target = replenish.getQtyToOrder();
      for (int j = 0; j < storages.length; j++) {
        MStorage storage = storages[j];
        if (storage.getQtyOnHand().signum() <= 0) continue;
        BigDecimal moveQty = target;
        if (storage.getQtyOnHand().compareTo(moveQty) < 0) moveQty = storage.getQtyOnHand();
        //
        MMovementLine line = new MMovementLine(move);
        line.setM_Product_ID(replenish.getM_Product_ID());
        line.setMovementQty(moveQty);
        if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
          line.setDescription("Total: " + replenish.getQtyToOrder());
        line.setM_Locator_ID(storage.getM_Locator_ID()); // 	from
        line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
        line.setM_LocatorTo_ID(M_LocatorTo_ID); // 	to
        line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
        line.save();
        //
        target = target.subtract(moveQty);
        if (target.signum() == 0) break;
      }
    }
    if (replenishs.length == 0) {
      m_info = "No Source Warehouse";
      log.warn(m_info);
    } else {
      m_info = "#" + noMoves + info;
      log.info(m_info);
    }
  } //	createRequisition