Search in sources :

Example 1 with MUOMConversion

use of org.compiere.model.MUOMConversion in project adempiere by adempiere.

the class ProductUOMConvert method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    if (p_M_Product_ID == 0 || p_M_Product_To_ID == 0 || p_M_Locator_ID == 0 || p_Qty == null || Env.ZERO.compareTo(p_Qty) == 0)
        throw new AdempiereUserError("Invalid Parameter");
    //
    MProduct product = MProduct.get(getCtx(), p_M_Product_ID);
    MProduct productTo = MProduct.get(getCtx(), p_M_Product_To_ID);
    log.info("Product=" + product + ", ProductTo=" + productTo + ", M_Locator_ID=" + p_M_Locator_ID + ", Qty=" + p_Qty);
    MUOMConversion[] conversions = MUOMConversion.getProductConversions(getCtx(), product.getM_Product_ID());
    MUOMConversion conversion = null;
    for (int i = 0; i < conversions.length; i++) {
        if (conversions[i].getC_UOM_To_ID() == productTo.getC_UOM_ID())
            conversion = conversions[i];
    }
    if (conversion == null)
        throw new AdempiereUserError("@NotFound@: @C_UOM_Conversion_ID@");
    MUOM uomTo = MUOM.get(getCtx(), productTo.getC_UOM_ID());
    BigDecimal qtyTo = p_Qty.divide(conversion.getDivideRate(), uomTo.getStdPrecision(), BigDecimal.ROUND_HALF_UP);
    BigDecimal qtyTo6 = p_Qty.divide(conversion.getDivideRate(), 6, BigDecimal.ROUND_HALF_UP);
    if (qtyTo.compareTo(qtyTo6) != 0)
        throw new AdempiereUserError("@StdPrecision@: " + qtyTo + " <> " + qtyTo6 + " (" + p_Qty + "/" + conversion.getDivideRate() + ")");
    log.info(conversion + " -> " + qtyTo);
    //	Set to Beta
    return "Not completed yet";
}
Also used : MUOMConversion(org.compiere.model.MUOMConversion) MProduct(org.compiere.model.MProduct) MUOM(org.compiere.model.MUOM) AdempiereUserError(org.compiere.util.AdempiereUserError) BigDecimal(java.math.BigDecimal)

Aggregations

BigDecimal (java.math.BigDecimal)1 MProduct (org.compiere.model.MProduct)1 MUOM (org.compiere.model.MUOM)1 MUOMConversion (org.compiere.model.MUOMConversion)1 AdempiereUserError (org.compiere.util.AdempiereUserError)1