details:   https://code.openbravo.com/erp/devel/pi/rev/0b6bb996e29d
changeset: 34946:0b6bb996e29d
user:      Mark <markmm82 <at> gmail.com>
date:      Fri Nov 02 12:54:48 2018 -0400
summary:   Fixes issue 39530: No stock error for Orphan lines in Return to 
Vendor Shipment

By default the UI will show an error if there is no stock available and there
not exists at least one storage bin linked to an inventory status configured as
overissue = Y inside the Return To Vendor Shipment's Warehouse.

If there is no overissue bin inside the RTVS warehouse, then the No Stock error
is shown when the line is selected. Also when the RTVS line is inserted, the 
storage
bin is automatically filled with the overissue bin and when the RTVS is 
processed,
the stock goes to negative in that bin.

diffstat:

 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/CheckExistsOverissueBinForRFCShipmentWH.java
 |   73 +++++
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/return-material/ob-return-material.js
           |  126 +++++----
 2 files changed, 146 insertions(+), 53 deletions(-)

diffs (240 lines):

diff -r 6ce7b150e9e2 -r 0b6bb996e29d 
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/CheckExistsOverissueBinForRFCShipmentWH.java
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ 
b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/actionHandler/CheckExistsOverissueBinForRFCShipmentWH.java
  Fri Nov 02 12:54:48 2018 -0400
@@ -0,0 +1,73 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2018 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.advpaymentmngt.actionHandler;
+
+import java.util.Map;
+
+import org.codehaus.jettison.json.JSONObject;
+import org.openbravo.client.kernel.BaseActionHandler;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBQuery;
+import org.openbravo.model.common.enterprise.Locator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CheckExistsOverissueBinForRFCShipmentWH extends BaseActionHandler 
{
+  private static final Logger log = LoggerFactory
+      .getLogger(CheckExistsOverissueBinForRFCShipmentWH.class);
+
+  @Override
+  protected JSONObject execute(Map<String, Object> parameters, String data) {
+    JSONObject result = new JSONObject();
+    JSONObject errorMessage = new JSONObject();
+    try {
+      final JSONObject jsonData = new JSONObject(data);
+      final String warehouseId = jsonData.getString("warehouseId");
+      Locator overIssueBin = getOverissueBinForWarehouse(warehouseId);
+      result.put("overissueBin", overIssueBin != null ? overIssueBin.getId() : 
"");
+      result
+          .put("storageBin$_identifier", overIssueBin != null ? 
overIssueBin.getIdentifier() : "");
+    } catch (Exception e) {
+      log.error("Error parsing JSON Object.", e);
+      try {
+        errorMessage = new JSONObject();
+        errorMessage.put("severity", "error");
+        errorMessage.put("title", "Error");
+        errorMessage.put("text", "");
+        result.put("message", errorMessage);
+        result.put("overissueBin", "");
+        result.put("storageBin$_identifier", "");
+      } catch (Exception e2) {
+        log.error("Message could not be built", e2);
+      }
+    }
+    return result;
+  }
+
+  private Locator getOverissueBinForWarehouse(String warehouseId) {
+    StringBuilder sbHQL = new StringBuilder(" as sb");
+    sbHQL.append(" where sb.warehouse.id = :warehouseId");
+    sbHQL.append(" and sb.inventoryStatus.overissue = true");
+    OBQuery<Locator> sbQuery = OBDal.getInstance().createQuery(Locator.class, 
sbHQL.toString());
+    sbQuery.setNamedParameter("warehouseId", warehouseId);
+    sbQuery.setMaxResult(1);
+    return sbQuery.uniqueResult();
+  }
+}
\ No newline at end of file
diff -r 6ce7b150e9e2 -r 0b6bb996e29d 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/return-material/ob-return-material.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/return-material/ob-return-material.js
    Wed Nov 07 08:22:46 2018 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/return-material/ob-return-material.js
    Fri Nov 02 12:54:48 2018 -0400
