From a7c4fed665d4659f1744cbabeff06e8a1c878b3f Mon Sep 17 00:00:00 2001 From: armenrz Date: Sun, 13 Sep 2009 10:27:00 +0000 Subject: [PATCH] BF 2856009: Reversal costing is broken in Physical Inventory https://sourceforge.net/tracker/?func=detail&aid=2856009&group_id=176962&atid=879332 --- base/src/org/compiere/model/MInventory.java | 24 ++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/base/src/org/compiere/model/MInventory.java b/base/src/org/compiere/model/MInventory.java index 5a17a389c9..29d4f11206 100644 --- a/base/src/org/compiere/model/MInventory.java +++ b/base/src/org/compiere/model/MInventory.java @@ -948,11 +948,25 @@ public class MInventory extends X_M_Inventory implements DocAction continue; } - ProductCost pc = new ProductCost (Env.getCtx(), - line.getM_Product_ID(), M_AttributeSetInstance_ID, line.get_TrxName()); - pc.setQty(qty); - BigDecimal costs = pc.getProductCosts(as, line.getAD_Org_ID(), as.getCostingMethod(), - 0,false); + BigDecimal costs = Env.ZERO; + if (isReversal()) + { + String sql = "SELECT amt * -1 FROM M_CostDetail WHERE M_InventoryLine_ID=?"; // negate costs + MProduct product = new MProduct(getCtx(), line.getM_Product_ID(), line.get_TrxName()); + String CostingLevel = product.getCostingLevel(as); + if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) + sql = sql + " AND AD_Org_ID=" + getAD_Org_ID(); + else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel) && M_AttributeSetInstance_ID != 0) + sql = sql + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID; + costs = DB.getSQLValueBD(line.get_TrxName(), sql, line.getReversalLine_ID()); + } + else + { + ProductCost pc = new ProductCost (getCtx(), + line.getM_Product_ID(), M_AttributeSetInstance_ID, line.get_TrxName()); + pc.setQty(qty); + costs = pc.getProductCosts(as, line.getAD_Org_ID(), as.getCostingMethod(), 0,false); + } if (costs == null || costs.signum() == 0) { return "No Costs for " + line.getProduct().getName();