Fixes Issue 24908: Order Date and Scheduled Delivery Date in Order Lines are being overwritten by Header Values
authorPandeeswari Ramakrishnan <pandeeswari.ramakrishnan@openbravo.com>
Mon, 14 Oct 2013 16:46:37 +0530
changeset 21279 551a90dec0c7
parent 21278 8105d6144b76
child 21280 4c35ecd054dd
Fixes Issue 24908: Order Date and Scheduled Delivery Date in Order Lines are being overwritten by Header Values
src-db/database/sourcedata/AD_REF_LIST.xml
src/org/openbravo/event/OrderEventHandler.java
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Mon Oct 14 11:34:32 2013 +0200
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Mon Oct 14 16:46:37 2013 +0530
@@ -8541,6 +8541,17 @@
 <!--2726618D177C401C8D764380FD6DA765-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--2726618D177C401C8D764380FD6DA765--></AD_REF_LIST>
 
+<!--28355203AC7843F2994AD4FAA9BE91BC--><AD_REF_LIST>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <AD_REF_LIST_ID><![CDATA[28355203AC7843F2994AD4FAA9BE91BC]]></AD_REF_LIST_ID>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <VALUE><![CDATA[SyncDateDelivered]]></VALUE>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <NAME><![CDATA[Syncronize date delivered based on header info]]></NAME>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--28355203AC7843F2994AD4FAA9BE91BC-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--28355203AC7843F2994AD4FAA9BE91BC--></AD_REF_LIST>
+
 <!--28F1C8DD5F5746C5928626525EC81BB2--><AD_REF_LIST>
 <!--28F1C8DD5F5746C5928626525EC81BB2-->  <AD_REF_LIST_ID><![CDATA[28F1C8DD5F5746C5928626525EC81BB2]]></AD_REF_LIST_ID>
 <!--28F1C8DD5F5746C5928626525EC81BB2-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -10771,6 +10782,17 @@
 <!--A6F23B8BC2CA497A80FD6ABFDD3AEE93-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--A6F23B8BC2CA497A80FD6ABFDD3AEE93--></AD_REF_LIST>
 
+<!--A8B33A78E45F474DA5CCA51E61D5B32D--><AD_REF_LIST>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <AD_REF_LIST_ID><![CDATA[A8B33A78E45F474DA5CCA51E61D5B32D]]></AD_REF_LIST_ID>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <VALUE><![CDATA[SyncDateOrdered]]></VALUE>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <NAME><![CDATA[Syncronize date ordered based on header info]]></NAME>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--A8B33A78E45F474DA5CCA51E61D5B32D--></AD_REF_LIST>
+
 <!--AA2BD581FDB44700A4C6D3D47C3DD354--><AD_REF_LIST>
 <!--AA2BD581FDB44700A4C6D3D47C3DD354-->  <AD_REF_LIST_ID><![CDATA[AA2BD581FDB44700A4C6D3D47C3DD354]]></AD_REF_LIST_ID>
 <!--AA2BD581FDB44700A4C6D3D47C3DD354-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/event/OrderEventHandler.java	Mon Oct 14 11:34:32 2013 +0200
+++ b/src/org/openbravo/event/OrderEventHandler.java	Mon Oct 14 16:46:37 2013 +0530
@@ -29,8 +29,11 @@
 import org.openbravo.base.model.Property;
 import org.openbravo.client.kernel.event.EntityPersistenceEventObserver;
 import org.openbravo.client.kernel.event.EntityUpdateEvent;
+import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.businessUtility.Preferences;
+import org.openbravo.erpCommon.utility.PropertyException;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.order.OrderLine;
 
@@ -53,21 +56,40 @@
     final Property orderDateProperty = orderEntity.getProperty(Order.PROPERTY_ORDERDATE);
     final Property scheduledDateProperty = orderEntity
         .getProperty(Order.PROPERTY_SCHEDULEDDELIVERYDATE);
+    String syncDateOrdered = null, syncDateDelivered = null;
     String orderId = (String) event.getTargetInstance().getId();
     Date newOrderDate = (Date) event.getCurrentState(orderDateProperty);
     Date oldOrderDate = (Date) event.getPreviousState(orderDateProperty);
     Date newScheduledDate = (Date) event.getCurrentState(scheduledDateProperty);
     Date oldScheduledDate = (Date) event.getPreviousState(scheduledDateProperty);
+
+    // Check whether the preference is set to sync with order header
+    try {
+      syncDateOrdered = Preferences.getPreferenceValue("SyncDateOrdered", true, OBContext
+          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
+          OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null);
+    } catch (PropertyException e) {
+      // if property not found, do not sync the ordered date
+      syncDateOrdered = "N";
+    }
+    try {
+      syncDateDelivered = Preferences.getPreferenceValue("SyncDateDelivered", true, OBContext
+          .getOBContext().getCurrentClient(), OBContext.getOBContext().getCurrentOrganization(),
+          OBContext.getOBContext().getUser(), OBContext.getOBContext().getRole(), null);
+    } catch (PropertyException e) {
+      // if property not found, do not sync the delivered date
+      syncDateDelivered = "N";
+    }
     OBCriteria<OrderLine> orderLineCriteria = OBDal.getInstance().createCriteria(OrderLine.class);
     orderLineCriteria.add(Restrictions.eq(OrderLine.PROPERTY_SALESORDER,
         OBDal.getInstance().get(Order.class, orderId)));
     if (orderLineCriteria.count() > 0) {
-      if (newOrderDate.compareTo(oldOrderDate)!=0) {
+      if (newOrderDate.compareTo(oldOrderDate) != 0 && "Y".equals(syncDateOrdered)) {
         for (OrderLine lines : orderLineCriteria.list()) {
           lines.setOrderDate(newOrderDate);
         }
       }
-      if (newScheduledDate.compareTo(oldScheduledDate)!=0) {
+      if (newScheduledDate.compareTo(oldScheduledDate) != 0 && "Y".equals(syncDateDelivered)) {
         for (OrderLine lines : orderLineCriteria.list()) {
           lines.setScheduledDeliveryDate(newScheduledDate);
         }