FR [ 2093551 ] Refactor/Add org.compiere.model.MProduct.getCostingLevel

FR [ 2093569 ] Refactor/Add org.compiere.model.MProduct.getCostingMethod
This commit is contained in:
teo_sarca 2008-09-04 18:27:37 +00:00
parent edd76b9323
commit dae6866242
6 changed files with 67 additions and 71 deletions

View File

@ -145,7 +145,6 @@ public class Doc_InOut extends Doc
// if Shipment CostDetail exist then get Cost from Cost Detail
BigDecimal costs = line.getProductCosts(as, line.getAD_Org_ID(), true, "M_InOutLine_ID=? AND M_AttributeSetInstance_ID=?");
// end MZ
if (costs == null || costs.signum() == 0) // zero costs OK
{
MProduct product = line.getProduct();
@ -292,11 +291,7 @@ public class Doc_InOut extends Doc
BigDecimal costs = null;
MProduct product = line.getProduct();
//get costing method for product
String costingMethod = as.getCostingMethod();
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(),
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), getTrxName());
if (pca.getCostingMethod() != null)
costingMethod = pca.getCostingMethod();
String costingMethod = product.getCostingMethod(as);
if (MAcctSchema.COSTINGMETHOD_AveragePO.equals(costingMethod) ||
MAcctSchema.COSTINGMETHOD_LastPOPrice.equals(costingMethod) )
{
@ -382,11 +377,7 @@ public class Doc_InOut extends Doc
BigDecimal costs = null;
MProduct product = line.getProduct();
//get costing method for product
String costingMethod = as.getCostingMethod();
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(),
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), getTrxName());
if (pca.getCostingMethod() != null)
costingMethod = pca.getCostingMethod();
String costingMethod = product.getCostingMethod(as);
if (MAcctSchema.COSTINGMETHOD_AveragePO.equals(costingMethod) ||
MAcctSchema.COSTINGMETHOD_LastPOPrice.equals(costingMethod) )
{

View File

@ -184,14 +184,9 @@ public class Doc_MatchPO extends Doc
// end MZ
*/
// Calculate PPV for standard costing
String costingMethod = as.getCostingMethod();
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(),
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), getTrxName());
if (pca.getCostingMethod() != null)
costingMethod = pca.getCostingMethod();
//get standard cost and also makesure cost for other costing method is updated
String costingMethod = product.getCostingMethod(as);
//get standard cost and also make sure cost for other costing method is updated
BigDecimal costs = m_pc.getProductCosts(as, getAD_Org_ID(),
MAcctSchema.COSTINGMETHOD_StandardCosting, m_C_OrderLine_ID, false); // non-zero costs

View File

@ -146,12 +146,7 @@ public class Doc_Movement extends Doc
// Only for between-org movements
if (dr.getAD_Org_ID() != cr.getAD_Org_ID())
{
String costingLevel = as.getCostingLevel();
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(),
line.getProduct().getM_Product_Category_ID(),
as.getC_AcctSchema_ID(), getTrxName());
if (pca.getCostingLevel() != null)
costingLevel = pca.getCostingLevel();
String costingLevel = line.getProduct().getCostingLevel(as);
if (!MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel))
continue;
//

View File

