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";
}
Aggregations