Fixes bug 28814: NPE fixed in Costing Background for a production product
authorUnai Martirena <unai.martirena@openbravo.com>
Thu, 29 Jan 2015 19:04:28 +0100
changeset 25687 e1e71f3b0a4f
parent 25686 af2f037123b1
child 25688 207433b8ebba
Fixes bug 28814: NPE fixed in Costing Background for a production product

When a product is defined as production the costing records created in the system are always for * organization. If a transaction of this product it was creating a backdated cost adjustment, in one place of the code a NPE exception error was happening because a costing record of legal entity org it was being trying to get. This has been fixed always filtering by client instead of organization when the product is of production type.
src/org/openbravo/costing/AverageCostAdjustment.java
--- a/src/org/openbravo/costing/AverageCostAdjustment.java	Tue Jan 27 20:10:56 2015 +0100
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java	Thu Jan 29 19:04:28 2015 +0100
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2015 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -723,7 +723,12 @@
     where.append(" as c");
     where.append("  left join c." + Costing.PROPERTY_INVENTORYTRANSACTION + " as trx");
     where.append(" where c." + Costing.PROPERTY_PRODUCT + " = :product");
-    where.append("   and c." + Costing.PROPERTY_ORGANIZATION + " = :org");
+    // FIXME: remove when manufacturing costs are fully migrated
+    if (bdCosting.getProduct().isProduction()) {
+      where.append("  and c." + Costing.PROPERTY_CLIENT + " = :client");
+    } else {
+      where.append("  and c." + Costing.PROPERTY_ORGANIZATION + " = :org");
+    }
     where.append("   and c." + Costing.PROPERTY_COSTTYPE + " = 'AVA'");
     if (bdCosting.getWarehouse() == null) {
       where.append(" and c." + Costing.PROPERTY_WAREHOUSE + " is null");
@@ -738,7 +743,12 @@
 
     OBQuery<Costing> qryCosting = OBDal.getInstance().createQuery(Costing.class, where.toString());
     qryCosting.setNamedParameter("product", bdCosting.getProduct());
-    qryCosting.setNamedParameter("org", bdCosting.getOrganization());
+    // FIXME: remove when manufacturing costs are fully migrated
+    if (bdCosting.getProduct().isProduction()) {
+      qryCosting.setNamedParameter("client", bdCosting.getClient());
+    } else {
+      qryCosting.setNamedParameter("org", bdCosting.getOrganization());
+    }
     if (bdCosting.getWarehouse() != null) {
       qryCosting.setNamedParameter("warehouse", bdCosting.getWarehouse());
     }