From 37a4b33bf6bc357c6ba327b00415d3c6bb76a374 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 18 Apr 2012 10:31:32 -0500 Subject: [PATCH] IDEMPIERE-241 Unnecessary cost records added on product creation Code integrated from Compiere community 3.3.0 version --- .../src/org/compiere/model/MCost.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MCost.java b/org.adempiere.base/src/org/compiere/model/MCost.java index a68f3443b4..831ae108c9 100644 --- a/org.adempiere.base/src/org/compiere/model/MCost.java +++ b/org.adempiere.base/src/org/compiere/model/MCost.java @@ -708,7 +708,20 @@ public class MCost extends X_M_Cost s_log.config(product.getName()); // Cost Elements - List 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 }