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
Modifier and TypeFieldDescriptionprotected static final BigDecimal
Indicator 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_ID
Fields 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
ConstructorDescriptionMUOMConversion
(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) MUOMConversion
(Properties ctx, MUOMConversion copy, String trxName) MUOMConversion
(MProduct parent) Parent ConstructorMUOMConversion
(MUOM parent) Parent ConstructorMUOMConversion
(MUOMConversion copy) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
beforeSave
(boolean newRecord) Before Savestatic BigDecimal
convert
(int C_UOM_From_ID, int C_UOM_To_ID, BigDecimal qty, boolean StdPrecision) Get Converted Qty from Server (no cache)static BigDecimal
convert
(Properties ctx, int C_UOM_ID, int C_UOM_To_ID, BigDecimal qty) Convert qty to target UOM and round.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.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.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.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.static int
convertToMinutes
(Properties ctx, int C_UOM_ID, BigDecimal qty) Convert qty to target UOM and round.protected static void
createRates
(Properties ctx) Create Conversion Matrix (Client)static BigDecimal
deriveRate
(Properties ctx, int C_UOM_ID, int C_UOM_To_ID) Derive Standard Conversionsstatic Timestamp
getEndDate
(Properties ctx, Timestamp startDate, int C_UOM_ID, BigDecimal qty) Calculate End Date based on start date and qtystatic BigDecimal
getOppositeRate
(BigDecimal rate) Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.static BigDecimal
getOppositeRate
(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 BigDecimal
getProductRateFrom
(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 BigDecimal
getProductRateTo
(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 BigDecimal
getRate
(int C_UOM_ID, int C_UOM_To_ID) Get Conversion Multiplier Rate from Serverstatic BigDecimal
getRate
(Properties ctx, int C_UOM_ID, int C_UOM_To_ID) Get Multiplier Rate to target UOMprotected static BigDecimal
getRate
(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, setMultiplyRate
Methods 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_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
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface org.compiere.model.I_C_UOM_Conversion
getAD_Client_ID, getAD_Org_ID, getCreated, getCreatedBy, getUpdated, getUpdatedBy, isActive, setAD_Org_ID, setIsActive
Methods 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
- Parameters:
copy
-
-
MUOMConversion
- Parameters:
ctx
-copy
-
-
MUOMConversion
- 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
Create Conversion Matrix (Client)- 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) Before Save- Overrides:
beforeSave
in classPO
- Parameters:
newRecord
- new- Returns:
- true if can be saved
-
toString
String Representation- Overrides:
toString
in classX_C_UOM_Conversion
- Returns:
- info
-
markImmutable
Description copied from interface:ImmutablePOSupport
mark PO as immutable- Specified by:
markImmutable
in interfaceImmutablePOSupport
- Returns:
- PO
-
getOppositeRate
Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.- Parameters:
rate
-- Returns:
BigDecimal
-
getOppositeRate
Calculate opposite conversion rate, i.e calculate divide rate for multiply rate and vice versa.- Parameters:
rate
-- Returns:
BigDecimal
-