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,ICostInfo,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
Nested Classes -
Field Summary
FieldsFields 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_UserDefinedFields 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_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
ConstructorsConstructorDescriptionMCost(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 TypeMethodDescriptionvoidadd(BigDecimal amt, BigDecimal qty) Add to Cumulative Amt/Qty and Current Qtyprotected booleanbeforeSave(boolean newRecord) Validate costing level configuration.static BigDecimalcalculateAverageInv(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate Average Invoice Cost from M_Transactionstatic BigDecimalcalculateAveragePO(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate Average PO from M_Transactionstatic BigDecimalcalculateFiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate FiFo Cost from M_Transactionstatic BigDecimalcalculateLiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID) Calculate LiFo costs from M_Transactionstatic voidCalculate costing for client.protected static voidCreate standard Costing records for Productprotected static voidDelete costing records for Product (for client and organization costing level)static MCostget(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 MCostget(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 MCostget(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID) Deprecated.static MCostget(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID, String trxName) Get/Create Cost Record.protected static BigDecimalgetCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, Timestamp dateAcct, MCostDetail costDetail, boolean isInBackDatePostingProcess, String trxName) Retrieve/Calculate Cost PriceGet Cost Elementstatic ICostInfogetCostInfo(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, Timestamp dateAcct, MCostDetail costDetail, String trxName) Get Costing Record from MCostHistory/MCoststatic ICostInfogetCostInfo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID, Timestamp dateAcct, MCostDetail costDetail, String trxName) Get/Create Costing Record from MCostHistory/MCost CostingLevel is not validated.static BigDecimalgetCurrentCost(MProduct product, int M_AttributeSetInstance_ID, String trxName) protected static BigDecimalgetCurrentCost(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 BigDecimalgetCurrentCost(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 BigDecimalgetLastInvoicePrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID) Get Last Vendor Invoice Price in currencystatic BigDecimalgetLastPOPrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID) Get Last PO Price in currencystatic BigDecimalgetPOPrice(MProduct product, int C_OrderLine_ID, int C_Currency_ID) Get PO Price in currencyprotected intGet Costing Precisionprotected static BigDecimalgetSeedCostFromPriceList(MProduct product, MAcctSchema as, int orgID) Get seed cost from purchase price liststatic BigDecimalgetSeedCosts(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, String costingMethod, int C_OrderLine_ID) Get Seed CostsvoidsetCurrentCostPrice(BigDecimal currentCostPrice) Set Current Cost PricevoidsetCurrentQty(BigDecimal CurrentQty) ThrowAverageCostingNegativeQtyExceptionif cost element is average po or average invoice and currentQty < 0.voidsetWeightedAverage(BigDecimal amt, BigDecimal qty) Add to cumulative Amt/Qty, current qty and calculate new weighted average cost.
((OldAvg*OldQty)+(Price*Qty)) / (OldQty+Qty).voidsetWeightedAverageInitial(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, setProcessedMethods 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_M_Cost
getAD_Client_ID, getAD_Org_ID, getCreated, getCreatedBy, getUpdated, getUpdatedBy, isActive, setAD_Org_ID, setIsActiveMethods inherited from interface org.compiere.model.I_Persistent
saveMethods inherited from interface org.compiere.model.ICostInfo
getCumulatedAmt, getCumulatedQty, getCurrentCostPrice, getCurrentQty
-
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
-
getCost
protected static BigDecimal getCost(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, String costingMethod, BigDecimal qty, int C_OrderLine_ID, boolean zeroCostsOK, Timestamp dateAcct, MCostDetail costDetail, boolean isInBackDatePostingProcess, String trxName) Retrieve/Calculate Cost Price- Parameters:
product- productM_AttributeSetInstance_ID- asi for batchlot costing levelas- schemaAD_Org_ID- org for organization costing levelcostingMethod- AcctSchema.COSTINGMETHOD_*qty- qtyC_OrderLine_ID- optional order linezeroCostsOK- zero/no costs are OKdateAcct- account datecostDetail- optional cost detail - use to retrieve the cost historyisInBackDatePostingProcess- in a back-date posting processtrxName- trx- Returns:
- 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 levelas- AcctSchemaOrg_ID- AD_Org_ID for organization costing levelM_CostType_ID- cost typecostingMethod- 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- elementtrxName- transaction name- Returns:
- cost price or null
-
getCostInfo
public static ICostInfo getCostInfo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID, int M_CostElement_ID, Timestamp dateAcct, MCostDetail costDetail, String trxName) Get/Create Costing Record from MCostHistory/MCost CostingLevel is not validated.- Parameters:
product- productM_AttributeSetInstance_ID- costing level asias- accounting schemaAD_Org_ID- costing level orgM_CostElement_ID- elementdateAcct- account datecostDetail- optional cost detail - use to retrieve the cost historytrxName- transaction name- Returns:
- ICostInfo 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
-
getCostInfo
public static ICostInfo getCostInfo(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, Timestamp dateAcct, MCostDetail costDetail, String trxName) Get Costing Record from MCostHistory/MCost- 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- asidateAcct- account datecostDetail- optional cost detail - use to retrieve the cost historytrxName- transaction name- Returns:
- ICostInfo 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:
setCurrentCostPricein interfaceI_M_Cost- Overrides:
setCurrentCostPricein 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) Validate costing level configuration. Validate CurrentQty is positive for average costing.- Overrides:
beforeSavein classPO- Parameters:
newRecord- new- Returns:
- true if can be saved
-
setCurrentQty
ThrowAverageCostingNegativeQtyExceptionif cost element is average po or average invoice and currentQty < 0.- Specified by:
setCurrentQtyin interfaceI_M_Cost- Overrides:
setCurrentQtyin classX_M_Cost- Parameters:
CurrentQty-
-