@ -17,13 +17,21 @@
*****************************************************************************/
package org.compiere.model;
import java.sql.*;
import java.math.*;
import java.util.*;
import java.util.logging.*;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.*;
import org.compiere.util.*;
import org.compiere.Adempiere;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
import org.compiere.util.Trx;
/**
* Product Cost Model
@ -36,6 +44,9 @@ import org.compiere.util.*;
*/
public class MCost extends X_M_Cost
{
private static final long serialVersionUID = 1L;
/**
* Retrieve/Calculate Current Cost Price
* @param product product
@ -55,16 +66,7 @@ public class MCost extends X_M_Cost
BigDecimal qty, int C_OrderLine_ID,
boolean zeroCostsOK, String trxName)
{
String CostingLevel = as.getCostingLevel();
MProductCategoryAcct pca = MProductCategoryAcct.get (product.getCtx(),
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), null);
if (pca == null)
throw new IllegalStateException("Cannot find Acct for M_Product_Category_ID="
+ product.getM_Product_Category_ID()
+ ", C_AcctSchema_ID=" + as.getC_AcctSchema_ID());
// Costing Level
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
String CostingLevel = product.getCostingLevel(as);
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{
AD_Org_ID = 0;
@ -77,13 +79,10 @@ public class MCost extends X_M_Cost
// Costing Method
if (costingMethod == null)
{
costingMethod = pca.getCostingMethod();
costingMethod = product.getCostingMethod(as);
if (costingMethod == null)
{
costingMethod = as.getCostingMethod();
if (costingMethod == null)
throw new IllegalArgumentException("No Costing Method");
// costingMethod = MAcctSchema.COSTINGMETHOD_StandardCosting;
throw new IllegalArgumentException("No Costing Method");
}
}
@ -117,7 +116,7 @@ public class MCost extends X_M_Cost
{
BigDecimal currentCostPrice = null;
String costElementType = null;
int M_CostElement_ID = 0;
//int M_CostElement_ID = 0;
BigDecimal percent = null;
//
BigDecimal materialCostEach = Env.ZERO;
@ -700,11 +699,7 @@ public class MCost extends X_M_Cost
for (int i = 0; i < mass.length; i++)
{
MAcctSchema as = mass[i];
MProductCategoryAcct pca = MProductCategoryAcct.get(product.getCtx(),
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), product.get_TrxName());
String cl = pca.getCostingLevel();
if (cl == null)
cl = as.getCostingLevel();
String cl = product.getCostingLevel(as);
// Create Std Costing
if (MAcctSchema.COSTINGLEVEL_Client.equals(cl))
{
@ -1608,12 +1603,8 @@ public class MCost extends X_M_Cost
if (m_manual)
{
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(),
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
String CostingLevel = product.getCostingLevel(as);
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{
if (getAD_Org_ID() != 0 || getM_AttributeSetInstance_ID() != 0)

View File

@ -748,12 +748,8 @@ public class MCostDetail extends X_M_CostDetail
// get costing level for product
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(),
product.getM_Product_Category_ID(), getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
String CostingLevel = product.getCostingLevel(as);
// Org Element
int Org_ID = getAD_Org_ID();
int M_ASI_ID = getM_AttributeSetInstance_ID();
@ -1085,12 +1081,8 @@ public class MCostDetail extends X_M_CostDetail
boolean ok = false;
// get costing level for product
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(),
product.getM_Product_Category_ID(), getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
String CostingLevel = product.getCostingLevel(as);
// Org Element
int Org_ID = getAD_Org_ID();
int M_ASI_ID = getM_AttributeSetInstance_ID();

View File

@ -38,6 +38,8 @@ import org.compiere.util.Msg;
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1885153 ] Refactor: getMMPolicy code
* <li>BF [ 1885414 ] ASI should be always mandatory if CostingLevel is Batch/Lot
* <li>FR [ 2093551 ] Refactor/Add org.compiere.model.MProduct.getCostingLevel
* <li>FR [ 2093569 ] Refactor/Add org.compiere.model.MProduct.getCostingMethod
*/
public class MProduct extends X_M_Product
{
@ -795,11 +797,9 @@ public class MProduct extends X_M_Product
//
// If CostingLevel is BatchLot ASI is always mandatory - check all client acct schemas
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
for (MAcctSchema as : mass) {
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), getM_Product_Category_ID(), as.getC_AcctSchema_ID(), get_TrxName());
String cl = pca.getCostingLevel();
if (cl == null)
cl = as.getCostingLevel();
for (MAcctSchema as : mass)
{
String cl = getCostingLevel(as);
if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(cl)) {
return true;
}
@ -823,4 +823,36 @@ public class MProduct extends X_M_Product
// Default not mandatory
return false;
}
/**
* Get Product Costing Level
* @param as accounting schema
* @return product costing level
*/
public String getCostingLevel(MAcctSchema as)
{
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), getM_Product_Category_ID(), as.get_ID(), get_TrxName());
String costingLevel = pca.getCostingLevel();
if (costingLevel == null)
{
costingLevel = as.getCostingLevel();
}
return costingLevel;
}
/**
* Get Product Costing Method
* @param C_AcctSchema_ID accounting schema ID
* @return product costing method
*/
public String getCostingMethod(MAcctSchema as)
{
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), getM_Product_Category_ID(), as.get_ID(), get_TrxName());
String costingMethod = pca.getCostingMethod();
if (costingMethod == null)
{
costingMethod = as.getCostingMethod();
}
return costingMethod;
}
} // MProduct