[Logistics] In C&R and CL the order's delivered status is updated.
authorAsier Martirena <asier.martirena@openbravo.com>
Tue, 19 Sep 2017 17:33:36 +0200
changeset 32250 8f2cfd334ef8
parent 32249 a1b1641f33a8
child 32251 108df1076a64
[Logistics] In C&R and CL the order's delivered status is updated.

Now, the canceled and cancellation orders must check the existing shipments in order to set the delivered value to true or false.
src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java
--- a/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Wed Aug 30 10:51:37 2017 +0200
+++ b/src/org/openbravo/erpCommon/businessUtility/CancelAndReplaceUtils.java	Tue Sep 19 17:33:36 2017 +0200
@@ -243,6 +243,20 @@
         throw new OBException(String.format(OBMessageUtils.messageBD("IsCancelled"),
             oldOrder.getDocumentNo()));
       }
+
+      // Check if there's any shipment associated to the old order
+      final StringBuffer hql = new StringBuffer();
+      hql.append("SELECT 1 ");
+      hql.append("FROM OrderLine AS ol ");
+      hql.append("WHERE EXISTS (SELECT 1 ");
+      hql.append("FROM MaterialMgmtShipmentInOutLine AS sl ");
+      hql.append("WHERE sl.salesOrderLine = ol)");
+      hql.append("AND ol.salesOrder.id = :orderId)");
+      final Query query = OBDal.getInstance().getSession().createQuery(hql.toString());
+      query.setParameter("orderId", oldOrderId);
+      query.setMaxResults(1);
+      final boolean hasShipment = query.uniqueResult() != null;
+
       // Close old reservations
       closeOldReservations(oldOrder);
 
@@ -422,6 +436,18 @@
         processShipmentHeader(nettingGoodsShipment);
       }
 
+      // Set the delivered status for the old and inverse orders
+      if (createNettingGoodsShipment) {
+        inverseOrder.setDelivered(true);
+        oldOrder.setDelivered(true);
+      } else if (associateShipmentToNewReceipt && replaceOrder) {
+        inverseOrder.setDelivered(false);
+        oldOrder.setDelivered(false);
+      } else {
+        inverseOrder.setDelivered(false);
+        oldOrder.setDelivered(hasShipment ? true : false);
+      }
+
       // Close inverse order
       inverseOrder.setDocumentStatus("CL");
       inverseOrder.setDocumentAction("--");