details:   https://code.openbravo.com/erp/devel/pi/rev/d816955a96eb
changeset: 32348:d816955a96eb
user:      Asier Martirena <asier.martirena <at> openbravo.com>
date:      Thu Jun 22 19:25:26 2017 +0200
summary:   Fixed issue 36294: A non canceled order can be set as canceled

Locked the database in order to not be able to synchronize two C&R or CL at the 
same time.

diffstat:

 src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java |  17 
+++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diffs (51 lines):

diff -r ee31b75a9991 -r d816955a96eb 
src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java
--- a/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java    
Thu Jun 22 13:16:33 2017 +0000
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java    
Thu Jun 22 19:25:26 2017 +0200
@@ -29,9 +29,11 @@
 import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.LockOptions;
 import org.hibernate.Query;
 import org.hibernate.ScrollMode;
 import org.hibernate.ScrollableResults;
+import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.process.FIN_AddPayment;
 import org.openbravo.advpaymentmngt.process.FIN_PaymentProcess;
@@ -235,9 +237,10 @@
         oldOrder = OBDal.getInstance().get(Order.class, orderId);
         oldOrderId = oldOrder.getId();
       }
+      oldOrder = lockOrder(oldOrder);
 
       // Added check in case Cancel and Replace button is hit more than once
-      if (jsonorder == null && oldOrder.isCancelled()) {
+      if (oldOrder.isCancelled()) {
         throw new 
OBException(String.format(OBMessageUtils.messageBD("IsCancelled"),
             oldOrder.getDocumentNo()));
       }
@@ -248,6 +251,7 @@
       if (newOrderId != null) {
         newOrder = OBDal.getInstance().get(Order.class, newOrderId);
       }
+
       oldOrder = OBDal.getInstance().get(Order.class, oldOrderId);
 
       // Get documentNo for the inverse Order Header coming from jsonorder, if 
exists
@@ -1281,4 +1285,15 @@
     return paymentSchedule;
   }
 
+  private static Order lockOrder(Order order) {
+    StringBuilder where = new StringBuilder("select c from " + 
Order.ENTITY_NAME
+        + " c where id = :id");
+    final Session session = OBDal.getInstance().getSession();
+    final Query query = session.createQuery(where.toString());
+    query.setParameter("id", order.getId());
+    query.setMaxResults(1);
+    query.setLockOptions(LockOptions.UPGRADE);
+    return (Order) query.uniqueResult();
+  }
+
 }

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to