public void createUsageVariances(MPPCostCollector ccuv) {
   // Apply only for material Usage Variance
   if (!ccuv.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_UsegeVariance)) {
     throw new IllegalArgumentException("Cost Collector is not Material Usage Variance");
   }
   //
   final I_M_Product product;
   final BigDecimal qty;
   if (ccuv.getPP_Order_BOMLine_ID() > 0) {
     product = MProduct.get(ccuv.getCtx(), ccuv.getM_Product_ID());
     qty = ccuv.getMovementQty();
   } else {
     product = MProduct.forS_Resource_ID(ccuv.getCtx(), ccuv.getS_Resource_ID(), null);
     final RoutingService routingService =
         RoutingServiceFactory.get().getRoutingService(ccuv.getAD_Client_ID());
     qty = routingService.getResourceBaseValue(ccuv.getS_Resource_ID(), ccuv);
   }
   //
   for (I_C_AcctSchema as : getAcctSchema(ccuv)) {
     for (I_M_CostElement element : getCostElements(ccuv.getCtx())) {
       final BigDecimal price =
           getProductActualCostPrice(ccuv, product, as, element, ccuv.get_TrxName());
       final BigDecimal amt = roundCost(price.multiply(qty), as.getC_AcctSchema_ID());
       //
       // Create / Update Cost Detail
       createVarianceCostDetail(
           ccuv, amt, qty, null, // no original cost detail
           product, as, element);
     } // for ELements
   } // Account Schema
 }
  /**
   * Import record using X_I_ProductPlanning table
   *
   * @param ipp X_I_ProductPlanning
   */
  private void importPurchaseProductPlanning(X_I_ProductPlanning ipp) {
    MProduct product = MProduct.get(getCtx(), ipp.getM_Product_ID());
    if (product.isPurchased()) {
      final StringBuffer whereClause = new StringBuffer();
      whereClause.append(MProductPO.COLUMNNAME_M_Product_ID).append("=? AND ");
      whereClause.append(MProductPO.COLUMNNAME_C_BPartner_ID).append("=?");
      MProductPO productPO =
          new Query(getCtx(), MProductPO.Table_Name, whereClause.toString(), get_TrxName())
              .setClient_ID()
              .setParameters(new Object[] {ipp.getM_Product_ID(), ipp.getC_BPartner_ID()})
              .first();

      if (productPO == null) {
        productPO = new MProductPO(getCtx(), 0, get_TrxName());
      }

      productPO.setAD_Org_ID(ipp.getAD_Org_ID());
      productPO.setM_Product_ID(ipp.getM_Product_ID());
      productPO.setC_BPartner_ID(ipp.getC_BPartner_ID());
      productPO.setOrder_Min(ipp.getOrder_Min());
      productPO.setOrder_Pack(ipp.getOrder_Pack());
      productPO.setDeliveryTime_Promised(ipp.getDeliveryTime_Promised().intValue());
      productPO.setVendorProductNo(ipp.getVendorProductNo());
      productPO.saveEx();
    }
  }
Exemple #3
0
  /**
   * Is this an Item Product (vs. not a Service, a charge)
   *
   * @return true if product
   */
  public boolean isItem() {
    if (m_isItem != null) return m_isItem.booleanValue();

    m_isItem = Boolean.FALSE;
    if (getM_Product_ID() != 0) {
      MProduct product = MProduct.get(Env.getCtx(), getM_Product_ID());
      if (product.get_ID() == getM_Product_ID() && product.isItem()) m_isItem = Boolean.TRUE;
    }
    return m_isItem.booleanValue();
  } //	isItem
