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

View File

@ -184,13 +184,8 @@ public class Doc_MatchPO extends Doc
// end MZ // end MZ
*/ */
// Calculate PPV for standard costing // Calculate PPV for standard costing
String costingMethod = as.getCostingMethod();
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), String costingMethod = product.getCostingMethod(as);
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), getTrxName());
if (pca.getCostingMethod() != null)
costingMethod = pca.getCostingMethod();
//get standard cost and also make sure cost for other costing method is updated //get standard cost and also make sure cost for other costing method is updated
BigDecimal costs = m_pc.getProductCosts(as, getAD_Org_ID(), BigDecimal costs = m_pc.getProductCosts(as, getAD_Org_ID(),
MAcctSchema.COSTINGMETHOD_StandardCosting, m_C_OrderLine_ID, false); // non-zero costs 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 // Only for between-org movements
if (dr.getAD_Org_ID() != cr.getAD_Org_ID()) if (dr.getAD_Org_ID() != cr.getAD_Org_ID())
{ {
String costingLevel = as.getCostingLevel(); String costingLevel = line.getProduct().getCostingLevel(as);
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(),
line.getProduct().getM_Product_Category_ID(),
as.getC_AcctSchema_ID(), getTrxName());
if (pca.getCostingLevel() != null)
costingLevel = pca.getCostingLevel();
if (!MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel)) if (!MAcctSchema.COSTINGLEVEL_Organization.equals(costingLevel))
continue; continue;
// //

View File

@ -17,13 +17,21 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.math.BigDecimal;
import java.math.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; 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.Adempiere;
import org.compiere.util.*; 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 * Product Cost Model
@ -36,6 +44,9 @@ import org.compiere.util.*;
*/ */
public class MCost extends X_M_Cost public class MCost extends X_M_Cost
{ {
private static final long serialVersionUID = 1L;
/** /**
* Retrieve/Calculate Current Cost Price * Retrieve/Calculate Current Cost Price
* @param product product * @param product product
@ -55,16 +66,7 @@ public class MCost extends X_M_Cost
BigDecimal qty, int C_OrderLine_ID, BigDecimal qty, int C_OrderLine_ID,
boolean zeroCostsOK, String trxName) boolean zeroCostsOK, String trxName)
{ {
String CostingLevel = as.getCostingLevel(); String CostingLevel = product.getCostingLevel(as);
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();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{ {
AD_Org_ID = 0; AD_Org_ID = 0;
@ -77,13 +79,10 @@ public class MCost extends X_M_Cost
// Costing Method // Costing Method
if (costingMethod == null) if (costingMethod == null)
{ {
costingMethod = pca.getCostingMethod(); costingMethod = product.getCostingMethod(as);
if (costingMethod == null) if (costingMethod == null)
{ {
costingMethod = as.getCostingMethod();
if (costingMethod == null)
throw new IllegalArgumentException("No Costing Method"); throw new IllegalArgumentException("No Costing Method");
// costingMethod = MAcctSchema.COSTINGMETHOD_StandardCosting;
} }
} }
@ -117,7 +116,7 @@ public class MCost extends X_M_Cost
{ {
BigDecimal currentCostPrice = null; BigDecimal currentCostPrice = null;
String costElementType = null; String costElementType = null;
int M_CostElement_ID = 0; //int M_CostElement_ID = 0;
BigDecimal percent = null; BigDecimal percent = null;
// //
BigDecimal materialCostEach = Env.ZERO; BigDecimal materialCostEach = Env.ZERO;
@ -700,11 +699,7 @@ public class MCost extends X_M_Cost
for (int i = 0; i < mass.length; i++) for (int i = 0; i < mass.length; i++)
{ {
MAcctSchema as = mass[i]; MAcctSchema as = mass[i];
MProductCategoryAcct pca = MProductCategoryAcct.get(product.getCtx(), String cl = product.getCostingLevel(as);
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), product.get_TrxName());
String cl = pca.getCostingLevel();
if (cl == null)
cl = as.getCostingLevel();
// Create Std Costing // Create Std Costing
if (MAcctSchema.COSTINGLEVEL_Client.equals(cl)) if (MAcctSchema.COSTINGLEVEL_Client.equals(cl))
{ {
@ -1608,12 +1603,8 @@ public class MCost extends X_M_Cost
if (m_manual) if (m_manual)
{ {
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null); MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(), String CostingLevel = product.getCostingLevel(as);
product.getM_Product_Category_ID(), as.getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{ {
if (getAD_Org_ID() != 0 || getM_AttributeSetInstance_ID() != 0) 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 // get costing level for product
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null); MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(), String CostingLevel = product.getCostingLevel(as);
product.getM_Product_Category_ID(), getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
// Org Element // Org Element
int Org_ID = getAD_Org_ID(); int Org_ID = getAD_Org_ID();
int M_ASI_ID = getM_AttributeSetInstance_ID(); int M_ASI_ID = getM_AttributeSetInstance_ID();
@ -1085,12 +1081,8 @@ public class MCostDetail extends X_M_CostDetail
boolean ok = false; boolean ok = false;
// get costing level for product // get costing level for product
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null); MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID()); MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(), String CostingLevel = product.getCostingLevel(as);
product.getM_Product_Category_ID(), getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
// Org Element // Org Element
int Org_ID = getAD_Org_ID(); int Org_ID = getAD_Org_ID();
int M_ASI_ID = getM_AttributeSetInstance_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 * @author Teo Sarca, SC ARHIPAC SERVICE SRL
* <li>FR [ 1885153 ] Refactor: getMMPolicy code * <li>FR [ 1885153 ] Refactor: getMMPolicy code
* <li>BF [ 1885414 ] ASI should be always mandatory if CostingLevel is Batch/Lot * <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 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 // If CostingLevel is BatchLot ASI is always mandatory - check all client acct schemas
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName()); MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
for (MAcctSchema as : mass) { for (MAcctSchema as : mass)
MProductCategoryAcct pca = MProductCategoryAcct.get(getCtx(), getM_Product_Category_ID(), as.getC_AcctSchema_ID(), get_TrxName()); {
String cl = pca.getCostingLevel(); String cl = getCostingLevel(as);
if (cl == null)
cl = as.getCostingLevel();
if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(cl)) { if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(cl)) {
return true; return true;
} }
@ -823,4 +823,36 @@ public class MProduct extends X_M_Product
// Default not mandatory // Default not mandatory
return false; 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 } // MProduct