Package org.compiere.model
Class MUOMConversion
java.lang.Object
org.compiere.model.PO
org.compiere.model.X_C_UOM_Conversion
org.compiere.model.MUOMConversion
- All Implemented Interfaces:
Serializable,Cloneable,Comparator<Object>,I_C_UOM_Conversion,I_Persistent,Evaluatee,ImmutablePOSupport
Unit of Measure Conversion Model
- Version:
- $Id: MUOMConversion.java,v 1.3 2006/07/30 00:51:03 jjanke Exp $
- Author:
- Jorg Janke
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final BigDecimalIndicator for Rateprotected static final CCache<Integer,MUOMConversion[]> Product Conversion Mapprotected static CCache<Point,BigDecimal> Conversion Map: Key=Point(from,to) Value=BigDecimalFields inherited from class org.compiere.model.PO
ACCESSLEVEL_ALL, ACCESSLEVEL_CLIENT, ACCESSLEVEL_CLIENTORG, ACCESSLEVEL_ORG, ACCESSLEVEL_SYSTEM, ACCESSLEVEL_SYSTEMCLIENT, ENTITYTYPE_Dictionary, ENTITYTYPE_UserMaintained, I_ZERO, LOCAL_TRX_PREFIX, log, p_ctx, p_info, UUID_NEW_RECORD, XML_ATTRIBUTE_AD_Table_ID, XML_ATTRIBUTE_Record_IDFields inherited from interface org.compiere.model.I_C_UOM_Conversion
accessLevel, COLUMNNAME_AD_Client_ID, COLUMNNAME_AD_Org_ID, COLUMNNAME_C_UOM_Conversion_ID, COLUMNNAME_C_UOM_Conversion_UU, COLUMNNAME_C_UOM_ID, COLUMNNAME_C_UOM_To_ID, COLUMNNAME_Created, COLUMNNAME_CreatedBy, COLUMNNAME_DivideRate, COLUMNNAME_IsActive, COLUMNNAME_M_Product_ID, COLUMNNAME_MultiplyRate, COLUMNNAME_Updated, COLUMNNAME_UpdatedBy, Model, Table_ID, Table_Name -
Constructor Summary
ConstructorsConstructorDescriptionMUOMConversion(Properties ctx, int C_UOM_Conversion_ID, String trxName) Default ConstructorMUOMConversion(Properties ctx, String C_UOM_Conversion_UU, String trxName) UUID based ConstructorMUOMConversion(Properties ctx, ResultSet rs, String trxName) Load ConstructorMUOMConversion(Properties ctx, MUOMConversion copy) Copy constructorMUOMConversion(Properties ctx, MUOMConversion copy, String trxName) Copy constructorMUOMConversion(MProduct parent) Parent ConstructorMUOMConversion(MUOM parent) Parent ConstructorMUOMConversion(MUOMConversion copy) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbeforeSave(boolean newRecord) Called before Save for Pre-Save Operation.
Default implementation is nop, to be implemented in sub-classes that needed it.static BigDecimalconvert(int C_UOM_From_ID, int C_UOM_To_ID, BigDecimal qty, boolean StdPrecision) Get Converted Qty from Server (no cache)static BigDecimalconvert(Properties ctx, int C_UOM_ID, int C_UOM_To_ID, BigDecimal qty) Convert qty to target UOM and round.static BigDecimalconvertProductFrom(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice) Convert PRICE expressed in product UoM to equivalent price in entered UoM and round.static BigDecimalconvertProductFrom(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice, int precision) Convert PRICE expressed in product UoM to equivalent price in entered UoM and round.static BigDecimalconvertProductTo(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice) Convert PRICE expressed in entered UoM to equivalent price in product UoM and round.static BigDecimalconvertProductTo(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice, int precision) Convert PRICE expressed in entered UoM to equivalent price in product UoM and round.static intconvertToMinutes(Properties ctx, int C_UOM_ID, BigDecimal qty) Convert qty to target UOM and round.protected static voidcreateRates(Properties ctx) Load conversion rate into cachestatic BigDecimalderiveRate(Properties ctx, int C_UOM_ID, int C_UOM_To_ID) Derive Standard Conversionsstatic TimestampgetEndDate(Properties ctx, Timestamp startDate, int C_UOM_ID, BigDecimal qty) Calculate End Date based on start date and qtystatic BigDecimalgetOppositeRate(BigDecimal rate) Calculate opposite conversion rate, i.e calculate divide rate from multiply rate and vice versa.static BigDecimalgetOppositeRate(BigDecimal rate, int scale) Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.static MUOMConversion[]getProductConversions(Properties ctx, int M_Product_ID) Get Product Conversions (cached)static BigDecimalgetProductRateFrom(Properties ctx, int M_Product_ID, int C_UOM_To_ID) Get multiply rate to convert PRICE from price in entered UOM to price in product UOM
OR multiply rate to convert QTY from product UOM to entered UOM.static BigDecimalgetProductRateTo(Properties ctx, int M_Product_ID, int C_UOM_To_ID) Get multiply rate to convert PRICE from price in entered UOM to price in product UOM
OR multiply rate to convert QTY from product UOM to entered UOMstatic BigDecimalgetRate(int C_UOM_ID, int C_UOM_To_ID) Get Conversion Multiplier Rate from Serverstatic BigDecimalgetRate(Properties ctx, int C_UOM_ID, int C_UOM_To_ID) Get Multiplier Rate to target UOMprotected static BigDecimalgetRate(Properties ctx, Point p) Get Conversion Multiplier Rate, try to derive it if not found directlymark PO as immutabletoString()String RepresentationMethods inherited from class org.compiere.model.X_C_UOM_Conversion
get_AccessLevel, getC_UOM, getC_UOM_Conversion_ID, getC_UOM_Conversion_UU, getC_UOM_ID, getC_UOM_To, getC_UOM_To_ID, getDivideRate, getKeyNamePair, getM_Product, getM_Product_ID, getMultiplyRate, initPO, setC_UOM_Conversion_ID, setC_UOM_Conversion_UU, setC_UOM_ID, setC_UOM_To_ID, setDivideRate, setM_Product_ID, setMultiplyRateMethods inherited from class org.compiere.model.PO
afterDelete, afterSave, beforeDelete, buildInsertSQL, checkImmutable, clearCrossTenantSafe, clone, columnExists, columnExists, compare, copyPO, copyValues, copyValues, createAttachment, delete, delete, delete_Accounting, delete_Tree, deleteEx, deleteEx, dump, dump, equals, get_Attribute, get_Attributes, get_ColumnCount, get_ColumnDescription, get_ColumnDisplayType, get_ColumnIndex, get_ColumnLabel, get_ColumnLookup, get_ColumnName, get_DisplayValue, get_HashMap, get_ID, get_IDOld, get_KeyColumns, get_Logger, get_OptimisticLockingColumns, get_Table_ID, get_TableAttribute, get_TableAttributeAsBoolean, get_TableAttributeAsInt, get_TableAttributes, get_TableName, get_Translation, get_Translation, get_Translation, get_Translation, get_Translation, get_TrxName, get_UUID, get_Value, get_Value, get_ValueAsBoolean, get_ValueAsInt, get_ValueAsInt, get_ValueAsString, get_ValueAsString, get_ValueDifference, get_ValueDifference, get_ValueE, get_ValueOfColumn, get_ValueOld, get_ValueOld, get_ValueOldAsInt, get_WhereClause, get_WhereClause, get_xmlDocument, get_xmlString, getAD_Client_ID, getAD_Org_ID, getAllIDs, getAttachment, getAttachment, getAttachmentData, getCreated, getCreatedBy, getCtx, getDoc, getFindParameter, getPdfAttachment, getUpdated, getUpdatedBy, getUUIDColumnName, getUUIDColumnName, hashCode, insert_Accounting, insert_Tree, insert_Tree, is_Changed, is_Immutable, is_new, is_UseOptimisticLocking, is_ValueChanged, is_ValueChanged, isActive, isAttachment, isColumnMandatory, isColumnUpdateable, isMandatoryOK, isPdfAttachment, isReplication, load, load, load, load, loadByUU, loadComplete, loadDefaults, loadPO, loadSpecial, lock, makeImmutable, postDelete, retrieveIdOfParentValue, retrieveIdOfParentValue, save, save, saveCrossTenantSafe, saveCrossTenantSafeEx, saveCrossTenantSafeEx, saveEx, saveEx, saveNew_afterSetID, saveNew_getID, saveNewSpecial, saveReplica, saveUpdate, set_Attribute, set_ColumnUpdateable, set_CustomColumn, set_CustomColumnReturningBoolean, set_OptimisticLockingColumns, set_TrxName, set_TrxName, set_UseOptimisticLocking, set_Value, set_Value, set_Value, set_Value, set_ValueE, set_ValueNoCheck, set_ValueNoCheckE, set_ValueOfColumn, set_ValueOfColumn, set_ValueOfColumnReturningBoolean, set_ValueOfColumnReturningBoolean, setAD_Client_ID, setAD_Org_ID, setClientOrg, setClientOrg, setCrossTenantSafe, setDoc, setDocWorkflowMgr, setIsActive, setProcessedOn, setReplication, setStandardDefaults, setUpdateable, setUpdatedBy, toInsertSQL, unlock, update_Tree, validForeignKeys, validForeignKeysExMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongMethods inherited from interface org.compiere.model.I_C_UOM_Conversion
getAD_Client_ID, getAD_Org_ID, getCreated, getCreatedBy, getUpdated, getUpdatedBy, isActive, setAD_Org_ID, setIsActiveMethods inherited from interface org.compiere.model.I_Persistent
save
-
Field Details
-
GETRATE
Indicator for Rate -
s_conversions
Conversion Map: Key=Point(from,to) Value=BigDecimal -
s_conversionProduct
Product Conversion Map
-
-
Constructor Details
-
MUOMConversion
UUID based Constructor- Parameters:
ctx- ContextC_UOM_Conversion_UU- UUID keytrxName- Transaction
-
MUOMConversion
Default Constructor- Parameters:
ctx- contextC_UOM_Conversion_ID- idtrxName- transaction
-
MUOMConversion
Load Constructor- Parameters:
ctx- contextrs- result settrxName- transaction
-
MUOMConversion
Parent Constructor- Parameters:
parent- uom parent
-
MUOMConversion
Parent Constructor- Parameters:
parent- product parent
-
MUOMConversion
Copy constructor- Parameters:
copy-
-
MUOMConversion
Copy constructor- Parameters:
ctx-copy-
-
MUOMConversion
Copy constructor- Parameters:
ctx-copy-trxName-
-
-
Method Details
-
convert
Convert qty to target UOM and round.- Parameters:
ctx- contextC_UOM_ID- from UOMC_UOM_To_ID- to UOMqty- qty- Returns:
- converted qty (std precision)
-
getRate
Get Multiplier Rate to target UOM- Parameters:
ctx- contextC_UOM_ID- from UOMC_UOM_To_ID- to UOM- Returns:
- multiplier
-
convertToMinutes
Convert qty to target UOM and round.- Parameters:
ctx- contextC_UOM_ID- from UOMqty- qty- Returns:
- minutes - 0 if not found
-
getEndDate
public static Timestamp getEndDate(Properties ctx, Timestamp startDate, int C_UOM_ID, BigDecimal qty) Calculate End Date based on start date and qty- Parameters:
ctx- contextstartDate- dateC_UOM_ID- UOMqty- qty- Returns:
- end date
-
getRate
Get Conversion Multiplier Rate, try to derive it if not found directly- Parameters:
ctx- contextp- Point with from(x) - to(y) C_UOM_ID- Returns:
- conversion multiplier or null
-
createRates
Load conversion rate into cache- Parameters:
ctx- context
-
deriveRate
Derive Standard Conversions- Parameters:
ctx- contextC_UOM_ID- from UOMC_UOM_To_ID- to UOM- Returns:
- Conversion or null
-
getRate
Get Conversion Multiplier Rate from Server- Parameters:
C_UOM_ID- from UOMC_UOM_To_ID- to UOM- Returns:
- conversion multiplier or null
-
convert
public static BigDecimal convert(int C_UOM_From_ID, int C_UOM_To_ID, BigDecimal qty, boolean StdPrecision) Get Converted Qty from Server (no cache)- Parameters:
qty- The quantity to be convertedC_UOM_From_ID- The C_UOM_ID of the qtyC_UOM_To_ID- The targeted UOMStdPrecision- if true, standard precision, if false costing precision- Returns:
- amount
-
convertProductTo
public static BigDecimal convertProductTo(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice) Convert PRICE expressed in entered UoM to equivalent price in product UoM and round.
OR Convert QTY in product UOM to qty in entered UoM and round.
eg: $6/6pk => $1/ea
OR 6 X ea => 1 X 6pk- Parameters:
ctx- contextM_Product_ID- productC_UOM_To_ID- entered UOMqtyPrice- quantity or price- Returns:
- Product: Qty/Price (precision rounded)
-
convertProductTo
public static BigDecimal convertProductTo(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice, int precision) Convert PRICE expressed in entered UoM to equivalent price in product UoM and round.
OR Convert QTY in product UOM to qty in entered UoM and round.
eg: $6/6pk => $1/ea
OR 6 X ea => 1 X 6pk- Parameters:
ctx- contextM_Product_ID- productC_UOM_To_ID- entered UOMqtyPrice- quantity or priceprecision- Rounding precision, -1 to use precision from UOM- Returns:
- Product: Qty/Price (precision rounded)
-
getProductRateTo
Get multiply rate to convert PRICE from price in entered UOM to price in product UOM
OR multiply rate to convert QTY from product UOM to entered UOM- Parameters:
ctx- contextM_Product_ID- productC_UOM_To_ID- entered UOM- Returns:
- multiplier or null
-
convertProductFrom
public static BigDecimal convertProductFrom(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice) Convert PRICE expressed in product UoM to equivalent price in entered UoM and round.
OR Convert QTY in entered UOM to qty in product UoM and round.
eg: $1/ea => $6/6pk
OR 1 X 6pk => 6 X ea- Parameters:
ctx- contextM_Product_ID- productC_UOM_To_ID- entered UOMqtyPrice- quantity or price- Returns:
- Product: Qty/Price (precision rounded)
-
convertProductFrom
public static BigDecimal convertProductFrom(Properties ctx, int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice, int precision) Convert PRICE expressed in product UoM to equivalent price in entered UoM and round.
OR Convert QTY in entered UOM to qty in product UoM and round.
eg: $1/ea => $6/6pk
OR 1 X 6pk => 6 X ea- Parameters:
ctx- contextM_Product_ID- productC_UOM_To_ID- entered UOMqtyPrice- quantity or priceprecision- Rounding precision, -1 to use precision from UOM- Returns:
- Product: Qty/Price (precision rounded)
-
getProductRateFrom
Get multiply rate to convert PRICE from price in entered UOM to price in product UOM
OR multiply rate to convert QTY from product UOM to entered UOM.- Parameters:
ctx- contextM_Product_ID- productC_UOM_To_ID- entered UOM- Returns:
- multiplier or null
-
getProductConversions
Get Product Conversions (cached)- Parameters:
ctx- contextM_Product_ID- product- Returns:
- array of conversions
-
beforeSave
protected boolean beforeSave(boolean newRecord) Description copied from class:POCalled before Save for Pre-Save Operation.
Default implementation is nop, to be implemented in sub-classes that needed it.- Overrides:
beforeSavein classPO- Parameters:
newRecord- true if it is a new record- Returns:
- true if record can be saved
-
toString
String Representation- Overrides:
toStringin classX_C_UOM_Conversion- Returns:
- info
-
markImmutable
Description copied from interface:ImmutablePOSupportmark PO as immutable- Specified by:
markImmutablein interfaceImmutablePOSupport- Returns:
- PO
-
getOppositeRate
Calculate opposite conversion rate, i.e calculate divide rate from multiply rate and vice versa.- Parameters:
rate-- Returns:
- opposite conversion rate
-
getOppositeRate
Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.- Parameters:
rate-- Returns:
BigDecimal
-