Exemple #4
0
 /**
  * Perform process.
  *
  * @return Message (text with variables)
  * @throws Exception if not successful
  */
 protected String doIt() throws Exception {
   if (log.isLoggable(Level.INFO)) log.info("M_Product_ID=" + p_M_Product_ID);
   if (p_M_Product_ID == 0)
     throw new AdempiereUserError("@NotFound@: @M_Product_ID@ = " + p_M_Product_ID);
   MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
   if (product.get_ID() != p_M_Product_ID)
     throw new AdempiereUserError("@NotFound@: @M_Product_ID@ = " + p_M_Product_ID);
   //
   if (MCostDetail.processProduct(product, get_TrxName())) return "@OK@";
   return "@Error@";
 } //	doIt
  /**
   * ************************************************************************ Invoice Line -
   * Product. - reset C_Charge_ID / M_AttributeSetInstance_ID - PriceList, PriceStd, PriceLimit,
   * C_Currency_ID, EnforcePriceLimit - UOM Calls Tax
   *
   * @param ctx context
   * @param WindowNo window no
   * @param mTab tab
   * @param mField field
   * @param value value
   * @return null or error message
   */
  public String product(
      Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    Integer M_Product_ID = (Integer) value;
    Integer M_AttributeSetInstance_ID = 0;

    if (M_Product_ID == null || M_Product_ID.intValue() == 0) return "";
    mTab.setValue("C_Charge_ID", null);

    //	Get Model and check the Attribute Set Instance from the context
    MProduct m_product = MProduct.get(Env.getCtx(), M_Product_ID);
    mTab.setValue("M_AttributeSetInstance_ID", m_product.getEnvAttributeSetInstance(ctx, WindowNo));

    /** *** Price Calculation see also qty *** */
    boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
    int C_BPartner_ID = Env.getContextAsInt(ctx, WindowNo, WindowNo, "C_BPartner_ID");
    BigDecimal Qty = (BigDecimal) mTab.getValue("QtyInvoiced");
    MProductPricing pp = new MProductPricing(M_Product_ID.intValue(), C_BPartner_ID, Qty, IsSOTrx);
    //
    int M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID");
    pp.setM_PriceList_ID(M_PriceList_ID);

    Timestamp invoiceDate = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
    /** PLV is only accurate if PL selected in header */
    int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID");
    if (M_PriceList_Version_ID == 0 && M_PriceList_ID > 0) {
      String sql =
          "SELECT plv.M_PriceList_Version_ID "
              + "FROM M_PriceList_Version plv "
              + "WHERE plv.M_PriceList_ID=? " //	1
              + " AND plv.ValidFrom <= ? "
              + "ORDER BY plv.ValidFrom DESC";
      //	Use newest price list - may not be future

      M_PriceList_Version_ID = DB.getSQLValueEx(null, sql, M_PriceList_ID, invoiceDate);
      if (M_PriceList_Version_ID > 0)
        Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", M_PriceList_Version_ID);
    }

    pp.setM_PriceList_Version_ID(M_PriceList_Version_ID);
    Timestamp date = Env.getContextAsDate(ctx, WindowNo, "DateInvoiced");
    pp.setPriceDate(date);
    //
    mTab.setValue("PriceList", pp.getPriceList());
    mTab.setValue("PriceLimit", pp.getPriceLimit());
    mTab.setValue("PriceActual", pp.getPriceStd());
    mTab.setValue("PriceEntered", pp.getPriceStd());
    mTab.setValue("C_Currency_ID", new Integer(pp.getC_Currency_ID()));
    //	mTab.setValue("Discount", pp.getDiscount());
    mTab.setValue("C_UOM_ID", new Integer(pp.getC_UOM_ID()));
    Env.setContext(ctx, WindowNo, "EnforcePriceLimit", pp.isEnforcePriceLimit() ? "Y" : "N");
    Env.setContext(ctx, WindowNo, "DiscountSchema", pp.isDiscountSchema() ? "Y" : "N");
    //
    return tax(ctx, WindowNo, mTab, mField, value);
  } //	product
  /**
   * Create Facts (the accounting logic) for PJI
   *
   * <pre>
   *  Issue
   *      ProjectWIP      DR
   *      Inventory               CR
   *  </pre>
   *
   * Project Account is either Asset or WIP depending on Project Type
   *
   * @param as accounting schema
   * @return Fact
   */
  public ArrayList<Fact> createFacts(MAcctSchema as) {
    //  create Fact Header
    Fact fact = new Fact(this, as, Fact.POST_Actual);
    setC_Currency_ID(as.getC_Currency_ID());

    MProject project = new MProject(getCtx(), m_issue.getC_Project_ID(), getTrxName());
    String ProjectCategory = project.getProjectCategory();
    MProduct product = MProduct.get(getCtx(), m_issue.getM_Product_ID());

    //  Line pointers
    FactLine dr = null;
    FactLine cr = null;

    //  Issue Cost
    BigDecimal costs = null;
    BigDecimal total = Env.ZERO;
    if (m_issue.getM_InOutLine_ID() != 0) costs = getPOCost(as);
    else if (m_issue.getS_TimeExpenseLine_ID() != 0) costs = getLaborCost(as);
    if (costs == null) // 	standard Product Costs
    {
      for (MCostDetail cost : m_line.getCostDetail(as)) {
        if (!MCostDetail.existsCost(cost)) continue;

        costs = MCostDetail.getTotalCost(cost, as);
        total = total.add(costs);
      }
    }

    if (total == null || total.signum() == 0) {
      p_Error = "Resubmit - No Costs for " + product.getName();
      log.log(Level.WARNING, p_Error);
      return null;
    }

    //  Project         DR
    int acctType = ACCTTYPE_ProjectWIP;
    if (MProject.PROJECTCATEGORY_AssetProject.equals(ProjectCategory))
      acctType = ACCTTYPE_ProjectAsset;
    dr = fact.createLine(m_line, getAccount(acctType, as), as.getC_Currency_ID(), costs, null);
    dr.setQty(m_line.getQty().negate());

    //  Inventory               CR
    acctType = ProductCost.ACCTTYPE_P_Asset;
    if (product.isService()) acctType = ProductCost.ACCTTYPE_P_Expense;
    cr =
        fact.createLine(
            m_line, m_line.getAccount(acctType, as), as.getC_Currency_ID(), null, costs);
    cr.setM_Locator_ID(m_line.getM_Locator_ID());
    cr.setLocationFromLocator(m_line.getM_Locator_ID(), true); // from Loc
    //
    ArrayList<Fact> facts = new ArrayList<Fact>();
    facts.add(fact);
    return facts;
  } //  createFact
  public void createRateVariances(MPPCostCollector cc) {
    final I_M_Product product;
    if (cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ActivityControl)) {
      final I_AD_WF_Node node = cc.getPP_Order_Node().getAD_WF_Node();
      product = MProduct.forS_Resource_ID(cc.getCtx(), node.getS_Resource_ID(), null);
    } else if (cc.isCostCollectorType(X_PP_Cost_Collector.COSTCOLLECTORTYPE_ComponentIssue)) {
      final I_PP_Order_BOMLine bomLine = cc.getPP_Order_BOMLine();
      product = MProduct.get(cc.getCtx(), bomLine.getM_Product_ID());
    } else {
      return;
    }

    I_PP_Cost_Collector ccrv = null; // Cost Collector - Rate Variance
    for (MAcctSchema as : getAcctSchema(cc)) {
      for (I_M_CostElement element : getCostElements(cc.getCtx())) {
        final MCostDetail cd = getCostDetail(cc, element.getM_CostElement_ID());
        if (cd == null) {
          continue;
        }

        //
        final BigDecimal qty = cd.getQty();
        final BigDecimal priceStd = getProductStandardCostPrice(cc, product, as, element);
        final BigDecimal priceActual =
            getProductActualCostPriceOrZero(cc, product, as, element, cc.get_TrxName());
        final BigDecimal amtStd = roundCost(priceStd.multiply(qty), as.getC_AcctSchema_ID());
        final BigDecimal amtActual = roundCost(priceActual.multiply(qty), as.getC_AcctSchema_ID());
        if (amtStd.compareTo(amtActual) == 0) {
          continue;
        }

        //
        if (ccrv == null) {
          ccrv =
              createVarianceCostCollector(cc, X_PP_Cost_Collector.COSTCOLLECTORTYPE_RateVariance);
        }
        //
        createVarianceCostDetail(ccrv, amtActual.negate(), qty.negate(), cd, null, as, element);
        createVarianceCostDetail(ccrv, amtStd, qty, cd, null, as, element);
      }
    }
    //
    if (ccrv != null) {
      Services.get(IDocActionBL.class)
          .processEx(ccrv, DocAction.ACTION_Complete, DocAction.STATUS_Completed);
    }
  }
  /**
   * Perform process.
   *
   * @return Message (clear text)
   * @throws Exception if not successful
   */
  protected String doIt() throws Exception {
    AD_PInstance_ID = getAD_PInstance_ID();
    final MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
    if (!product.isVerified())
      throw new AdempiereException(
          "Product BOM Configuration not verified. Please verify the product first - "
              + product.getValue()); // TODO: translate

    try {
      loadBOM();
      print();
    } catch (Exception e) {
      log.log(Level.SEVERE, "PrintBOM", e.toString());
      throw new Exception(e.getLocalizedMessage());
    } finally {
      String sql = "DELETE FROM T_BomLine WHERE AD_PInstance_ID = " + AD_PInstance_ID;
      DB.executeUpdateEx(sql, get_TrxName());
    }

    return "@OK@";
  } // doIt
 /**
  * Get Product
  *
  * @return product or null
  */
 public MProduct getProduct() {
   if (m_product == null && getM_Product_ID() != 0)
     m_product = MProduct.get(getCtx(), getM_Product_ID());
   return m_product;
 } // getProduct
