[Reservations]Improve Error handling
authorRafa de Miguel <rafael.demiguel@openbravo.com>
Thu, 08 Nov 2012 10:15:01 +0100
changeset 18684 6ce827f9d469
parent 18683 a3b01ae29b19
child 18685 a263369e06d5
[Reservations]Improve Error handling
src-db/database/sourcedata/AD_MESSAGE.xml
src/org/openbravo/materialmgmt/ReservationUtils.java
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Nov 06 13:00:40 2012 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Nov 08 10:15:01 2012 +0100
@@ -19224,6 +19224,17 @@
 <!--B5B771C2ACC04FE4A75C39249BFAD2EC-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--B5B771C2ACC04FE4A75C39249BFAD2EC--></AD_MESSAGE>
 
+<!--B6C42649E3704354972819C1B2C2DACF--><AD_MESSAGE>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <AD_MESSAGE_ID><![CDATA[B6C42649E3704354972819C1B2C2DACF]]></AD_MESSAGE_ID>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <VALUE><![CDATA[cannotReserveDeliveredSalesOrderLine]]></VALUE>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <MSGTEXT><![CDATA[You can not reserve quantity for a delivered sales order line.]]></MSGTEXT>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--B6C42649E3704354972819C1B2C2DACF-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--B6C42649E3704354972819C1B2C2DACF--></AD_MESSAGE>
+
 <!--B6CDB7D04FD249579A48D26C0ED48F45--><AD_MESSAGE>
 <!--B6CDB7D04FD249579A48D26C0ED48F45-->  <AD_MESSAGE_ID><![CDATA[B6CDB7D04FD249579A48D26C0ED48F45]]></AD_MESSAGE_ID>
 <!--B6CDB7D04FD249579A48D26C0ED48F45-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -19886,6 +19897,17 @@
 <!--CF72BCDFFF044C1D8007B907D8B64DF3-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--CF72BCDFFF044C1D8007B907D8B64DF3--></AD_MESSAGE>
 
+<!--CFB9AB0D6D564592A40147738EFF81AB--><AD_MESSAGE>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <AD_MESSAGE_ID><![CDATA[CFB9AB0D6D564592A40147738EFF81AB]]></AD_MESSAGE_ID>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <VALUE><![CDATA[notValidReservationType]]></VALUE>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <MSGTEXT><![CDATA[Not a valid reservation type.]]></MSGTEXT>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--CFB9AB0D6D564592A40147738EFF81AB-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--CFB9AB0D6D564592A40147738EFF81AB--></AD_MESSAGE>
+
 <!--CFE6932D251A4631A5223E845D4A4891--><AD_MESSAGE>
 <!--CFE6932D251A4631A5223E845D4A4891-->  <AD_MESSAGE_ID><![CDATA[CFE6932D251A4631A5223E845D4A4891]]></AD_MESSAGE_ID>
 <!--CFE6932D251A4631A5223E845D4A4891-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -20841,6 +20863,17 @@
 <!--F38A8843E6504699A91571A79C3AA3DF-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--F38A8843E6504699A91571A79C3AA3DF--></AD_MESSAGE>
 
+<!--F572F66AA4F344769920F13B233D0B01--><AD_MESSAGE>
+<!--F572F66AA4F344769920F13B233D0B01-->  <AD_MESSAGE_ID><![CDATA[F572F66AA4F344769920F13B233D0B01]]></AD_MESSAGE_ID>
+<!--F572F66AA4F344769920F13B233D0B01-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F572F66AA4F344769920F13B233D0B01-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F572F66AA4F344769920F13B233D0B01-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F572F66AA4F344769920F13B233D0B01-->  <VALUE><![CDATA[cannotReservePurchaseOrder]]></VALUE>
+<!--F572F66AA4F344769920F13B233D0B01-->  <MSGTEXT><![CDATA[Purchase order line can not be reserved.]]></MSGTEXT>
+<!--F572F66AA4F344769920F13B233D0B01-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--F572F66AA4F344769920F13B233D0B01-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F572F66AA4F344769920F13B233D0B01--></AD_MESSAGE>
+
 <!--F6E3C4F8AAD64A07A3BC1937B053689E--><AD_MESSAGE>
 <!--F6E3C4F8AAD64A07A3BC1937B053689E-->  <AD_MESSAGE_ID><![CDATA[F6E3C4F8AAD64A07A3BC1937B053689E]]></AD_MESSAGE_ID>
 <!--F6E3C4F8AAD64A07A3BC1937B053689E-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/materialmgmt/ReservationUtils.java	Tue Nov 06 13:00:40 2012 +0100
+++ b/src/org/openbravo/materialmgmt/ReservationUtils.java	Thu Nov 08 10:15:01 2012 +0100
@@ -24,6 +24,8 @@
 
 import javax.servlet.ServletException;
 
+import jxl.common.Logger;
+
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.structure.BaseOBObject;
 import org.openbravo.dal.core.DalUtil;
@@ -44,16 +46,21 @@
   String returnValue;
   String exito;
 
+  private static final Logger log4j = Logger.getLogger(ReservationUtils.class);
+
   public static Reservation createReserveFromSalesOrderLine(OrderLine soLine, boolean doProcess)
       throws OBException {
     if (!soLine.getSalesOrder().isSalesTransaction()) {
-      throw new OBException("@cannotReservePurchaseOrder@");
+      log4j.error("ReservationUtils: @cannotReservePurchaseOrder@");
+      throw new OBException(OBMessageUtils.messageBD("@cannotReservePurchaseOrder@"));
     }
     if (soLine.getOrderedQuantity().subtract(soLine.getDeliveredQuantity())
         .compareTo(BigDecimal.ZERO) == 0) {
-      throw new OBException("@cannotReserveDeliveredSalesOrderLine@");
+      log4j.error("ReservationUtils: @cannotReserveDeliveredSalesOrderLine@");
+      throw new OBException(OBMessageUtils.messageBD("@cannotReserveDeliveredSalesOrderLine@"));
     }
 
+    OBDal.getInstance().flush();
     CSResponse cs = null;
     try {
       cs = ReservationUtilsData.createReserveFromSalesOrderLine(
@@ -70,12 +77,15 @@
   }
 
   public static OBError reserveStockAuto(Reservation reservation) throws OBException {
+
+    OBDal.getInstance().flush();
     CSResponse cs = null;
     try {
       cs = ReservationUtilsData.reserveStockAuto(OBDal.getInstance().getConnection(false),
           new DalConnectionProvider(), reservation.getId(),
           (String) DalUtil.getId(OBContext.getOBContext().getUser()));
     } catch (ServletException e) {
+      log4j.error("ReservationUtils Error: ", e);
       throw new OBException(e.getMessage());
     }
 
@@ -105,15 +115,18 @@
     } else if (obObject instanceof StorageDetail) {
       strType = "SD";
     } else {
+      log4j.error("ReservationUtils: @notValidReservationType@");
       throw new OBException("@notValidReservationType@");
     }
 
+    OBDal.getInstance().flush();
     CSResponse cs = null;
     try {
       cs = ReservationUtilsData.reserveStockManual(OBDal.getInstance().getConnection(false),
           new DalConnectionProvider(), reservation.getId(), strType, obObject.getId().toString(),
           quantity.toString(), (String) DalUtil.getId(OBContext.getOBContext().getUser()));
     } catch (ServletException e) {
+      log4j.error("ReservationUtils Error: ", e);
       throw new OBException(e.getMessage());
     }