Fixes bug 28792: Null Pointer exception now is avoided in Costing Background
authorUnai Martirena <unai.martirena@openbravo.com>
Tue, 27 Jan 2015 20:08:23 +0100
changeset 25685 5bd6da7f0dad
parent 25684 da97e2f7803d
child 25686 af2f037123b1
Fixes bug 28792: Null Pointer exception now is avoided in Costing Background


The problem was in AverageCostAdjustment java process while calling AverageAlgorithm.getProductCost method. While returning null, Null Pointer Exception error was raised.
src/org/openbravo/costing/AverageCostAdjustment.java
--- a/src/org/openbravo/costing/AverageCostAdjustment.java	Tue Jan 13 17:52:27 2015 +0100
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java	Tue Jan 27 20:08:23 2015 +0100
@@ -119,6 +119,11 @@
     // Initialize current unit cost including the cost adjustments.
     Costing costing = AverageAlgorithm.getProductCost(trxDate, basetrx.getProduct(),
         getCostDimensions(), getCostOrg());
+    if (costing == null) {
+      throw new OBException("@NoAvgCostDefined@ @Organization@: " + getCostOrg().getName()
+          + ", @Product@: " + basetrx.getProduct().getName() + ", @Date@: "
+          + OBDateUtils.formatDate(trxDate));
+    }
     BigDecimal cost = null;
     // If current stock is zero the cost is not modified until a related transaction that modifies
     // the stock is found.
@@ -383,6 +388,11 @@
       // This is the current costing rule. Check if current average cost needs to be updated.
       Costing currentCosting = AverageAlgorithm.getProductCost(new Date(), basetrx.getProduct(),
           getCostDimensions(), getCostOrg());
+      // if (currentCosting == null) {
+      // throw new OBException("@NoAvgCostDefined@ @Organization@: " + getCostOrg().getName()
+      // + ", @Product@: " + basetrx.getProduct().getName() + ", @Date@: "
+      // + OBDateUtils.formatDate(new Date()));
+      // }
       if (currentCosting.getCost().compareTo(cost) != 0) {
         basetrx = getTransaction();
         Date newDate = new Date();