Exemple #10
0
 /**
  * Set M_Product_ID
  *
  * @param M_Product_ID product
  * @param setUOM set also UOM
  */
 public void setM_Product_ID(int M_Product_ID, boolean setUOM) {
   if (setUOM) setProduct(MProduct.get(getCtx(), M_Product_ID));
   else super.setM_Product_ID(M_Product_ID);
   setM_AttributeSetInstance_ID(0);
 } // setM_Product_ID
  /**
   * Invoice Line - Quantity. - called from C_UOM_ID, QtyEntered, QtyInvoiced - enforces qty UOM
   * relationship
   *
   * @param ctx context
   * @param WindowNo window no
   * @param mTab tab
   * @param mField field
   * @param value value
   * @return null or error message
   */
  public String qty(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) {
    if (isCalloutActive() || value == null) return "";

    int M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID");
    //	log.log(Level.WARNING,"qty - init - M_Product_ID=" + M_Product_ID);
    BigDecimal QtyInvoiced, QtyEntered, PriceActual, PriceEntered;

    //	No Product
    if (M_Product_ID == 0) {
      QtyEntered = (BigDecimal) mTab.getValue("QtyEntered");
      mTab.setValue("QtyInvoiced", QtyEntered);
    }
    //	UOM Changed - convert from Entered -> Product
    else if (mField.getColumnName().equals("C_UOM_ID")) {
      int C_UOM_To_ID = ((Integer) value).intValue();
      QtyEntered = (BigDecimal) mTab.getValue("QtyEntered");
      BigDecimal QtyEntered1 =
          QtyEntered.setScale(MUOM.getPrecision(ctx, C_UOM_To_ID), BigDecimal.ROUND_HALF_UP);
      if (QtyEntered.compareTo(QtyEntered1) != 0) {
        log.fine(
            "Corrected QtyEntered Scale UOM="
                + C_UOM_To_ID
                + "; QtyEntered="
                + QtyEntered
                + "->"
                + QtyEntered1);
        QtyEntered = QtyEntered1;
        mTab.setValue("QtyEntered", QtyEntered);
      }
      QtyInvoiced = MUOMConversion.convertProductFrom(ctx, M_Product_ID, C_UOM_To_ID, QtyEntered);
      if (QtyInvoiced == null) QtyInvoiced = QtyEntered;
      boolean conversion = QtyEntered.compareTo(QtyInvoiced) != 0;
      PriceActual = (BigDecimal) mTab.getValue("PriceActual");
      PriceEntered = MUOMConversion.convertProductFrom(ctx, M_Product_ID, C_UOM_To_ID, PriceActual);
      if (PriceEntered == null) PriceEntered = PriceActual;
      log.fine(
          "qty - UOM="
              + C_UOM_To_ID
              + ", QtyEntered/PriceActual="
              + QtyEntered
              + "/"
              + PriceActual
              + " -> "
              + conversion
              + " QtyInvoiced/PriceEntered="
              + QtyInvoiced
              + "/"
              + PriceEntered);
      Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
      mTab.setValue("QtyInvoiced", QtyInvoiced);
      mTab.setValue("PriceEntered", PriceEntered);
    }
    //	QtyEntered changed - calculate QtyInvoiced
    else if (mField.getColumnName().equals("QtyEntered")) {
      int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
      QtyEntered = (BigDecimal) value;
      BigDecimal QtyEntered1 =
          QtyEntered.setScale(MUOM.getPrecision(ctx, C_UOM_To_ID), BigDecimal.ROUND_HALF_UP);
      if (QtyEntered.compareTo(QtyEntered1) != 0) {
        log.fine(
            "Corrected QtyEntered Scale UOM="
                + C_UOM_To_ID
                + "; QtyEntered="
                + QtyEntered
                + "->"
                + QtyEntered1);
        QtyEntered = QtyEntered1;
        mTab.setValue("QtyEntered", QtyEntered);
      }
      QtyInvoiced = MUOMConversion.convertProductFrom(ctx, M_Product_ID, C_UOM_To_ID, QtyEntered);
      if (QtyInvoiced == null) QtyInvoiced = QtyEntered;
      boolean conversion = QtyEntered.compareTo(QtyInvoiced) != 0;
      log.fine(
          "qty - UOM="
              + C_UOM_To_ID
              + ", QtyEntered="
              + QtyEntered
              + " -> "
              + conversion
              + " QtyInvoiced="
              + QtyInvoiced);
      Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
      mTab.setValue("QtyInvoiced", QtyInvoiced);
    }
    //	QtyInvoiced changed - calculate QtyEntered (should not happen)
    else if (mField.getColumnName().equals("QtyInvoiced")) {
      int C_UOM_To_ID = Env.getContextAsInt(ctx, WindowNo, "C_UOM_ID");
      QtyInvoiced = (BigDecimal) value;
      int precision = MProduct.get(ctx, M_Product_ID).getUOMPrecision();
      BigDecimal QtyInvoiced1 = QtyInvoiced.setScale(precision, BigDecimal.ROUND_HALF_UP);
      if (QtyInvoiced.compareTo(QtyInvoiced1) != 0) {
        log.fine("Corrected QtyInvoiced Scale " + QtyInvoiced + "->" + QtyInvoiced1);
        QtyInvoiced = QtyInvoiced1;
        mTab.setValue("QtyInvoiced", QtyInvoiced);
      }
      QtyEntered = MUOMConversion.convertProductTo(ctx, M_Product_ID, C_UOM_To_ID, QtyInvoiced);
      if (QtyEntered == null) QtyEntered = QtyInvoiced;
      boolean conversion = QtyInvoiced.compareTo(QtyEntered) != 0;
      log.fine(
          "qty - UOM="
              + C_UOM_To_ID
              + ", QtyInvoiced="
              + QtyInvoiced
              + " -> "
              + conversion
              + " QtyEntered="
              + QtyEntered);
      Env.setContext(ctx, WindowNo, "UOMConversion", conversion ? "Y" : "N");
      mTab.setValue("QtyEntered", QtyEntered);
    }
    //
    return "";
  } //	qty
