IDEMPIERE-241 Unnecessary cost records added on product creation

Code integrated from Compiere community 3.3.0 version
This commit is contained in:
Carlos Ruiz 2012-04-18 10:31:32 -05:00
parent 644207b999
commit 37a4b33bf6
1 changed files with 14 additions and 7 deletions

View File

@ -708,7 +708,20 @@ public class MCost extends X_M_Cost
s_log.config(product.getName());
// Cost Elements
List <MCostElement> ces = MCostElement.getCostElementsWithCostingMethods(product);
MCostElement[] ces = MCostElement.getCostingMethods(product);
MCostElement ce = null;
for (MCostElement element : ces) {
if (X_M_CostElement.COSTINGMETHOD_StandardCosting.equals(element.getCostingMethod()))
{
ce = element;
break;
}
}
if (ce == null)
{
s_log.fine("No Standard Costing in System");
return;
}
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(product.getCtx(),
product.getAD_Client_ID(), product.get_TrxName());
@ -720,8 +733,6 @@ public class MCost extends X_M_Cost
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());
@ -735,15 +746,12 @@ public class MCost extends X_M_Cost
+ " - " + 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())
@ -756,7 +764,6 @@ public class MCost extends X_M_Cost
s_log.warning("Not created: Std.Cost for " + product.getName()
+ " - " + o.getName()
+ " - " + as.getName());
}
}
} // for all orgs
}