Fixes bug 28051: Reserved qty now is correct.
authorUnai Martirena <unai.martirena@openbravo.com>
Thu, 26 Feb 2015 19:48:36 +0100
changeset 26090 b6c2ecaf7e1a
parent 26089 e0dc3cac2184
child 26091 60961105cec1
child 26095 7f9c56fa7aba
Fixes bug 28051: Reserved qty now is correct.

In this issue 3 changes have been done:
[1]: In M_RESERVATION_POST stored procedure, when calling to AD_UPDATE_PINSTANCE an extra parameter has been added ('N'). This has been done to avoid to do a commit when working with Oracle database, because it was causing to behave different in Postgres and Oracle.
[2]: In StockReservationPickAndEditDataSource, when opening Manage Reservations P&E from Sales Order, it retrieves a Reservation related to the Order Line if it exists and it processes. This was failing in Oracle if it was already processed, so a check has been added to avoid this case.
[3]: In ManageReservationActionHandler, when clicking Done in Manage Reservation P&E, it was first reserving what the user was typing in the P&E, and if it was not processed the reservation, it was processing it. As the M_RESERVATION_POST tries always to reserve as much as possible, it was overriding the previously set amounts. In order to prevent this, now first the reservation is being processed and after that the values typed in the UI are being set to the reservation.
src-db/database/model/functions/M_RESERVATION_POST.xml
src/org/openbravo/common/actionhandler/ManageReservationActionHandler.java
src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java
--- a/src-db/database/model/functions/M_RESERVATION_POST.xml	Thu Feb 26 21:38:33 2015 +0000
+++ b/src-db/database/model/functions/M_RESERVATION_POST.xml	Thu Feb 26 19:48:36 2015 +0100
@@ -57,7 +57,7 @@
     --  Update AD_PInstance
     DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_pinstance_id) ;
     v_ResultStr:='PInstanceNotFound';
-    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
+    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL, 'N') ;
     --  Get Parameters
     v_ResultStr:='ReadingParameters';
     FOR Cur_Parameter IN (
@@ -417,7 +417,7 @@
 
   IF (p_pinstance_id IS NOT NULL) THEN
     DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message) ;
-    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message) ;
+    AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'N', v_Result, v_Message, 'N') ;
     DBMS_OUTPUT.PUT_LINE('--<<M_Reservation_Post finished>> ' || v_Message) ;
   END IF;
   RETURN;
@@ -428,7 +428,7 @@
   DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
   IF (p_pinstance_id IS NOT NULL) THEN
     ROLLBACK;
-    AD_UPDATE_PINSTANCE(p_pinstance_id, NULL, 'N', 0, v_ResultStr) ;
+    AD_UPDATE_PINSTANCE(p_pinstance_id, NULL, 'N', 0, v_ResultStr, 'N') ;
   ELSE
     RAISE;
   END IF;
--- a/src/org/openbravo/common/actionhandler/ManageReservationActionHandler.java	Thu Feb 26 21:38:33 2015 +0000
+++ b/src/org/openbravo/common/actionhandler/ManageReservationActionHandler.java	Thu Feb 26 19:48:36 2015 +0100
@@ -78,6 +78,15 @@
 
         processReservation = reservation.getRESStatus().equals("DR");
       }
+      if (processReservation) {
+        OBError result = ReservationUtils.processReserve(reservation, "PR");
+        if (result.getType().equals("Error")) {
+          JSONObject errorMessage = new JSONObject();
+          errorMessage.put("severity", result.getType().toLowerCase());
+          errorMessage.put("text", result.getMessage());
+          jsonRequest.put("message", errorMessage);
+        }
+      }
       if (reservation != null) {
         // FIXME: Replace with OBDao method when handler is merged with latest pi.
         // List<String> idList = OBDao.getIDListFromOBObject(reservation
@@ -88,15 +97,6 @@
         }
         manageReservedStockLines(jsonRequest, reservation, idList);
       }
-      if (processReservation) {
-        OBError result = ReservationUtils.processReserve(reservation, "PR");
-        if (result.getType().equals("Error")) {
-          JSONObject errorMessage = new JSONObject();
-          errorMessage.put("severity", result.getType().toLowerCase());
-          errorMessage.put("text", result.getMessage());
-          jsonRequest.put("message", errorMessage);
-        }
-      }
 
     } catch (Exception e) {
       log.error("Error in Manage Reservation Action Handler", e);
--- a/src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java	Thu Feb 26 21:38:33 2015 +0000
+++ b/src/org/openbravo/common/datasource/StockReservationPickAndEditDataSource.java	Thu Feb 26 19:48:36 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) 2014 Openbravo SLU
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -589,7 +589,9 @@
     if (ol != null && !"".equals(ol)) {
       reservation = ReservationUtils.getReservationFromOrder(OBDal.getInstance().get(
           OrderLine.class, ol));
-      ReservationUtils.processReserve(reservation, "PR");
+      if (reservation.getRESStatus().equals("DR")) {
+        ReservationUtils.processReserve(reservation, "PR");
+      }
     } else {
       reservation = OBDal.getInstance().get(Reservation.class, strReservation);
     }