/** * Before Save * * @param newRecord new * @return true */ protected boolean beforeSave(boolean newRecord) { // Org Consistency if (newRecord || is_ValueChanged("C_CashBook_ID") || is_ValueChanged("M_Warehouse_ID")) { MCashBook cb = MCashBook.get(getCtx(), getC_CashBook_ID(), get_TrxName()); if (cb.getAD_Org_ID() != getAD_Org_ID()) { log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @C_CashBook_ID@")); return false; } MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID(), get_TrxName()); if (wh.getAD_Org_ID() != getAD_Org_ID()) { log.saveError("Error", Msg.parseTranslation(getCtx(), "@AD_Org_ID@: @M_Warehouse_ID@")); return false; } } return true; } // beforeSave
/** * Set (default) Locator based on qty. * * @param Qty quantity Assumes Warehouse is set */ public void setM_Locator_ID(BigDecimal Qty) { // Locator established if (getM_Locator_ID() != 0) return; // No Product if (getM_Product_ID() == 0) { set_ValueNoCheck(COLUMNNAME_M_Locator_ID, null); return; } // Get existing Location int M_Locator_ID = MStorage.getM_Locator_ID( getM_Warehouse_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), Qty, get_TrxName()); // Get default Location if (M_Locator_ID == 0) { MWarehouse wh = MWarehouse.get(getCtx(), getM_Warehouse_ID()); M_Locator_ID = wh.getDefaultLocator().getM_Locator_ID(); } setM_Locator_ID(M_Locator_ID); } // setM_Locator_ID
/** * ************************************************************************ Before Save * * @param newRecord new * @return save */ protected boolean beforeSave(boolean newRecord) { log.fine(""); if (newRecord && getParent().isComplete()) { log.saveError("ParentComplete", Msg.translate(getCtx(), "M_InOutLine")); return false; } // Locator is mandatory if no charge is defined - teo_sarca BF [ 2757978 ] if (getProduct() != null && MProduct.PRODUCTTYPE_Item.equals(getProduct().getProductType())) { if (getM_Locator_ID() <= 0 && getC_Charge_ID() <= 0) { throw new FillMandatoryException(COLUMNNAME_M_Locator_ID); } } // Get Line No if (getLine() == 0) { String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM M_InOutLine WHERE M_InOut_ID=?"; int ii = DB.getSQLValueEx(get_TrxName(), sql, getM_InOut_ID()); setLine(ii); } // UOM if (getC_UOM_ID() == 0) setC_UOM_ID(Env.getContextAsInt(getCtx(), "#C_UOM_ID")); if (getC_UOM_ID() == 0) { int C_UOM_ID = MUOM.getDefault_UOM_ID(getCtx()); if (C_UOM_ID > 0) setC_UOM_ID(C_UOM_ID); } // Qty Precision if (newRecord || is_ValueChanged("QtyEntered")) setQtyEntered(getQtyEntered()); if (newRecord || is_ValueChanged("MovementQty")) setMovementQty(getMovementQty()); // Order/RMA Line if (getC_OrderLine_ID() == 0 && getM_RMALine_ID() == 0) { if (getParent().isSOTrx()) { log.saveError("FillMandatory", Msg.translate(getCtx(), "C_Order_ID")); return false; } } // Validate Locator/Warehouse - teo_sarca, BF [ 2784194 ] if (getM_Locator_ID() > 0) { MLocator locator = MLocator.get(getCtx(), getM_Locator_ID()); if (getM_Warehouse_ID() != locator.getM_Warehouse_ID()) { throw new WarehouseLocatorConflictException( MWarehouse.get(getCtx(), getM_Warehouse_ID()), locator, getLine()); } } // if (getC_Charge_ID() == 0 && getM_Product_ID() == 0) // ; /** * Qty on instance ASI if (getM_AttributeSetInstance_ID() != 0) { MProduct product = * getProduct(); int M_AttributeSet_ID = product.getM_AttributeSet_ID(); boolean isInstance = * M_AttributeSet_ID != 0; if (isInstance) { MAttributeSet mas = MAttributeSet.get(getCtx(), * M_AttributeSet_ID); isInstance = mas.isInstanceAttribute(); } // Max if (isInstance) { * MStorage storage = MStorage.get(getCtx(), getM_Locator_ID(), getM_Product_ID(), * getM_AttributeSetInstance_ID(), get_TrxName()); if (storage != null) { BigDecimal qty = * storage.getQtyOnHand(); if (getMovementQty().compareTo(qty) > 0) { log.warning("Qty - Stock=" * + qty + ", Movement=" + getMovementQty()); log.saveError("QtyInsufficient", "=" + qty); * return false; } } } } /* */ return true; } // beforeSave