Package org.compiere.model
Class MCost
java.lang.Object
org.compiere.model.PO
org.compiere.model.X_M_Cost
org.compiere.model.MCost
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparator<Object>
,I_M_Cost
,I_Persistent
,Evaluatee
Product Cost Model
- Version:
- $Id: MCost.java,v 1.6 2006/07/30 00:51:02 jjanke Exp $
- Author:
- Jorg Janke, Carlos Ruiz - globalqss
- integrate bug fix from Teo Sarca - [ 1619112 ] Posible problem for LastPO costing, Batch/Lot level, Red1
- FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 (only non-join query), Teo Sarca
- BF [ 2847648 ] Manufacture and shipment cost errors https://sourceforge.net/p/adempiere/libero/237/
- See Also:
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.compiere.model.X_M_Cost
COSTINGMETHOD__, COSTINGMETHOD_AD_Reference_ID, COSTINGMETHOD_AverageInvoice, COSTINGMETHOD_AveragePO, COSTINGMETHOD_Fifo, COSTINGMETHOD_LastInvoice, COSTINGMETHOD_LastPOPrice, COSTINGMETHOD_Lifo, COSTINGMETHOD_StandardCosting, COSTINGMETHOD_UserDefined
Fields 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_M_Cost
accessLevel, COLUMNNAME_AD_Client_ID, COLUMNNAME_AD_Org_ID, COLUMNNAME_C_AcctSchema_ID, COLUMNNAME_CostingMethod, COLUMNNAME_Created, COLUMNNAME_CreatedBy, COLUMNNAME_CumulatedAmt, COLUMNNAME_CumulatedQty, COLUMNNAME_CurrentCostPrice, COLUMNNAME_CurrentCostPriceLL, COLUMNNAME_CurrentQty, COLUMNNAME_Description, COLUMNNAME_FutureCostPrice, COLUMNNAME_FutureCostPriceLL, COLUMNNAME_IsActive, COLUMNNAME_IsCostFrozen, COLUMNNAME_M_AttributeSetInstance_ID, COLUMNNAME_M_Cost_UU, COLUMNNAME_M_CostElement_ID, COLUMNNAME_M_CostType_ID, COLUMNNAME_M_Product_ID, COLUMNNAME_Percent, COLUMNNAME_Processed, COLUMNNAME_Updated, COLUMNNAME_UpdatedBy, Model, Table_ID, Table_Name
-
Constructor Summary
ConstructorDescriptionMCost
(Properties ctx, int ignored, String trxName) Standard ConstructorMCost
(Properties ctx, String M_Cost_UU, String trxName) UUID based ConstructorMCost
(Properties ctx, ResultSet rs, String trxName) Load ConstructorMCost
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID) Parent Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(BigDecimal amt, BigDecimal qty) Add to Cumulative Amt/Qty and Current Qtyprotected boolean
Before Deleteprotected boolean
beforeSave
(boolean newRecord) Before Savestatic BigDecimal
calculateAverageInv
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate Average Invoice Cost from M_Transactionstatic BigDecimal
calculateAveragePO
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate Average PO from M_Transactionstatic BigDecimal
calculateFiFo
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate FiFo Cost from M_Transactionstatic BigDecimal
calculateLiFo
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate LiFo costs from M_Transactionstatic void
Calculate costing for client.protected static void
Create standard Costing records for Productprotected static void
Delete costing records for Product (for client and organization costing level)static MCost
get
(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID, int M_AttributeSetInstance_ID) Deprecated.static MCost
get
(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID, int M_AttributeSetInstance_ID, String trxName) Get Cost Recordstatic MCost
get
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID) Deprecated.static MCost
get
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID, String trxName) Get/Create Cost Record.Get Cost Elementstatic BigDecimal
getCurrentCost
(MProduct product, int M_AttributeSetInstance_ID, String trxName) protected static BigDecimal
getCurrentCost
(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, int M_CostType_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, String trxName) Calculate and Get Current Cost Price for Costing Levelstatic BigDecimal
getCurrentCost
(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, String trxName) Retrieve/Calculate Current Cost PriceGet History Average (Amt/Qty)static BigDecimal
getLastInvoicePrice
(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID) Get Last Vendor Invoice Price in currencystatic BigDecimal
getLastPOPrice
(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID) Get Last PO Price in currencystatic BigDecimal
getPOPrice
(MProduct product, int C_OrderLine_ID, int C_Currency_ID) Get PO Price in currencyprotected int
Get Costing Precisionprotected static BigDecimal
getSeedCostFromPriceList
(MProduct product, MAcctSchema as, int orgID) Get seed cost from purchase price liststatic BigDecimal
getSeedCosts
(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, String costingMethod, int C_OrderLine_ID) Get Seed Costsvoid
setCurrentCostPrice
(BigDecimal currentCostPrice) Set Current Cost Pricevoid
setCurrentQty
(BigDecimal CurrentQty) ThrowAverageCostingNegativeQtyException
if cost element is average po or average invoice and currentQty < 0.void
setWeightedAverage
(BigDecimal amt, BigDecimal qty) Add to cumulative Amt/Qty, current qty and calculate new weighted average cost.
((OldAvg*OldQty)+(Price*Qty)) / (OldQty+Qty).void
setWeightedAverageInitial
(BigDecimal amtUnit) toString()
String RepresentationMethods inherited from class org.compiere.model.X_M_Cost
get_AccessLevel, getC_AcctSchema, getC_AcctSchema_ID, getCostingMethod, getCumulatedAmt, getCumulatedQty, getCurrentCostPrice, getCurrentCostPriceLL, getCurrentQty, getDescription, getFutureCostPrice, getFutureCostPriceLL, getM_AttributeSetInstance, getM_AttributeSetInstance_ID, getM_Cost_UU, getM_CostElement, getM_CostElement_ID, getM_CostType, getM_CostType_ID, getM_Product, getM_Product_ID, getPercent, initPO, isCostFrozen, isProcessed, setC_AcctSchema_ID, setCostingMethod, setCumulatedAmt, setCumulatedQty, setCurrentCostPriceLL, setDescription, setFutureCostPrice, setFutureCostPriceLL, setIsCostFrozen, setM_AttributeSetInstance_ID, setM_Cost_UU, setM_CostElement_ID, setM_CostType_ID, setM_Product_ID, setPercent, setProcessed
Methods inherited from class org.compiere.model.PO
afterDelete, afterSave, 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_M_Cost
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
-
m_manual
protected boolean m_manualData is entered Manually
-
-
Constructor Details
-
MCost
UUID based Constructor- Parameters:
ctx
- ContextM_Cost_UU
- UUID keytrxName
- Transaction
-
MCost
Standard Constructor- Parameters:
ctx
- contextignored
- multi-keytrxName
- trx
-
MCost
Load Constructor- Parameters:
ctx
- contextrs
- result settrxName
- trx
-
MCost
public MCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID) Parent Constructor- Parameters:
product
- ProductM_AttributeSetInstance_ID
- asias
- Acct SchemaAD_Org_ID
- orgM_CostElement_ID
- cost element
-
-
Method Details
-
getCurrentCost
public static BigDecimal getCurrentCost(MProduct product, int M_AttributeSetInstance_ID, String trxName) - Parameters:
product
-M_AttributeSetInstance_ID
-trxName
-- Returns:
- current product cost
-
getCurrentCost
public static BigDecimal getCurrentCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, String trxName) Retrieve/Calculate Current Cost Price- Parameters:
product
- productM_AttributeSetInstance_ID
- asi for batchlot costing levelas
- accounting schemaAD_Org_ID
- org for organization costing levelcostingMethod
- AcctSchema.COSTINGMETHOD_*qty
- qtyC_OrderLine_ID
- optional order linezeroCostsOK
- zero/no costs are OKtrxName
- trx- Returns:
- current cost price or null
-
getCurrentCost
protected static BigDecimal getCurrentCost(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, int M_CostType_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, String trxName) Calculate and Get Current Cost Price for Costing Level- Parameters:
product
- productM_ASI_ID
- M_AttributeSetInstance_ID for batchlot costing levelOrg_ID
- AD_Org_ID for organization costing levelM_CostType_ID
- cost typeas
- AcctSchemacostingMethod
- methodqty
- quantityC_OrderLine_ID
- optional order linezeroCostsOK
- zero/no costs are OKtrxName
- trx- Returns:
- cost price or null
-
getSeedCosts
public static BigDecimal getSeedCosts(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, String costingMethod, int C_OrderLine_ID) Get Seed Costs- Parameters:
product
- productM_ASI_ID
- costing M_AttributeSetInstance_ID for batchlot costing levelas
- accounting schemaOrg_ID
- AD_Org_ID for organization costing levelcostingMethod
- costing methodC_OrderLine_ID
- optional order line- Returns:
- seed cost or null
-
getSeedCostFromPriceList
Get seed cost from purchase price list- Parameters:
product
-as
-orgID
-- Returns:
- seed cost or null
-
getLastInvoicePrice
public static BigDecimal getLastInvoicePrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID) Get Last Vendor Invoice Price in currency- Parameters:
product
- productM_ASI_ID
- attribute set instanceAD_Org_ID
- orgC_Currency_ID
- accounting currency- Returns:
- last invoice price in currency
-
getLastPOPrice
public static BigDecimal getLastPOPrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID) Get Last PO Price in currency- Parameters:
product
- productM_ASI_ID
- attribute set instanceAD_Org_ID
- orgC_Currency_ID
- accounting currency- Returns:
- last PO price in currency or null
-
getPOPrice
Get PO Price in currency- Parameters:
product
- productC_OrderLine_ID
- order lineC_Currency_ID
- accounting currency- Returns:
- PO price for order line in currency or null
-
create
Calculate costing for client. Handles Transaction if not in a transaction.- Parameters:
client
- client
-
create
Create standard Costing records for Product- Parameters:
product
- product
-
delete
Delete costing records for Product (for client and organization costing level)- Parameters:
product
- product
-
calculateAverageInv
public static BigDecimal calculateAverageInv(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate Average Invoice Cost from M_Transaction- Parameters:
product
- productM_AttributeSetInstance_ID
- optional asias
- acct schemaAD_Org_ID
- optional org- Returns:
- average invoice costs or null
-
calculateAveragePO
public static BigDecimal calculateAveragePO(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate Average PO from M_Transaction- Parameters:
product
- productM_AttributeSetInstance_ID
- asias
- acct schemaAD_Org_ID
- org- Returns:
- average PO cost or null
-
calculateFiFo
public static BigDecimal calculateFiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate FiFo Cost from M_Transaction- Parameters:
product
- productM_AttributeSetInstance_ID
- asias
- acct schemaAD_Org_ID
- org- Returns:
- FIFO costs or null
-
calculateLiFo
public static BigDecimal calculateLiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate LiFo costs from M_Transaction- Parameters:
product
- productM_AttributeSetInstance_ID
- asias
- acct schemaAD_Org_ID
- org- Returns:
- LIFO costs or null
-
get
public static MCost get(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID, String trxName) Get/Create Cost Record. CostingLevel is not validated.- Parameters:
product
- productM_AttributeSetInstance_ID
- costing level asias
- accounting schemaAD_Org_ID
- costing level orgM_CostElement_ID
- element- Returns:
- cost price or null
-
get
@Deprecated public static MCost get(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID) Deprecated. -
get
public static MCost get(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID, int M_AttributeSetInstance_ID, String trxName) Get Cost Record- Parameters:
ctx
- contextAD_Client_ID
- clientAD_Org_ID
- orgM_Product_ID
- productM_CostType_ID
- cost typeC_AcctSchema_ID
- asM_CostElement_ID
- cost elementM_AttributeSetInstance_ID
- asitrxName
- transaction name- Returns:
- MCost or null
-
get
@Deprecated public static MCost get(Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID, int M_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID, int M_AttributeSetInstance_ID) Deprecated. -
add
Add to Cumulative Amt/Qty and Current Qty- Parameters:
amt
- amtqty
- qty
-
setWeightedAverage
Add to cumulative Amt/Qty, current qty and calculate new weighted average cost.
((OldAvg*OldQty)+(Price*Qty)) / (OldQty+Qty).- Parameters:
amt
- total amt (price * qty)qty
- qty
-
setWeightedAverageInitial
- Parameters:
amtUnit
- unit amt
-
getPrecision
protected int getPrecision()Get Costing Precision- Returns:
- precision (6)
-
setCurrentCostPrice
Set Current Cost Price- Specified by:
setCurrentCostPrice
in interfaceI_M_Cost
- Overrides:
setCurrentCostPrice
in classX_M_Cost
- Parameters:
currentCostPrice
- if null set to 0
-
getHistoryAverage
Get History Average (Amt/Qty)- Returns:
- average if amt/aty <> 0 otherwise null
-
toString
String Representation -
getCostElement
Get Cost Element- Returns:
- cost element
-
beforeSave
protected boolean beforeSave(boolean newRecord) Before Save- Overrides:
beforeSave
in classPO
- Parameters:
newRecord
- new- Returns:
- true if can be saved
-
beforeDelete
protected boolean beforeDelete()Before Delete- Overrides:
beforeDelete
in classPO
- Returns:
- true
-
setCurrentQty
ThrowAverageCostingNegativeQtyException
if cost element is average po or average invoice and currentQty < 0.- Specified by:
setCurrentQty
in interfaceI_M_Cost
- Overrides:
setCurrentQty
in classX_M_Cost
- Parameters:
CurrentQty
-
-