/**
  * @param parent
  * @param M_AttributeSetInstance_ID
  * @param MovementQty
  * @param DateMaterialPolicy
  * @param isAutoGenerated
  */
 public MMovementLineMA(
     MMovementLine parent,
     int M_AttributeSetInstance_ID,
     BigDecimal MovementQty,
     Timestamp DateMaterialPolicy,
     boolean isAutoGenerated) {
   this(parent.getCtx(), 0, parent.get_TrxName());
   setClientOrg(parent);
   setM_MovementLine_ID(parent.getM_MovementLine_ID());
   //
   setM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
   setMovementQty(MovementQty);
   if (DateMaterialPolicy == null) {
     if (M_AttributeSetInstance_ID > 0) {
       MAttributeSetInstance asi =
           new MAttributeSetInstance(
               parent.getCtx(), M_AttributeSetInstance_ID, parent.get_TrxName());
       DateMaterialPolicy = asi.getCreated();
     } else {
       DateMaterialPolicy = parent.getParent().getMovementDate();
     }
   }
   setDateMaterialPolicy(DateMaterialPolicy);
   setIsAutoGenerated(isAutoGenerated);
 } //	MMovementLineMA
Example #2
0
  @Override
  protected boolean beforeSave(boolean newRecord) {
    //	Check Storage
    if (!newRecord
        && //
        ((is_ValueChanged("IsActive") && !isActive()) // 	now not active
            || (is_ValueChanged("IsStocked") && !isStocked()) // 	now not stocked
            || (is_ValueChanged("ProductType") // 	from Item
                && PRODUCTTYPE_Item.equals(get_ValueOld("ProductType"))))) {
      MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
      BigDecimal OnHand = Env.ZERO;
      BigDecimal Ordered = Env.ZERO;
      BigDecimal Reserved = Env.ZERO;
      for (int i = 0; i < storages.length; i++) {
        OnHand = OnHand.add(storages[i].getQtyOnHand());
        Ordered = Ordered.add(storages[i].getQtyOrdered());
        Reserved = Reserved.add(storages[i].getQtyReserved());
      }
      String errMsg = "";
      if (OnHand.signum() != 0) errMsg = "@QtyOnHand@ = " + OnHand;
      if (Ordered.signum() != 0) errMsg += " - @QtyOrdered@ = " + Ordered;
      if (Reserved.signum() != 0) errMsg += " - @QtyReserved@" + Reserved;
      if (errMsg.length() > 0) {
        log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
        return false;
      }
    } //	storage

    // it checks if UOM has been changed , if so disallow the change if the condition is true.
    if ((!newRecord) && is_ValueChanged("C_UOM_ID") && hasInventoryOrCost()) {
      log.saveError("Error", Msg.getMsg(getCtx(), "SaveUomError"));
      return false;
    }

    //	Reset Stocked if not Item
    // AZ Goodwill: Bug Fix isStocked always return false
    // if (isStocked() && !PRODUCTTYPE_Item.equals(getProductType()))
    if (!PRODUCTTYPE_Item.equals(getProductType())) setIsStocked(false);

    //	UOM reset
    if (m_precision != null && is_ValueChanged("C_UOM_ID")) m_precision = null;

    // AttributeSetInstance reset
    if (is_ValueChanged(COLUMNNAME_M_AttributeSet_ID)) {
      MAttributeSetInstance asi =
          new MAttributeSetInstance(getCtx(), getM_AttributeSetInstance_ID(), get_TrxName());
      setM_AttributeSetInstance_ID(0);
      // Delete the old m_attributesetinstance
      try {
        asi.deleteEx(true, get_TrxName());
      } catch (AdempiereException ex) {
        log.saveError("Error", "Error deleting the AttributeSetInstance");
        return false;
      }
    }

    return true;
  } //	beforeSave
Example #3
0
  /**
   * Get the Attribute Set Instance. This is called by callouts to fill the
   * M_AttributeSetInstance_ID field. The ASI should override the context if the product has a
   * defined ASI or if the context ASI does not use the same attribute set.
   *
   * @param ctx
   * @param WindowNo number
   */
  public Integer getEnvAttributeSetInstance(Properties ctx, int WindowNo) {
    Integer M_AttributeSetInstance_ID = 0;

    //	Set Attribute Instance from the context
    M_AttributeSetInstance_ID =
        Env.getContextAsInt(ctx, WindowNo, Env.TAB_INFO, "M_AttributeSetInstance_ID");
    //	Get Model and check if it has a product attribute instance
    if (getM_AttributeSetInstance_ID() > 0) {
      //  If the product has a product instance associated with it. Use it regardless of the
      // context.
      //  Product Attributes and Instance Attributes are exclusive
      M_AttributeSetInstance_ID = new Integer(getM_AttributeSetInstance_ID());
    } else if (getM_AttributeSet_ID() > 0 && M_AttributeSetInstance_ID > 0) {
      // Check compatibility of the instance with the product - they have to use the same set.
      MAttributeSetInstance masi =
          MAttributeSetInstance.get(
              Env.getCtx(), M_AttributeSetInstance_ID, this.getM_Product_ID());
      if (masi.getMAttributeSet().get_ID() != this.getAttributeSet().get_ID())
        M_AttributeSetInstance_ID = 0;
    }
    if (M_AttributeSetInstance_ID != 0) return M_AttributeSetInstance_ID;
    else return null;
  }