details:   https://code.openbravo.com/erp/devel/pi/rev/6d346acd0ba3
changeset: 35384:6d346acd0ba3
user:      Atul Gaware <atul.gaware <at> openbravo.com>
date:      Tue Jan 29 23:14:28 2019 +0530
summary:   Fixes Issue 0039988: Last inventory counting no updating

M_Transaction records are not created for inventory count line
having qtyCount equals to book quantity or order quantity equals
order quantity book. Hence update inventory is not called which
actual updates the date inventory in M_Storage_Detail.

Update Date Inventory method is introduced and now used to update
date in such cases which calls update inventory.

diffstat:

 src/org/openbravo/materialmgmt/InventoryCountProcess.java |  62 ++++++++++++++-
 1 files changed, 60 insertions(+), 2 deletions(-)

diffs (96 lines):

diff -r e74dadb5ea9b -r 6d346acd0ba3 
src/org/openbravo/materialmgmt/InventoryCountProcess.java
--- a/src/org/openbravo/materialmgmt/InventoryCountProcess.java Wed Jan 30 
13:48:11 2019 +0100
+++ b/src/org/openbravo/materialmgmt/InventoryCountProcess.java Tue Jan 29 
23:14:28 2019 +0530
@@ -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) 2012-2018 Openbravo SLU
+ * All portions are Copyright (C) 2012-2019 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,6 +19,8 @@
 
 package org.openbravo.materialmgmt;
 
+import java.math.BigDecimal;
+import java.sql.CallableStatement;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -249,10 +251,13 @@
       OBException obException = new OBException(e.getMessage(), e.getCause());
       throw obException;
     }
-
     inventory.setProcessed(true);
     OBDal.getInstance().flush();
 
+    // Update inventory date for inventory count lines whose qtycount is equal 
to book quantity or
+    // orderquantity is equals to quantity order book
+    updateDateInventory(inventory);
+
     return msg;
   }
 
@@ -422,6 +427,59 @@
     }
   }
 
+  private void updateDateInventory(InventoryCount inventory) {
+
+    try {
+      for (InventoryCountLine invCountLine : 
inventory.getMaterialMgmtInventoryCountLineList()) {
+        if 
(invCountLine.getQuantityCount().compareTo(invCountLine.getBookQuantity()) == 0
+            || (invCountLine.getOrderQuantity() != null
+                && invCountLine.getQuantityOrderBook() != null && 
invCountLine.getOrderQuantity()
+                    .compareTo(invCountLine.getQuantityOrderBook()) == 0)) {
+          org.openbravo.database.ConnectionProvider cp = new 
DalConnectionProvider(false);
+          CallableStatement updateStockStatement = cp.getConnection()
+              .prepareCall("{call M_UPDATE_INVENTORY 
(?,?,?,?,?,?,?,?,?,?,?,?,?)}");
+          // client
+          updateStockStatement.setString(1, invCountLine.getClient().getId());
+          // org
+          updateStockStatement.setString(2, 
invCountLine.getOrganization().getId());
+          // user
+          updateStockStatement.setString(3, 
OBContext.getOBContext().getUser().getId());
+          // product
+          updateStockStatement.setString(4, invCountLine.getProduct().getId());
+          // locator
+          updateStockStatement.setString(5, 
invCountLine.getStorageBin().getId());
+          // attributesetinstance
+          updateStockStatement.setString(6,
+              invCountLine.getAttributeSetValue() != null
+                  ? invCountLine.getAttributeSetValue().getId()
+                  : null);
+          // uom
+          updateStockStatement.setString(7, invCountLine.getUOM().getId());
+          // product uom
+          updateStockStatement.setString(8,
+              invCountLine.getOrderUOM() != null ? 
invCountLine.getOrderUOM().getId() : null);
+          // p_qty
+          updateStockStatement.setBigDecimal(9, BigDecimal.ZERO);
+          // p_qtyorder
+          updateStockStatement.setBigDecimal(10, BigDecimal.ZERO);
+          // p_dateLastInventory --- **
+          updateStockStatement.setDate(11,
+              new java.sql.Date(inventory.getMovementDate().getTime()));
+          // p_preqty
+          updateStockStatement.setBigDecimal(12, BigDecimal.ZERO);
+          // p_preqtyorder
+          updateStockStatement.setBigDecimal(13, BigDecimal.ZERO);
+
+          updateStockStatement.execute();
+        }
+      }
+      OBDal.getInstance().flush();
+    } catch (Exception e) {
+      log4j.error("Error in updateDateInventory while Inventory Count 
Process", e);
+      throw new OBException(e.getMessage(), e);
+    }
+  }
+
   private void checkStock(InventoryCount inventory) {
     String attribute;
     final StringBuilder hqlString = new StringBuilder();


_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to