Exemple #12
0
  /**
   * Create Cost Detail (Material Issue, Material Receipt)
   *
   * @param model
   * @param mtrx Material Transaction
   */
  public void createCostDetail(IDocumentLine model, MTransaction mtrx) {
    final I_PP_Cost_Collector cc =
        (model instanceof MPPCostCollector ? (MPPCostCollector) model : null);

    final Properties ctx = mtrx.getCtx();

    for (I_C_AcctSchema as : getAcctSchema(mtrx)) {
      // Cost Detail
      final I_M_Product product = MProduct.get(ctx, mtrx.getM_Product_ID());
      final String costingMethod = Services.get(IProductBL.class).getCostingMethod(product, as);
      // Check costing method
      if (!getCostingMethod().equals(costingMethod)) {
        throw new LiberoException("Costing method not supported - " + costingMethod);
      }
      //
      for (I_M_CostElement element : getCostElements(ctx)) {
        //
        // Delete Unprocessed zero Differences
        deleteCostDetail(
            model, as, element.getM_CostElement_ID(), mtrx.getM_AttributeSetInstance_ID());
        //
        // Get Costs
        final BigDecimal qty = mtrx.getMovementQty();
        final BigDecimal price =
            getProductActualCostPriceOrZero(cc, product, as, element, mtrx.get_TrxName());
        final BigDecimal amt = roundCost(price.multiply(qty), as.getC_AcctSchema_ID());
        //
        // Create / Update Cost Detail
        MCostDetail cd = getCostDetail(model, mtrx, as, element.getM_CostElement_ID());
        if (cd == null) // createNew
        {
          cd =
              new MCostDetail(
                  as,
                  mtrx.getAD_Org_ID(),
                  mtrx.getM_Product_ID(),
                  mtrx.getM_AttributeSetInstance_ID(),
                  element.getM_CostElement_ID(),
                  amt,
                  qty,
                  model.getDescription(),
                  mtrx.get_TrxName());
          // cd.setMovementDate(mtrx.getMovementDate());
          // if (cost != null)
          // {
          // cd.setCurrentCostPrice(cost.getCurrentCostPrice());
          // cd.setCurrentCostPriceLL(cost.getCurrentCostPriceLL());
          // }
          // else
          // {
          // cd.setCurrentCostPrice(Env.ZERO);
          // cd.setCurrentCostPriceLL(Env.ZERO);
          // }
          // cd.setM_CostType_ID(as.getM_CostType_ID());
          // //cd.setCostingMethod(element.getCostingMethod());
          // cd.setM_Transaction_ID(mtrx.get_ID());
          if (cc != null) {
            cd.setPP_Cost_Collector_ID(cc.getPP_Cost_Collector_ID());
          }
        } else {
          cd.setDeltaAmt(amt.subtract(cd.getAmt()));
          cd.setDeltaQty(mtrx.getMovementQty().subtract(cd.getQty()));
          if (cd.isDelta()) {
            cd.setProcessed(false);
            cd.setAmt(amt);
            cd.setQty(mtrx.getMovementQty());
          }
        }
        cd.saveEx();
        processCostDetail(cd);
        log.info("" + cd);
      } // for ELements
    } // Account Schema
  }
  /** Start dialog */
  private void cmd_dialog() {
    //
    Integer oldValue = (Integer) getValue();
    int oldValueInt = oldValue == null ? 0 : oldValue.intValue();
    int M_AttributeSetInstance_ID = oldValueInt;
    int M_Product_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_Product_ID");
    int M_ProductBOM_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "M_ProductBOM_ID");

    log.config(
        "M_Product_ID="
            + M_Product_ID
            + "/"
            + M_ProductBOM_ID
            + ",M_AttributeSetInstance_ID="
            + M_AttributeSetInstance_ID
            + ", AD_Column_ID="
            + gridField.getAD_Column_ID());

    //	M_Product.M_AttributeSetInstance_ID = 8418
    boolean productWindow = (gridField.getAD_Column_ID() == 8418); // 	HARDCODED

    //	Exclude ability to enter ASI
    boolean exclude = true;

    if (M_Product_ID != 0) {
      MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
      int M_AttributeSet_ID = Services.get(IProductBL.class).getM_AttributeSet_ID(product);
      if (M_AttributeSet_ID != 0) {
        final IAttributeExcludeBL excludeBL = Services.get(IAttributeExcludeBL.class);
        final I_M_AttributeSet attributeSet =
            InterfaceWrapperHelper.create(
                Env.getCtx(), M_AttributeSet_ID, I_M_AttributeSet.class, ITrx.TRXNAME_None);
        final I_M_AttributeSetExclude asExclude =
            excludeBL.getAttributeSetExclude(
                attributeSet, gridField.getAD_Column_ID(), Env.isSOTrx(Env.getCtx(), m_WindowNo));
        if ((null == asExclude) || (!excludeBL.isFullExclude(asExclude))) {
          exclude = false;
        }
      }
    }

    boolean changed = false;
    if (M_ProductBOM_ID != 0) // 	Use BOM Component
    M_Product_ID = M_ProductBOM_ID;
    //
    if (!productWindow && (M_Product_ID == 0 || exclude)) {
      changed = true;
      getComponent().setText(null);
      M_AttributeSetInstance_ID = 0;
    } else {
      WPAttributeDialog vad =
          new WPAttributeDialog(
              M_AttributeSetInstance_ID,
              M_Product_ID,
              m_C_BPartner_ID,
              productWindow,
              gridField.getAD_Column_ID(),
              m_WindowNo);
      if (vad.isChanged()) {
        getComponent().setText(vad.getM_AttributeSetInstanceName());
        M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
        if (m_GridTab != null && !productWindow && vad.getM_Locator_ID() > 0)
          m_GridTab.setValue("M_Locator_ID", vad.getM_Locator_ID());
        changed = true;
      }
    }
    /**
     * Selection { // Get Model MAttributeSetInstance masi = MAttributeSetInstance.get(Env.getCtx(),
     * M_AttributeSetInstance_ID, M_Product_ID); if (masi == null) { log.log(Level.SEVERE, "No Model
     * for M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", M_Product_ID=" +
     * M_Product_ID); } else { Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID",
     * masi.getM_AttributeSet_ID()); // Get Attribute Set MAttributeSet as =
     * masi.getMAttributeSet(); // Product has no Attribute Set if (as == null)
     * ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet"); // Product has no Instance
     * Attributes else if (!as.isInstanceAttribute()) ADialog.error(m_WindowNo, this,
     * "PAttributeNoInstanceAttribute"); else { int M_Warehouse_ID = Env.getContextAsInt (Env.getCtx
     * (), m_WindowNo, "M_Warehouse_ID"); int M_Locator_ID = Env.getContextAsInt (Env.getCtx (),
     * m_WindowNo, "M_Locator_ID"); String title = ""; PAttributeInstance pai = new
     * PAttributeInstance ( Env.getFrame(this), title, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
     * m_C_BPartner_ID); if (pai.getM_AttributeSetInstance_ID() != -1) {
     * m_text.setText(pai.getM_AttributeSetInstanceName()); M_AttributeSetInstance_ID =
     * pai.getM_AttributeSetInstance_ID(); changed = true; } } } }
     */

    //	Set Value
    if (changed) {
      log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
      m_value = new Object(); // 	force re-query display
      if (M_AttributeSetInstance_ID == 0) setValue(null);
      else setValue(new Integer(M_AttributeSetInstance_ID));

      ValueChangeEvent vce =
          new ValueChangeEvent(this, gridField.getColumnName(), new Object(), getValue());
      fireValueChange(vce);
      if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && gridField != null) {
        //  force Change - user does not realize that embedded object is already saved.
        m_GridTab.processFieldChange(gridField);
      }
    } //	change
  } //  cmd_file
Exemple #14
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