- Initial cost from m_product_po is wrong if m_product_po.c_uom_id <> m_product.c_uom_id
This commit is contained in:
parent
e76f04dfe0
commit
197c5bd9e2
|
@ -37,19 +37,19 @@ import org.compiere.util.Trx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Product Cost Model
|
* Product Cost Model
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: MCost.java,v 1.6 2006/07/30 00:51:02 jjanke Exp $
|
* @version $Id: MCost.java,v 1.6 2006/07/30 00:51:02 jjanke Exp $
|
||||||
*
|
*
|
||||||
* Carlos Ruiz - globalqss - integrate bug fix from Teo Sarca
|
* Carlos Ruiz - globalqss - integrate bug fix from Teo Sarca
|
||||||
* [ 1619112 ] Posible problem for LastPO costing, Batch/Lot level
|
* [ 1619112 ] Posible problem for LastPO costing, Batch/Lot level
|
||||||
*
|
*
|
||||||
* FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 (only non-join query)
|
* FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 (only non-join query)
|
||||||
*/
|
*/
|
||||||
public class MCost extends X_M_Cost
|
public class MCost extends X_M_Cost
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -127982599769472918L;
|
private static final long serialVersionUID = -127982599769472918L;
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ public class MCost extends X_M_Cost
|
||||||
* Retrieve/Calculate Current Cost Price
|
* Retrieve/Calculate Current Cost Price
|
||||||
* @param product product
|
* @param product product
|
||||||
* @param M_AttributeSetInstance_ID real asi
|
* @param M_AttributeSetInstance_ID real asi
|
||||||
* @param as accounting schema
|
* @param as accounting schema
|
||||||
* @param AD_Org_ID real org
|
* @param AD_Org_ID real org
|
||||||
* @param costingMethod AcctSchema.COSTINGMETHOD_*
|
* @param costingMethod AcctSchema.COSTINGMETHOD_*
|
||||||
* @param qty qty
|
* @param qty qty
|
||||||
* @param C_OrderLine_ID optional order line
|
* @param C_OrderLine_ID optional order line
|
||||||
|
@ -69,7 +69,7 @@ public class MCost extends X_M_Cost
|
||||||
*/
|
*/
|
||||||
public static BigDecimal getCurrentCost (MProduct product,
|
public static BigDecimal getCurrentCost (MProduct product,
|
||||||
int M_AttributeSetInstance_ID,
|
int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID, String costingMethod,
|
MAcctSchema as, int AD_Org_ID, String costingMethod,
|
||||||
BigDecimal qty, int C_OrderLine_ID,
|
BigDecimal qty, int C_OrderLine_ID,
|
||||||
boolean zeroCostsOK, String trxName)
|
boolean zeroCostsOK, String trxName)
|
||||||
{
|
{
|
||||||
|
@ -92,16 +92,16 @@ public class MCost extends X_M_Cost
|
||||||
throw new IllegalArgumentException("No Costing Method");
|
throw new IllegalArgumentException("No Costing Method");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create/Update Costs
|
// Create/Update Costs
|
||||||
MCostDetail.processProduct (product, trxName);
|
MCostDetail.processProduct (product, trxName);
|
||||||
|
|
||||||
return getCurrentCost (
|
return getCurrentCost (
|
||||||
product, M_AttributeSetInstance_ID,
|
product, M_AttributeSetInstance_ID,
|
||||||
as, AD_Org_ID, as.getM_CostType_ID(), costingMethod, qty,
|
as, AD_Org_ID, as.getM_CostType_ID(), costingMethod, qty,
|
||||||
C_OrderLine_ID, zeroCostsOK, trxName);
|
C_OrderLine_ID, zeroCostsOK, trxName);
|
||||||
} // getCurrentCost
|
} // getCurrentCost
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Current Cost Price for Costing Level
|
* Get Current Cost Price for Costing Level
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -116,9 +116,9 @@ public class MCost extends X_M_Cost
|
||||||
* @param trxName trx
|
* @param trxName trx
|
||||||
* @return cost price or null
|
* @return cost price or null
|
||||||
*/
|
*/
|
||||||
private static BigDecimal getCurrentCost (MProduct product, int M_ASI_ID,
|
private static BigDecimal getCurrentCost (MProduct product, int M_ASI_ID,
|
||||||
MAcctSchema as, int Org_ID, int M_CostType_ID,
|
MAcctSchema as, int Org_ID, int M_CostType_ID,
|
||||||
String costingMethod, BigDecimal qty, int C_OrderLine_ID,
|
String costingMethod, BigDecimal qty, int C_OrderLine_ID,
|
||||||
boolean zeroCostsOK, String trxName)
|
boolean zeroCostsOK, String trxName)
|
||||||
{
|
{
|
||||||
BigDecimal currentCostPrice = null;
|
BigDecimal currentCostPrice = null;
|
||||||
|
@ -163,7 +163,7 @@ public class MCost extends X_M_Cost
|
||||||
String cm = rs.getString(3);
|
String cm = rs.getString(3);
|
||||||
percent = rs.getBigDecimal(4);
|
percent = rs.getBigDecimal(4);
|
||||||
// M_CostElement_ID = rs.getInt(5);
|
// M_CostElement_ID = rs.getInt(5);
|
||||||
s_log.finest("CurrentCostPrice=" + currentCostPrice
|
s_log.finest("CurrentCostPrice=" + currentCostPrice
|
||||||
+ ", CostElementType=" + costElementType
|
+ ", CostElementType=" + costElementType
|
||||||
+ ", CostingMethod=" + cm
|
+ ", CostingMethod=" + cm
|
||||||
+ ", Percent=" + percent);
|
+ ", Percent=" + percent);
|
||||||
|
@ -171,9 +171,9 @@ public class MCost extends X_M_Cost
|
||||||
if (currentCostPrice != null && currentCostPrice.signum() != 0)
|
if (currentCostPrice != null && currentCostPrice.signum() != 0)
|
||||||
{
|
{
|
||||||
if (cm != null)
|
if (cm != null)
|
||||||
{
|
{
|
||||||
materialCostEach = materialCostEach.add(currentCostPrice).add(currentCostPriceLL);
|
materialCostEach = materialCostEach.add(currentCostPrice).add(currentCostPriceLL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
otherCostEach = otherCostEach.add(currentCostPrice).add(currentCostPriceLL);
|
otherCostEach = otherCostEach.add(currentCostPrice).add(currentCostPriceLL);
|
||||||
}
|
}
|
||||||
|
@ -191,12 +191,12 @@ public class MCost extends X_M_Cost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 1) // Print summary
|
if (count > 1) // Print summary
|
||||||
s_log.finest("MaterialCost=" + materialCostEach
|
s_log.finest("MaterialCost=" + materialCostEach
|
||||||
+ ", OtherCosts=" + otherCostEach
|
+ ", OtherCosts=" + otherCostEach
|
||||||
+ ", Percentage=" + percentage);
|
+ ", Percentage=" + percentage);
|
||||||
|
|
||||||
// Seed Initial Costs
|
// Seed Initial Costs
|
||||||
if (materialCostEach.signum() == 0) // no costs
|
if (materialCostEach.signum() == 0) // no costs
|
||||||
{
|
{
|
||||||
|
@ -220,10 +220,10 @@ public class MCost extends X_M_Cost
|
||||||
|| MCostElement.COSTINGMETHOD_Lifo.equals(costingMethod))
|
|| MCostElement.COSTINGMETHOD_Lifo.equals(costingMethod))
|
||||||
{
|
{
|
||||||
MCostElement ce = MCostElement.getMaterialCostElement(as, costingMethod);
|
MCostElement ce = MCostElement.getMaterialCostElement(as, costingMethod);
|
||||||
materialCost = MCostQueue.getCosts(product, M_ASI_ID,
|
materialCost = MCostQueue.getCosts(product, M_ASI_ID,
|
||||||
as, Org_ID, ce, qty, trxName);
|
as, Org_ID, ce, qty, trxName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other Costs
|
// Other Costs
|
||||||
BigDecimal otherCost = otherCostEach.multiply(qty);
|
BigDecimal otherCost = otherCostEach.multiply(qty);
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ public class MCost extends X_M_Cost
|
||||||
s_log.finer("Sum Costs = " + costs + " (Add=" + percentCost + ")");
|
s_log.finer("Sum Costs = " + costs + " (Add=" + percentCost + ")");
|
||||||
return costs;
|
return costs;
|
||||||
} // getCurrentCost
|
} // getCurrentCost
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Seed Costs
|
* Get Seed Costs
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -285,7 +285,7 @@ public class MCost extends X_M_Cost
|
||||||
else if (MCostElement.COSTINGMETHOD_StandardCosting.equals(costingMethod))
|
else if (MCostElement.COSTINGMETHOD_StandardCosting.equals(costingMethod))
|
||||||
{
|
{
|
||||||
// migrate old costs
|
// migrate old costs
|
||||||
MProductCosting pc = MProductCosting.get(product.getCtx(), product.getM_Product_ID(),
|
MProductCosting pc = MProductCosting.get(product.getCtx(), product.getM_Product_ID(),
|
||||||
as.getC_AcctSchema_ID(), null);
|
as.getC_AcctSchema_ID(), null);
|
||||||
if (pc != null)
|
if (pc != null)
|
||||||
retValue = pc.getCurrentCostPrice();
|
retValue = pc.getCurrentCostPrice();
|
||||||
|
@ -310,7 +310,7 @@ public class MCost extends X_M_Cost
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for Standard Costs first
|
// Look for Standard Costs first
|
||||||
if (!MCostElement.COSTINGMETHOD_StandardCosting.equals(costingMethod))
|
if (!MCostElement.COSTINGMETHOD_StandardCosting.equals(costingMethod))
|
||||||
{
|
{
|
||||||
|
@ -351,7 +351,7 @@ public class MCost extends X_M_Cost
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still Nothing
|
// Still Nothing
|
||||||
// Inv second
|
// Inv second
|
||||||
if (MCostElement.COSTINGMETHOD_AveragePO.equals(costingMethod)
|
if (MCostElement.COSTINGMETHOD_AveragePO.equals(costingMethod)
|
||||||
|
@ -380,7 +380,7 @@ public class MCost extends X_M_Cost
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still nothing try ProductPO
|
// Still nothing try ProductPO
|
||||||
MProductPO[] pos = MProductPO.getOfProduct(product.getCtx(), product.getM_Product_ID(), null);
|
MProductPO[] pos = MProductPO.getOfProduct(product.getCtx(), product.getM_Product_ID(), null);
|
||||||
for (int i = 0; i < pos.length; i++)
|
for (int i = 0; i < pos.length; i++)
|
||||||
|
@ -390,26 +390,31 @@ public class MCost extends X_M_Cost
|
||||||
price = pos[0].getPriceList();
|
price = pos[0].getPriceList();
|
||||||
if (price != null && price.signum() != 0)
|
if (price != null && price.signum() != 0)
|
||||||
{
|
{
|
||||||
price = MConversionRate.convert(product.getCtx(), price,
|
price = MConversionRate.convert(product.getCtx(), price,
|
||||||
pos[0].getC_Currency_ID(), as.getC_Currency_ID(),
|
pos[0].getC_Currency_ID(), as.getC_Currency_ID(),
|
||||||
as.getAD_Client_ID(), Org_ID);
|
as.getAD_Client_ID(), Org_ID);
|
||||||
if (price != null && price.signum() != 0)
|
if (price != null && price.signum() != 0)
|
||||||
{
|
{
|
||||||
|
if (pos[i].getC_UOM_ID() != product.getC_UOM_ID())
|
||||||
|
{
|
||||||
|
price = MUOMConversion.convertProductTo (Env.getCtx(), product.getM_Product_ID(),
|
||||||
|
pos[i].getC_UOM_ID(), price);
|
||||||
|
}
|
||||||
retValue = price;
|
retValue = price;
|
||||||
s_log.fine(product.getName() + ", Product_PO = " + retValue);
|
s_log.fine(product.getName() + ", Product_PO = " + retValue);
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still nothing try Purchase Price List
|
// Still nothing try Purchase Price List
|
||||||
// ....
|
// ....
|
||||||
|
|
||||||
s_log.fine(product.getName() + " = " + retValue);
|
s_log.fine(product.getName() + " = " + retValue);
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getSeedCosts
|
} // getSeedCosts
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Last Invoice Price in currency
|
* Get Last Invoice Price in currency
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -418,7 +423,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param C_Currency_ID accounting currency
|
* @param C_Currency_ID accounting currency
|
||||||
* @return last invoice price in currency
|
* @return last invoice price in currency
|
||||||
*/
|
*/
|
||||||
public static BigDecimal getLastInvoicePrice (MProduct product,
|
public static BigDecimal getLastInvoicePrice (MProduct product,
|
||||||
int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
|
int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
|
||||||
{
|
{
|
||||||
BigDecimal retValue = null;
|
BigDecimal retValue = null;
|
||||||
|
@ -465,7 +470,7 @@ public class MCost extends X_M_Cost
|
||||||
{
|
{
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
{
|
{
|
||||||
s_log.finer(product.getName() + " = " + retValue);
|
s_log.finer(product.getName() + " = " + retValue);
|
||||||
|
@ -482,7 +487,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param C_Currency_ID accounting currency
|
* @param C_Currency_ID accounting currency
|
||||||
* @return last PO price in currency or null
|
* @return last PO price in currency or null
|
||||||
*/
|
*/
|
||||||
public static BigDecimal getLastPOPrice (MProduct product,
|
public static BigDecimal getLastPOPrice (MProduct product,
|
||||||
int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
|
int M_ASI_ID, int AD_Org_ID, int C_Currency_ID)
|
||||||
{
|
{
|
||||||
BigDecimal retValue = null;
|
BigDecimal retValue = null;
|
||||||
|
@ -528,7 +533,7 @@ public class MCost extends X_M_Cost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
{
|
{
|
||||||
s_log.finer(product.getName() + " = " + retValue);
|
s_log.finer(product.getName() + " = " + retValue);
|
||||||
|
@ -580,7 +585,7 @@ public class MCost extends X_M_Cost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retValue != null)
|
if (retValue != null)
|
||||||
{
|
{
|
||||||
s_log.finer(product.getName() + " = " + retValue);
|
s_log.finer(product.getName() + " = " + retValue);
|
||||||
|
@ -588,7 +593,7 @@ public class MCost extends X_M_Cost
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} // getPOPrice
|
} // getPOPrice
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Create costing for client.
|
* Create costing for client.
|
||||||
* Handles Transaction if not in a transaction
|
* Handles Transaction if not in a transaction
|
||||||
|
@ -596,7 +601,7 @@ public class MCost extends X_M_Cost
|
||||||
*/
|
*/
|
||||||
public static void create (MClient client)
|
public static void create (MClient client)
|
||||||
{
|
{
|
||||||
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(client.getCtx(), client.getAD_Client_ID());
|
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(client.getCtx(), client.getAD_Client_ID());
|
||||||
String trxName = client.get_TrxName();
|
String trxName = client.get_TrxName();
|
||||||
String trxNameUsed = trxName;
|
String trxNameUsed = trxName;
|
||||||
Trx trx = null;
|
Trx trx = null;
|
||||||
|
@ -622,7 +627,7 @@ public class MCost extends X_M_Cost
|
||||||
MProduct product = new MProduct (client.getCtx(), rs, trxNameUsed);
|
MProduct product = new MProduct (client.getCtx(), rs, trxNameUsed);
|
||||||
for (int i = 0; i < ass.length; i++)
|
for (int i = 0; i < ass.length; i++)
|
||||||
{
|
{
|
||||||
BigDecimal cost = getCurrentCost(product, 0, ass[i], 0,
|
BigDecimal cost = getCurrentCost(product, 0, ass[i], 0,
|
||||||
null, Env.ONE, 0, false, trxNameUsed); // create non-zero costs
|
null, Env.ONE, 0, false, trxNameUsed); // create non-zero costs
|
||||||
s_log.info(product.getName() + " = " + cost);
|
s_log.info(product.getName() + " = " + cost);
|
||||||
}
|
}
|
||||||
|
@ -656,8 +661,8 @@ public class MCost extends X_M_Cost
|
||||||
trx.close();
|
trx.close();
|
||||||
}
|
}
|
||||||
} // create
|
} // create
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create standard Costing records for Product
|
* Create standard Costing records for Product
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -668,92 +673,31 @@ public class MCost extends X_M_Cost
|
||||||
|
|
||||||
// Cost Elements
|
// Cost Elements
|
||||||
Collection <MCostElement> ces = MCostElement.getCostElementsWithCostingMethods(product);
|
Collection <MCostElement> ces = MCostElement.getCostElementsWithCostingMethods(product);
|
||||||
|
|
||||||
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(product.getCtx(),
|
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(product.getCtx(),
|
||||||
product.getAD_Client_ID(), product.get_TrxName());
|
product.getAD_Client_ID(), product.get_TrxName());
|
||||||
MOrg[] orgs = null;
|
MOrg[] orgs = null;
|
||||||
|
|
||||||
int M_ASI_ID = 0; // No Attribute
|
int M_ASI_ID = 0; // No Attribute
|
||||||
for (MAcctSchema as : mass)
|
for (MAcctSchema as : mass)
|
||||||
{
|
{
|
||||||
String cl = product.getCostingLevel(as);
|
String cl = product.getCostingLevel(as);
|
||||||
// Create Std Costing
|
// Create Std Costing
|
||||||
if (MAcctSchema.COSTINGLEVEL_Client.equals(cl))
|
if (MAcctSchema.COSTINGLEVEL_Client.equals(cl))
|
||||||
{
|
{
|
||||||
for(MCostElement ce : ces)
|
for(MCostElement ce : ces)
|
||||||
{
|
{
|
||||||
MCost cost = MCost.get (product, M_ASI_ID,
|
MCost cost = MCost.get (product, M_ASI_ID,
|
||||||
as, 0, ce.getM_CostElement_ID(), product.get_TrxName());
|
as, 0, ce.getM_CostElement_ID(), product.get_TrxName());
|
||||||
if (cost.is_new())
|
if (cost.is_new())
|
||||||
{
|
{
|
||||||
if (cost.save())
|
if (cost.save())
|
||||||
s_log.config("Std.Cost for " + product.getName()
|
s_log.config("Std.Cost for " + product.getName()
|
||||||
+ " - " + as.getName());
|
+ " - " + as.getName());
|
||||||
else
|
else
|
||||||
s_log.warning("Not created: Std.Cost for " + product.getName()
|
s_log.warning("Not created: Std.Cost for " + product.getName()
|
||||||
+ " - " + as.getName());
|
+ " - " + as.getName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(cl))
|
|
||||||
{
|
|
||||||
if (orgs == null)
|
|
||||||
orgs = MOrg.getOfClient(product);
|
|
||||||
for (MOrg o : orgs)
|
|
||||||
{
|
|
||||||
for(MCostElement ce : ces)
|
|
||||||
{
|
|
||||||
MCost cost = MCost.get (product, M_ASI_ID,
|
|
||||||
as, o.getAD_Org_ID(), ce.getM_CostElement_ID(), product.get_TrxName());
|
|
||||||
if (cost.is_new())
|
|
||||||
{
|
|
||||||
if (cost.save())
|
|
||||||
s_log.config("Std.Cost for " + product.getName()
|
|
||||||
+ " - " + o.getName()
|
|
||||||
+ " - " + as.getName());
|
|
||||||
else
|
|
||||||
s_log.warning("Not created: Std.Cost for " + product.getName()
|
|
||||||
+ " - " + o.getName()
|
|
||||||
+ " - " + as.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // for all orgs
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
s_log.warning("Not created: Std.Cost for " + product.getName()
|
|
||||||
+ " - Costing Level on Batch/Lot");
|
|
||||||
}
|
|
||||||
} // accounting schema loop
|
|
||||||
} // create
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete standard Costing records for Product
|
|
||||||
* @param product product
|
|
||||||
**/
|
|
||||||
protected static void delete (MProduct product)
|
|
||||||
{
|
|
||||||
s_log.config(product.getName());
|
|
||||||
// Cost Elements
|
|
||||||
Collection <MCostElement> ces = MCostElement.getCostElementsWithCostingMethods(product);
|
|
||||||
|
|
||||||
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(product.getCtx(),
|
|
||||||
product.getAD_Client_ID(), product.get_TrxName());
|
|
||||||
MOrg[] orgs = null;
|
|
||||||
|
|
||||||
int M_ASI_ID = 0; // No Attribute
|
|
||||||
for (MAcctSchema as : mass)
|
|
||||||
{
|
|
||||||
String cl = product.getCostingLevel(as);
|
|
||||||
// Create Std Costing
|
|
||||||
if (MAcctSchema.COSTINGLEVEL_Client.equals(cl))
|
|
||||||
{
|
|
||||||
for(MCostElement ce : ces)
|
|
||||||
{
|
|
||||||
MCost cost = MCost.get (product, M_ASI_ID,
|
|
||||||
as, 0, ce.getM_CostElement_ID(), product.get_TrxName());
|
|
||||||
if(cost != null)
|
|
||||||
cost.deleteEx(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(cl))
|
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(cl))
|
||||||
|
@ -763,8 +707,69 @@ public class MCost extends X_M_Cost
|
||||||
for (MOrg o : orgs)
|
for (MOrg o : orgs)
|
||||||
{
|
{
|
||||||
for(MCostElement ce : ces)
|
for(MCostElement ce : ces)
|
||||||
{
|
{
|
||||||
MCost cost = MCost.get (product, M_ASI_ID,
|
MCost cost = MCost.get (product, M_ASI_ID,
|
||||||
|
as, o.getAD_Org_ID(), ce.getM_CostElement_ID(), product.get_TrxName());
|
||||||
|
if (cost.is_new())
|
||||||
|
{
|
||||||
|
if (cost.save())
|
||||||
|
s_log.config("Std.Cost for " + product.getName()
|
||||||
|
+ " - " + o.getName()
|
||||||
|
+ " - " + as.getName());
|
||||||
|
else
|
||||||
|
s_log.warning("Not created: Std.Cost for " + product.getName()
|
||||||
|
+ " - " + o.getName()
|
||||||
|
+ " - " + as.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // for all orgs
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_log.warning("Not created: Std.Cost for " + product.getName()
|
||||||
|
+ " - Costing Level on Batch/Lot");
|
||||||
|
}
|
||||||
|
} // accounting schema loop
|
||||||
|
} // create
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete standard Costing records for Product
|
||||||
|
* @param product product
|
||||||
|
**/
|
||||||
|
protected static void delete (MProduct product)
|
||||||
|
{
|
||||||
|
s_log.config(product.getName());
|
||||||
|
// Cost Elements
|
||||||
|
Collection <MCostElement> ces = MCostElement.getCostElementsWithCostingMethods(product);
|
||||||
|
|
||||||
|
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(product.getCtx(),
|
||||||
|
product.getAD_Client_ID(), product.get_TrxName());
|
||||||
|
MOrg[] orgs = null;
|
||||||
|
|
||||||
|
int M_ASI_ID = 0; // No Attribute
|
||||||
|
for (MAcctSchema as : mass)
|
||||||
|
{
|
||||||
|
String cl = product.getCostingLevel(as);
|
||||||
|
// Create Std Costing
|
||||||
|
if (MAcctSchema.COSTINGLEVEL_Client.equals(cl))
|
||||||
|
{
|
||||||
|
for(MCostElement ce : ces)
|
||||||
|
{
|
||||||
|
MCost cost = MCost.get (product, M_ASI_ID,
|
||||||
|
as, 0, ce.getM_CostElement_ID(), product.get_TrxName());
|
||||||
|
if(cost != null)
|
||||||
|
cost.deleteEx(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(cl))
|
||||||
|
{
|
||||||
|
if (orgs == null)
|
||||||
|
orgs = MOrg.getOfClient(product);
|
||||||
|
for (MOrg o : orgs)
|
||||||
|
{
|
||||||
|
for(MCostElement ce : ces)
|
||||||
|
{
|
||||||
|
MCost cost = MCost.get (product, M_ASI_ID,
|
||||||
as, o.getAD_Org_ID(), ce.getM_CostElement_ID(), product.get_TrxName());
|
as, o.getAD_Org_ID(), ce.getM_CostElement_ID(), product.get_TrxName());
|
||||||
if(cost != null)
|
if(cost != null)
|
||||||
cost.deleteEx(true);
|
cost.deleteEx(true);
|
||||||
|
@ -773,12 +778,12 @@ public class MCost extends X_M_Cost
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s_log.warning("Not created: Std.Cost for " + product.getName()
|
s_log.warning("Not created: Std.Cost for " + product.getName()
|
||||||
+ " - Costing Level on Batch/Lot");
|
+ " - Costing Level on Batch/Lot");
|
||||||
}
|
}
|
||||||
} // accounting schema loop
|
} // accounting schema loop
|
||||||
} // create
|
} // create
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Calculate Average Invoice from Trx
|
* Calculate Average Invoice from Trx
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -787,7 +792,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param AD_Org_ID optonal org
|
* @param AD_Org_ID optonal org
|
||||||
* @return average costs or null
|
* @return average costs or null
|
||||||
*/
|
*/
|
||||||
public static BigDecimal calculateAverageInv (MProduct product, int M_AttributeSetInstance_ID,
|
public static BigDecimal calculateAverageInv (MProduct product, int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID)
|
MAcctSchema as, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
String sql = "SELECT t.MovementQty, mi.Qty, il.QtyInvoiced, il.PriceActual,"
|
String sql = "SELECT t.MovementQty, mi.Qty, il.QtyInvoiced, il.PriceActual,"
|
||||||
|
@ -840,8 +845,8 @@ public class MCost extends X_M_Cost
|
||||||
int C_ConversionType_ID = rs.getInt(7);
|
int C_ConversionType_ID = rs.getInt(7);
|
||||||
int Client_ID = rs.getInt(8);
|
int Client_ID = rs.getInt(8);
|
||||||
int Org_ID = rs.getInt(9);
|
int Org_ID = rs.getInt(9);
|
||||||
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
||||||
C_Currency_ID, as.getC_Currency_ID(),
|
C_Currency_ID, as.getC_Currency_ID(),
|
||||||
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
||||||
//
|
//
|
||||||
BigDecimal oldAverageAmt = newAverageAmt;
|
BigDecimal oldAverageAmt = newAverageAmt;
|
||||||
|
@ -880,7 +885,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param AD_Org_ID org
|
* @param AD_Org_ID org
|
||||||
* @return costs or null
|
* @return costs or null
|
||||||
*/
|
*/
|
||||||
public static BigDecimal calculateAveragePO (MProduct product, int M_AttributeSetInstance_ID,
|
public static BigDecimal calculateAveragePO (MProduct product, int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID)
|
MAcctSchema as, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
String sql = "SELECT t.MovementQty, mp.Qty, ol.QtyOrdered, ol.PriceCost, ol.PriceActual," // 1..5
|
String sql = "SELECT t.MovementQty, mp.Qty, ol.QtyOrdered, ol.PriceCost, ol.PriceActual," // 1..5
|
||||||
|
@ -936,8 +941,8 @@ public class MCost extends X_M_Cost
|
||||||
int C_ConversionType_ID = rs.getInt(8);
|
int C_ConversionType_ID = rs.getInt(8);
|
||||||
int Client_ID = rs.getInt(9);
|
int Client_ID = rs.getInt(9);
|
||||||
int Org_ID = rs.getInt(10);
|
int Org_ID = rs.getInt(10);
|
||||||
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
||||||
C_Currency_ID, as.getC_Currency_ID(),
|
C_Currency_ID, as.getC_Currency_ID(),
|
||||||
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
||||||
//
|
//
|
||||||
BigDecimal oldAverageAmt = newAverageAmt;
|
BigDecimal oldAverageAmt = newAverageAmt;
|
||||||
|
@ -967,7 +972,7 @@ public class MCost extends X_M_Cost
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} // calculateAveragePO
|
} // calculateAveragePO
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate FiFo Cost
|
* Calculate FiFo Cost
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -976,7 +981,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param AD_Org_ID org
|
* @param AD_Org_ID org
|
||||||
* @return costs or null
|
* @return costs or null
|
||||||
*/
|
*/
|
||||||
public static BigDecimal calculateFiFo (MProduct product, int M_AttributeSetInstance_ID,
|
public static BigDecimal calculateFiFo (MProduct product, int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID)
|
MAcctSchema as, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
String sql = "SELECT t.MovementQty, mi.Qty, il.QtyInvoiced, il.PriceActual,"
|
String sql = "SELECT t.MovementQty, mi.Qty, il.QtyInvoiced, il.PriceActual,"
|
||||||
|
@ -1058,10 +1063,10 @@ public class MCost extends X_M_Cost
|
||||||
int C_ConversionType_ID = rs.getInt(7);
|
int C_ConversionType_ID = rs.getInt(7);
|
||||||
int Client_ID = rs.getInt(8);
|
int Client_ID = rs.getInt(8);
|
||||||
int Org_ID = rs.getInt(9);
|
int Org_ID = rs.getInt(9);
|
||||||
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
||||||
C_Currency_ID, as.getC_Currency_ID(),
|
C_Currency_ID, as.getC_Currency_ID(),
|
||||||
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
||||||
|
|
||||||
// Add Stock
|
// Add Stock
|
||||||
boolean used = false;
|
boolean used = false;
|
||||||
if (fifo.size() == 1)
|
if (fifo.size() == 1)
|
||||||
|
@ -1076,7 +1081,7 @@ public class MCost extends X_M_Cost
|
||||||
pp.Cost = cost;
|
pp.Cost = cost;
|
||||||
used = true;
|
used = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!used)
|
if (!used)
|
||||||
{
|
{
|
||||||
|
@ -1095,7 +1100,7 @@ public class MCost extends X_M_Cost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fifo.size() == 0)
|
if (fifo.size() == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -1113,7 +1118,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param AD_Org_ID org
|
* @param AD_Org_ID org
|
||||||
* @return costs or null
|
* @return costs or null
|
||||||
*/
|
*/
|
||||||
public static BigDecimal calculateLiFo (MProduct product, int M_AttributeSetInstance_ID,
|
public static BigDecimal calculateLiFo (MProduct product, int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID)
|
MAcctSchema as, int AD_Org_ID)
|
||||||
{
|
{
|
||||||
String sql = "SELECT t.MovementQty, mi.Qty, il.QtyInvoiced, il.PriceActual,"
|
String sql = "SELECT t.MovementQty, mi.Qty, il.QtyInvoiced, il.PriceActual,"
|
||||||
|
@ -1196,8 +1201,8 @@ public class MCost extends X_M_Cost
|
||||||
int C_ConversionType_ID = rs.getInt(7);
|
int C_ConversionType_ID = rs.getInt(7);
|
||||||
int Client_ID = rs.getInt(8);
|
int Client_ID = rs.getInt(8);
|
||||||
int Org_ID = rs.getInt(9);
|
int Org_ID = rs.getInt(9);
|
||||||
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
BigDecimal cost = MConversionRate.convert(product.getCtx(), price,
|
||||||
C_Currency_ID, as.getC_Currency_ID(),
|
C_Currency_ID, as.getC_Currency_ID(),
|
||||||
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
DateAcct, C_ConversionType_ID, Client_ID, Org_ID);
|
||||||
//
|
//
|
||||||
QtyCost pp = new QtyCost (movementQty, cost);
|
QtyCost pp = new QtyCost (movementQty, cost);
|
||||||
|
@ -1214,7 +1219,7 @@ public class MCost extends X_M_Cost
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
rs = null; pstmt = null;
|
rs = null; pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lifo.size() == 0)
|
if (lifo.size() == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -1224,7 +1229,7 @@ public class MCost extends X_M_Cost
|
||||||
return pp.Cost;
|
return pp.Cost;
|
||||||
} // calculateLiFo
|
} // calculateLiFo
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* MCost Qty-Cost Pair
|
* MCost Qty-Cost Pair
|
||||||
*/
|
*/
|
||||||
|
@ -1244,7 +1249,7 @@ public class MCost extends X_M_Cost
|
||||||
public BigDecimal Qty = null;
|
public BigDecimal Qty = null;
|
||||||
/** Cost */
|
/** Cost */
|
||||||
public BigDecimal Cost = null;
|
public BigDecimal Cost = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Representation
|
* String Representation
|
||||||
* @return info
|
* @return info
|
||||||
|
@ -1256,8 +1261,8 @@ public class MCost extends X_M_Cost
|
||||||
return sb.toString ();
|
return sb.toString ();
|
||||||
} // toString
|
} // toString
|
||||||
} // QtyCost
|
} // QtyCost
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get/Create Cost Record.
|
* Get/Create Cost Record.
|
||||||
* CostingLevel is not validated
|
* CostingLevel is not validated
|
||||||
|
@ -1280,12 +1285,12 @@ public class MCost extends X_M_Cost
|
||||||
+ " AND M_CostElement_ID=?";
|
+ " AND M_CostElement_ID=?";
|
||||||
cost = new Query(product.getCtx(), MCost.Table_Name, whereClause, trxName)
|
cost = new Query(product.getCtx(), MCost.Table_Name, whereClause, trxName)
|
||||||
.setParameters(new Object[]{
|
.setParameters(new Object[]{
|
||||||
product.getAD_Client_ID(),
|
product.getAD_Client_ID(),
|
||||||
AD_Org_ID,
|
AD_Org_ID,
|
||||||
product.getM_Product_ID(),
|
product.getM_Product_ID(),
|
||||||
M_AttributeSetInstance_ID,
|
M_AttributeSetInstance_ID,
|
||||||
as.getM_CostType_ID(),
|
as.getM_CostType_ID(),
|
||||||
as.getC_AcctSchema_ID(),
|
as.getC_AcctSchema_ID(),
|
||||||
M_CostElement_ID})
|
M_CostElement_ID})
|
||||||
.first();
|
.first();
|
||||||
//FR: [ 2214883 ] - end -
|
//FR: [ 2214883 ] - end -
|
||||||
|
@ -1295,14 +1300,14 @@ public class MCost extends X_M_Cost
|
||||||
as, AD_Org_ID, M_CostElement_ID);
|
as, AD_Org_ID, M_CostElement_ID);
|
||||||
return cost;
|
return cost;
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static MCost get (MProduct product, int M_AttributeSetInstance_ID,
|
public static MCost get (MProduct product, int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
|
MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
|
||||||
{
|
{
|
||||||
return get(product, M_AttributeSetInstance_ID, as, AD_Org_ID, M_CostElement_ID, product.get_TrxName());
|
return get(product, M_AttributeSetInstance_ID, as, AD_Org_ID, M_CostElement_ID, product.get_TrxName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Cost Record
|
* Get Cost Record
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -1316,7 +1321,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param trxName transaction name
|
* @param trxName transaction name
|
||||||
* @return cost or null
|
* @return cost or null
|
||||||
*/
|
*/
|
||||||
public static MCost get (Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID,
|
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_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID,
|
||||||
int M_AttributeSetInstance_ID,
|
int M_AttributeSetInstance_ID,
|
||||||
String trxName)
|
String trxName)
|
||||||
|
@ -1335,9 +1340,9 @@ public class MCost extends X_M_Cost
|
||||||
.setParameters(params)
|
.setParameters(params)
|
||||||
.firstOnly();
|
.firstOnly();
|
||||||
} // get
|
} // get
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static MCost get (Properties ctx, int AD_Client_ID, int AD_Org_ID, int M_Product_ID,
|
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_CostType_ID, int C_AcctSchema_ID, int M_CostElement_ID,
|
||||||
int M_AttributeSetInstance_ID)
|
int M_AttributeSetInstance_ID)
|
||||||
{
|
{
|
||||||
|
@ -1346,11 +1351,11 @@ public class MCost extends X_M_Cost
|
||||||
M_AttributeSetInstance_ID,
|
M_AttributeSetInstance_ID,
|
||||||
null); // trxName
|
null); // trxName
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger s_log = CLogger.getCLogger (MCost.class);
|
private static CLogger s_log = CLogger.getCLogger (MCost.class);
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Standard Constructor
|
* Standard Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -1398,7 +1403,7 @@ public class MCost extends X_M_Cost
|
||||||
* @param AD_Org_ID org
|
* @param AD_Org_ID org
|
||||||
* @param M_CostElement_ID cost element
|
* @param M_CostElement_ID cost element
|
||||||
*/
|
*/
|
||||||
public MCost (MProduct product, int M_AttributeSetInstance_ID,
|
public MCost (MProduct product, int M_AttributeSetInstance_ID,
|
||||||
MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
|
MAcctSchema as, int AD_Org_ID, int M_CostElement_ID)
|
||||||
{
|
{
|
||||||
this (product.getCtx(), 0, product.get_TrxName());
|
this (product.getCtx(), 0, product.get_TrxName());
|
||||||
|
@ -1414,7 +1419,7 @@ public class MCost extends X_M_Cost
|
||||||
|
|
||||||
/** Data is entered Manually */
|
/** Data is entered Manually */
|
||||||
private boolean m_manual = true;
|
private boolean m_manual = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add Cumulative Amt/Qty and Current Qty
|
* Add Cumulative Amt/Qty and Current Qty
|
||||||
* @param amt amt
|
* @param amt amt
|
||||||
|
@ -1461,7 +1466,7 @@ public class MCost extends X_M_Cost
|
||||||
return as.getCostingPrecision();
|
return as.getCostingPrecision();
|
||||||
return 6;
|
return 6;
|
||||||
} // gerPrecision
|
} // gerPrecision
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Current Cost Price
|
* Set Current Cost Price
|
||||||
* @param currentCostPrice if null set to 0
|
* @param currentCostPrice if null set to 0
|
||||||
|
@ -1473,7 +1478,7 @@ public class MCost extends X_M_Cost
|
||||||
else
|
else
|
||||||
super.setCurrentCostPrice (Env.ZERO);
|
super.setCurrentCostPrice (Env.ZERO);
|
||||||
} // setCurrentCostPrice
|
} // setCurrentCostPrice
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get History Average (Amt/Qty)
|
* Get History Average (Amt/Qty)
|
||||||
* @return average if amt/aty <> 0 otherwise null
|
* @return average if amt/aty <> 0 otherwise null
|
||||||
|
@ -1484,10 +1489,10 @@ public class MCost extends X_M_Cost
|
||||||
if (getCumulatedQty().signum() != 0
|
if (getCumulatedQty().signum() != 0
|
||||||
&& getCumulatedAmt().signum() != 0)
|
&& getCumulatedAmt().signum() != 0)
|
||||||
retValue = getCumulatedAmt()
|
retValue = getCumulatedAmt()
|
||||||
.divide(getCumulatedQty(), getPrecision(), BigDecimal.ROUND_HALF_UP);
|
.divide(getCumulatedQty(), getPrecision(), BigDecimal.ROUND_HALF_UP);
|
||||||
return retValue;
|
return retValue;
|
||||||
} // getHistoryAverage
|
} // getHistoryAverage
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Representation
|
* String Representation
|
||||||
* @return info
|
* @return info
|
||||||
|
@ -1523,7 +1528,7 @@ public class MCost extends X_M_Cost
|
||||||
return null;
|
return null;
|
||||||
return MCostElement.get(getCtx(), M_CostElement_ID);
|
return MCostElement.get(getCtx(), M_CostElement_ID);
|
||||||
} // getCostElement
|
} // getCostElement
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before Save
|
* Before Save
|
||||||
* @param newRecord new
|
* @param newRecord new
|
||||||
|
@ -1531,8 +1536,8 @@ public class MCost extends X_M_Cost
|
||||||
*/
|
*/
|
||||||
protected boolean beforeSave (boolean newRecord)
|
protected boolean beforeSave (boolean newRecord)
|
||||||
{
|
{
|
||||||
//The method getCostElement() not should be cached because is a transaction
|
//The method getCostElement() not should be cached because is a transaction
|
||||||
//MCostElement ce = getCostElement();
|
//MCostElement ce = getCostElement();
|
||||||
MCostElement ce = (MCostElement)getM_CostElement();
|
MCostElement ce = (MCostElement)getM_CostElement();
|
||||||
// Check if data entry makes sense
|
// Check if data entry makes sense
|
||||||
if (m_manual)
|
if (m_manual)
|
||||||
|
@ -1550,7 +1555,7 @@ public class MCost extends X_M_Cost
|
||||||
}
|
}
|
||||||
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
|
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
|
||||||
{
|
{
|
||||||
if (getM_AttributeSetInstance_ID() == 0
|
if (getM_AttributeSetInstance_ID() == 0
|
||||||
&& ce.isCostingMethod())
|
&& ce.isCostingMethod())
|
||||||
{
|
{
|
||||||
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_AttributeSetInstance_ID"));
|
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_AttributeSetInstance_ID"));
|
||||||
|
@ -1560,7 +1565,7 @@ public class MCost extends X_M_Cost
|
||||||
setAD_Org_ID(0);
|
setAD_Org_ID(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cannot enter calculated
|
// Cannot enter calculated
|
||||||
if (m_manual && ce != null && ce.isCalculated())
|
if (m_manual && ce != null && ce.isCalculated())
|
||||||
{
|
{
|
||||||
|
@ -1570,8 +1575,8 @@ public class MCost extends X_M_Cost
|
||||||
// Percentage
|
// Percentage
|
||||||
if (ce != null)
|
if (ce != null)
|
||||||
{
|
{
|
||||||
if (ce.isCalculated()
|
if (ce.isCalculated()
|
||||||
|| MCostElement.COSTELEMENTTYPE_Material.equals(ce.getCostElementType())
|
|| MCostElement.COSTELEMENTTYPE_Material.equals(ce.getCostElementType())
|
||||||
&& getPercent() != 0)
|
&& getPercent() != 0)
|
||||||
setPercent(0);
|
setPercent(0);
|
||||||
}
|
}
|
||||||
|
@ -1588,8 +1593,8 @@ public class MCost extends X_M_Cost
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} // beforeSave
|
} // beforeSave
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before Delete
|
* Before Delete
|
||||||
* @return true
|
* @return true
|
||||||
|
@ -1599,7 +1604,7 @@ public class MCost extends X_M_Cost
|
||||||
return true;
|
return true;
|
||||||
} // beforeDelete
|
} // beforeDelete
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test
|
* Test
|
||||||
* @param args ignored
|
* @param args ignored
|
||||||
|
@ -1608,12 +1613,12 @@ public class MCost extends X_M_Cost
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
DELETE M_Cost c
|
DELETE M_Cost c
|
||||||
WHERE EXISTS (SELECT * FROM M_CostElement ce
|
WHERE EXISTS (SELECT * FROM M_CostElement ce
|
||||||
WHERE c.M_CostElement_ID=ce.M_CostElement_ID AND ce.IsCalculated='Y')
|
WHERE c.M_CostElement_ID=ce.M_CostElement_ID AND ce.IsCalculated='Y')
|
||||||
/
|
/
|
||||||
UPDATE M_Cost
|
UPDATE M_Cost
|
||||||
SET CumulatedAmt=0, CumulatedQty=0
|
SET CumulatedAmt=0, CumulatedQty=0
|
||||||
/
|
/
|
||||||
UPDATE M_CostDetail
|
UPDATE M_CostDetail
|
||||||
SET Processed='N'
|
SET Processed='N'
|
||||||
WHERE Processed='Y'
|
WHERE Processed='Y'
|
||||||
|
@ -1621,11 +1626,11 @@ public class MCost extends X_M_Cost
|
||||||
COMMIT
|
COMMIT
|
||||||
/
|
/
|
||||||
**/
|
**/
|
||||||
|
|
||||||
Adempiere.startup(true);
|
Adempiere.startup(true);
|
||||||
MClient client = MClient.get(Env.getCtx(), 11); // GardenWorld
|
MClient client = MClient.get(Env.getCtx(), 11); // GardenWorld
|
||||||
create(client);
|
create(client);
|
||||||
|
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
} // MCost
|
} // MCost
|
||||||
|
|
Loading…
Reference in New Issue