Fixes Issue 30936. Return Material flow should not be included
authorDavid Miguelez <david.miguelez@openbravo.com>
Mon, 28 Sep 2015 18:10:02 +0200
changeset 27632 9ee648f47df5
parent 27631 47ec5cda846f
child 27633 d57ecc399f74
child 27636 ebe9ebd06ddd
Fixes Issue 30936. Return Material flow should not be included
in Price Correction Process.
Also, make sure every Transaction that goes through this process
is set to no longer check Price Correction.
src/org/openbravo/costing/PriceDifferenceProcess.java
--- a/src/org/openbravo/costing/PriceDifferenceProcess.java	Tue Sep 29 13:06:08 2015 +0200
+++ b/src/org/openbravo/costing/PriceDifferenceProcess.java	Mon Sep 28 18:10:02 2015 +0200
@@ -31,6 +31,7 @@
 import org.hibernate.ScrollableResults;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.exception.OBException;
+import org.openbravo.costing.CostingServer.TrxType;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
@@ -48,8 +49,8 @@
 public class PriceDifferenceProcess {
   private static CostAdjustment costAdjHeader = null;
 
-  private static boolean calculateTransactionPriceDifference(MaterialTransaction materialTransaction)
-      throws OBException {
+  private static boolean calculateTransactionPriceDifferenceLogic(
+      MaterialTransaction materialTransaction) throws OBException {
     boolean costAdjCreated = false;
 
     // With Standard Algorithm, no cost adjustment is needed
@@ -67,10 +68,12 @@
     Date trxDate = materialTransaction.getMovementDate();
     int costCurPrecission = trxCurrency.getCostingPrecision().intValue();
     ShipmentInOutLine receiptLine = materialTransaction.getGoodsShipmentLine();
-    if (receiptLine == null || receiptLine.getShipmentReceipt().isSalesTransaction()) {
+    if (receiptLine == null
+        || !isValidPriceAdjTrx(receiptLine.getMaterialMgmtMaterialTransactionList().get(0))) {
       // We can only adjust cost of receipt lines.
       return false;
     }
+
     BigDecimal receiptQty = receiptLine.getMovementQuantity();
     boolean isNegativeReceipt = receiptQty.signum() == -1;
     if (isNegativeReceipt) {
@@ -153,10 +156,20 @@
       costAdjCreated = true;
     }
 
+    return costAdjCreated;
+  }
+
+  private static boolean calculateTransactionPriceDifference(MaterialTransaction materialTransaction)
+      throws OBException {
+
+    boolean costAdjCreated = calculateTransactionPriceDifferenceLogic(materialTransaction);
+
     materialTransaction.setCheckpricedifference(Boolean.FALSE);
     OBDal.getInstance().save(materialTransaction);
     OBDal.getInstance().flush();
+
     return costAdjCreated;
+
   }
 
   public static JSONObject processPriceDifferenceTransaction(MaterialTransaction materialTransaction)
@@ -268,4 +281,17 @@
       // PDC: Price Dif Correction
     }
   }
+
+  /**
+   * True if is an Incoming Transaction
+   */
+  private static boolean isValidPriceAdjTrx(MaterialTransaction trx) {
+    TrxType transacctionType = TrxType.getTrxType(trx);
+    switch (transacctionType) {
+    case Receipt:
+      return true;
+    default:
+      return false;
+    }
+  }
 }