@@ -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) 2011-2017 Openbravo SLU
+ * All portions are Copyright (C) 2011-2018 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -143,42 +143,45 @@
       editedRecord = null,
       storageBin = record.storageBin,
       i;
-  //Cheking available stock
-  if (storageBin === null) {
+  //Checking available stock
+  if (storageBin === null && !record.hasOverIssueBin) {
     item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_RM_NotAvailableStock', [record.rMOrderNo]));
     return false;
   }
-  // check value is positive and below available qty and pending qty
-  if (value === null || value < 0 || value > record.pending || value > 
record.availableQty) {
-    if (record.pending < record.availableQty) {
-      item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_RM_MoreThanPending', [record.pending]));
-    } else {
-      item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_RM_MoreThanAvailable', [record.availableQty]));
+  if (storageBin !== null && !record.hasOverIssueBin) {
+    // check value is positive and below available qty and pending qty. 
+    // This check it is only needed if there isn't any storage bin with 
Overissue inventory status in the RTVS Warehouse
+    if (value === null || value < 0 || value > record.pending || value > 
record.availableQty) {
+      if (record.pending < record.availableQty) {
+        item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_RM_MoreThanPending', [record.pending]));
+      } else {
+        item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_RM_MoreThanAvailable', [record.availableQty]));
+      }
+      return false;
     }
-    return false;
-  }
-  // check shipped total quantity for the order line is below pending qty.
-  var isUomManagementEnabled = OB.PropertyStore.get('UomManagement');
-  for (i = 0; i < selectedRecordsLength; i++) {
-    editedRecord = isc.addProperties({}, selectedRecords[i], 
item.grid.getEditedRecord(selectedRecords[i]));
-    if (editedRecord.orderLine === orderLine) {
-      if (isUomManagementEnabled === 'Y') {
-        if (record.returnedUOM === editedRecord.returnedUOM) {
-          pendingQty -= editedRecord.movementQuantity;
-        } else {
-          var movementQuantity = new 
BigDecimal(String(editedRecord.movementQuantity));
-          var rate = new BigDecimal(String(editedRecord.rate));
-          pendingQty -= (editedRecord.returnedUOM !== editedRecord.uOM) ? 
movementQuantity.multiply(
-          rate).toString() : movementQuantity.divide(rate).toString();
+    // check shipped total quantity for the order line is below pending qty.
+    var isUomManagementEnabled = OB.PropertyStore.get('UomManagement');
+    for (i = 0; i < selectedRecordsLength; i++) {
+      editedRecord = isc.addProperties({}, selectedRecords[i], 
item.grid.getEditedRecord(selectedRecords[i]));
+      if (editedRecord.orderLine === orderLine) {
+        if (isUomManagementEnabled === 'Y') {
+          if (record.returnedUOM === editedRecord.returnedUOM) {
+            pendingQty -= editedRecord.movementQuantity;
+          } else {
+            var movementQuantity = new 
BigDecimal(String(editedRecord.movementQuantity));
+            var rate = new BigDecimal(String(editedRecord.rate));
+            pendingQty -= (editedRecord.returnedUOM !== editedRecord.uOM) ? 
movementQuantity.multiply(
+            rate).toString() : movementQuantity.divide(rate).toString();
+          }
         }
-      }
-      if (pendingQty < 0) {
-        if (isUomManagementEnabled === 'Y') {
-          item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_RM_TooMuchShippedInUomManagement', []));
-        } else {
-          item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_RM_TooMuchShipped', [record.pending]));
+        if (pendingQty < 0) {
+          if (isUomManagementEnabled === 'Y') {
+            item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_RM_TooMuchShippedInUomManagement', []));
+          } else {
+            item.grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, 
null, OB.I18N.getLabel('OBUIAPP_RM_TooMuchShipped', [record.pending]));
+          }
+          return false;
         }
-        return false;
       }
     }
   }
@@ -200,34 +203,51 @@
       editedRecord = null,
       isstocked = record.stocked,
       i;
+  //calculate already shipped qty on grid
+  var calculateAlreadyShippedQtyOnGrid = function () {
+      var isUomManagementEnabled = OB.PropertyStore.get('UomManagement');
+      for (i = 0; i < selectedRecords.length; i++) {
+        editedRecord = isc.addProperties({}, selectedRecords[i], 
grid.getEditedRecord(selectedRecords[i]));
+        if (editedRecord.orderLine === orderLine && selectedRecords[i].id !== 
record.id) {
+          if (isUomManagementEnabled === 'Y') {
+            if (record.returnedUOM === editedRecord.returnedUOM) {
+              shippedQty = shippedQty.add(new 
BigDecimal(String(editedRecord.movementQuantity)));
+            } else {
+              var movementQuantity = new 
BigDecimal(String(editedRecord.movementQuantity));
+              var rate = new BigDecimal(String(editedRecord.rate));
+              shippedQty = (editedRecord.returnedUOM !== editedRecord.uOM) ? 
shippedQty.add(movementQuantity.multiply(rate)) : 
shippedQty.add(movementQuantity.divide(rate));
+            }
+          }
+        }
+      }
+      pending = pending.subtract(shippedQty);
+      if (pending.compareTo(availableQty) < 0) {
+        record.movementQuantity = pending.toString();
+      } else {
+        record.movementQuantity = availableQty.toString();
+      }
+      };
   if (state) {
     // Checking available stock
     if (storageBin === null && isstocked) {
-      grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_RM_NotAvailableStock', [record.rMOrderNo]));
-      return false;
-    }
-    // calculate already shipped qty on grid
-    var isUomManagementEnabled = OB.PropertyStore.get('UomManagement');
-    for (i = 0; i < selectedRecords.length; i++) {
-      editedRecord = isc.addProperties({}, selectedRecords[i], 
grid.getEditedRecord(selectedRecords[i]));
-      if (editedRecord.orderLine === orderLine && selectedRecords[i].id !== 
record.id) {
-        if (isUomManagementEnabled === 'Y') {
-          if (record.returnedUOM === editedRecord.returnedUOM) {
-            shippedQty = shippedQty.add(new 
BigDecimal(String(editedRecord.movementQuantity)));
+      // Check if exists any storage bin with overissue inventory status
+      var callback = function (response, data, request) {
+          if (data.overissueBin === '') {
+            grid.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, null, 
OB.I18N.getLabel('OBUIAPP_RM_NotAvailableStock', [record.rMOrderNo]));
+            record.hasOverIssueBin = false;
+            return false;
           } else {
-            var movementQuantity = new 
BigDecimal(String(editedRecord.movementQuantity));
-            var rate = new BigDecimal(String(editedRecord.rate));
-            shippedQty = (editedRecord.returnedUOM !== editedRecord.uOM) ? 
shippedQty.add(movementQuantity.multiply(rate)) : 
shippedQty.add(movementQuantity.divide(rate));
+            calculateAlreadyShippedQtyOnGrid();
+            record.hasOverIssueBin = true;
+            record.storageBin = data.overissueBin;
+            record.storageBin$_identifier = data.storageBin$_identifier;
           }
-        }
-
-      }
-    }
-    pending = pending.subtract(shippedQty);
-    if (pending.compareTo(availableQty) < 0) {
-      record.movementQuantity = pending.toString();
+          };
+      
OB.RemoteCallManager.call('org.openbravo.advpaymentmngt.actionHandler.CheckExistsOverissueBinForRFCShipmentWH',
 {
+        warehouseId: grid.view.parentWindow.activeView.getContextInfo(false, 
true, true, true).inpmWarehouseId
+      }, {}, callback);
     } else {
-      record.movementQuantity = availableQty.toString();
+      calculateAlreadyShippedQtyOnGrid();
     }
   }
 };


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

Reply via email to