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
public class MCost extends X_M_Cost
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MCost.QtyCost
MCost Qty-Cost Pair
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_manual
Data is entered Manually-
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, 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
Constructors Constructor Description MCost(Properties ctx, int ignored, String trxName)
Standard 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(BigDecimal amt, BigDecimal qty)
Add Cumulative Amt/Qty and Current Qtyprotected boolean
beforeDelete()
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 from Trxstatic BigDecimal
calculateAveragePO(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate Average POstatic BigDecimal
calculateFiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate FiFo Coststatic BigDecimal
calculateLiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate LiFo costsstatic void
create(MClient client)
Create costing for client.protected static void
create(MProduct product)
Create standard Costing records for Productprotected static void
delete(MProduct product)
Delete standard Costing records for Productstatic 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.MCostElement
getCostElement()
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)
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 PriceBigDecimal
getHistoryAverage()
Get History Average (Amt/Qty)static BigDecimal
getLastInvoicePrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
Get Last 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
getPrecision()
Get Costing Precisionprotected static BigDecimal
getSeedCostFromPriceList(MProduct product, MAcctSchema as, int orgID)
static BigDecimal
getSeedCosts(MProduct product, int M_ASI_ID, MAcctSchema as, int Org_ID, String costingMethod, int C_OrderLine_ID)
Get Seed Costsstatic void
main(String[] args)
Testvoid
setCurrentCostPrice(BigDecimal currentCostPrice)
Set Current Cost Pricevoid
setCurrentQty(BigDecimal CurrentQty)
Set Current Quantity.void
setWeightedAverage(BigDecimal amt, BigDecimal qty)
Add Amt/Qty and calculate weighted average.void
setWeightedAverageInitial(BigDecimal amtUnit)
String
toString()
String Representation-
Methods 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, 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_Value, get_Value, get_ValueAsBoolean, get_ValueAsInt, get_ValueAsInt, 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, load, loadByUU, loadComplete, loadDefaults, loadSpecial, lock, makeImmutable, postDelete, retrieveIdOfParentValue, retrieveIdOfParentValue, save, save, 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, 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
-
-
-
-
Constructor Detail
-
MCost
public MCost(Properties ctx, int ignored, String trxName)
Standard Constructor- Parameters:
ctx
- contextignored
- multi-keytrxName
- trx
-
MCost
public MCost(Properties ctx, ResultSet rs, String trxName)
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 Detail
-
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
- real asias
- accounting schemaAD_Org_ID
- real orgcostingMethod
- 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)
Get Current Cost Price for Costing Level- Parameters:
product
- productM_ASI_ID
- costing level asiOrg_ID
- costing level orgM_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 level asias
- accounting schemaOrg_ID
- costing level orgcostingMethod
- costing methodC_OrderLine_ID
- optional order line- Returns:
- price or null
-
getSeedCostFromPriceList
protected static BigDecimal getSeedCostFromPriceList(MProduct product, MAcctSchema as, int orgID)
-
getLastInvoicePrice
public static BigDecimal getLastInvoicePrice(MProduct product, int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
Get Last 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
public static BigDecimal getPOPrice(MProduct product, int C_OrderLine_ID, int C_Currency_ID)
Get PO Price in currency- Parameters:
product
- productC_OrderLine_ID
- order lineC_Currency_ID
- accounting currency- Returns:
- last PO price in currency or null
-
create
public static void create(MClient client)
Create costing for client. Handles Transaction if not in a transaction- Parameters:
client
- client
-
create
protected static void create(MProduct product)
Create standard Costing records for Product- Parameters:
product
- product
-
delete
protected static void delete(MProduct product)
Delete standard Costing records for Product- Parameters:
product
- product
-
calculateAverageInv
public static BigDecimal calculateAverageInv(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate Average Invoice from Trx- Parameters:
product
- productM_AttributeSetInstance_ID
- optional asias
- acct schemaAD_Org_ID
- optonal org- Returns:
- average costs or null
-
calculateAveragePO
public static BigDecimal calculateAveragePO(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate Average PO- Parameters:
product
- productM_AttributeSetInstance_ID
- asias
- acct schemaAD_Org_ID
- org- Returns:
- costs or null
-
calculateFiFo
public static BigDecimal calculateFiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate FiFo Cost- Parameters:
product
- productM_AttributeSetInstance_ID
- asias
- acct schemaAD_Org_ID
- org- Returns:
- costs or null
-
calculateLiFo
public static BigDecimal calculateLiFo(MProduct product, int M_AttributeSetInstance_ID, MAcctSchema as, int AD_Org_ID)
Calculate LiFo costs- Parameters:
product
- productM_AttributeSetInstance_ID
- asias
- acct schemaAD_Org_ID
- org- Returns:
- 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:
- cost 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
public void add(BigDecimal amt, BigDecimal qty)
Add Cumulative Amt/Qty and Current Qty- Parameters:
amt
- amtqty
- qty
-
setWeightedAverage
public void setWeightedAverage(BigDecimal amt, BigDecimal qty)
Add Amt/Qty and calculate weighted average. ((OldAvg*OldQty)+(Price*Qty)) / (OldQty+Qty)- Parameters:
amt
- total amt (price * qty)qty
- qty
-
setWeightedAverageInitial
public void setWeightedAverageInitial(BigDecimal amtUnit)
- Parameters:
amtUnit
- unit amt
-
getPrecision
protected int getPrecision()
Get Costing Precision- Returns:
- precision (6)
-
setCurrentCostPrice
public void setCurrentCostPrice(BigDecimal currentCostPrice)
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
public BigDecimal getHistoryAverage()
Get History Average (Amt/Qty)- Returns:
- average if amt/aty <> 0 otherwise null
-
toString
public String toString()
String Representation
-
getCostElement
public MCostElement 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
public void setCurrentQty(BigDecimal CurrentQty)
Description copied from class:X_M_Cost
Set Current Quantity.- Specified by:
setCurrentQty
in interfaceI_M_Cost
- Overrides:
setCurrentQty
in classX_M_Cost
- Parameters:
CurrentQty
- Current Quantity
-
main
public static void main(String[] args)
Test- Parameters:
args
- ignored
-
-