Fixes Issue 25174: Goods shipment can be booked without product and quantity.
authorGaurav Deshmukh <gaurav.deshmukh@openbravo.com>
Thu, 30 Jan 2014 11:29:06 +0530
changeset 22017 af9e83d05902
parent 22016 99858c127329
child 22018 12b3d243b293
Fixes Issue 25174: Goods shipment can be booked without product and quantity.
src-db/database/model/functions/M_INOUT_POST.xml
src-db/database/sourcedata/AD_COLUMN.xml
src-db/database/sourcedata/AD_MESSAGE.xml
src/org/openbravo/event/MInOutLineEventHandler.java
--- a/src-db/database/model/functions/M_INOUT_POST.xml	Thu Feb 13 17:23:11 2014 +0100
+++ b/src-db/database/model/functions/M_INOUT_POST.xml	Thu Jan 30 11:29:06 2014 +0530
@@ -68,6 +68,7 @@
     Cur_InOutLine RECORD;
     Cur_Order RECORD;
     Cur_OrderLine RECORD;
+    Cur_Lines RECORD;
     --
     v_Result NUMBER:=1;
     v_AD_Org_ID VARCHAR2(32);
@@ -179,13 +180,31 @@
           RAISE_APPLICATION_ERROR(-20000, '@NotCorrectOrgBpartnerInout@') ;
         END IF;
       END IF;
-
+       Declare
+       v_Message_product VARCHAR(2000) :='';
+       Begin
+          FOR Cur_Lines IN (
+                             SELECT M.line
+                             FROM M_InOut I,
+                                  M_InOutLine M
+                             WHERE I.M_InOut_ID=M.M_InOut_ID
+                               AND I.M_INOUT_ID=v_Record_ID
+                               AND (M.M_PRODUCT_ID IS NULL AND M.MOVEMENTQTY <> 0)
+                               ORDER BY M.line
+                            ) LOOP
+               v_Message_product:=v_Message_product||Cur_Lines.line||', ';
+          END LOOP;
+          if v_Message_product != '' then
+             RAISE_APPLICATION_ERROR(-20000, '@Inline@ '||v_Message_product||' '||'@ProductNullAndMovementQtyGreaterZero@') ;
+          end if ;
+	     End ;
       if(v_isreturndoctype = 'N' AND v_isSoTrx = 'Y' and v_DocAction<>'RC') then
         v_message := null;
         for Cur_OrderLine in (
           select c_orderline_id, line
           from m_inoutline
           where m_inout_id = v_Record_ID
+          and c_orderline_id is not null
           order by line
         ) loop
           select COALESCE(sum(movementqty), 0)
--- a/src-db/database/sourcedata/AD_COLUMN.xml	Thu Feb 13 17:23:11 2014 +0100
+++ b/src-db/database/sourcedata/AD_COLUMN.xml	Thu Jan 30 11:29:06 2014 +0530
@@ -56553,7 +56553,7 @@
 <!--3540-->  <AD_TABLE_ID><![CDATA[320]]></AD_TABLE_ID>
 <!--3540-->  <AD_REFERENCE_ID><![CDATA[29]]></AD_REFERENCE_ID>
 <!--3540-->  <FIELDLENGTH><![CDATA[10]]></FIELDLENGTH>
-<!--3540-->  <DEFAULTVALUE><![CDATA[1]]></DEFAULTVALUE>
+<!--3540-->  <DEFAULTVALUE><![CDATA[0]]></DEFAULTVALUE>
 <!--3540-->  <ISKEY><![CDATA[N]]></ISKEY>
 <!--3540-->  <ISPARENT><![CDATA[N]]></ISPARENT>
 <!--3540-->  <ISMANDATORY><![CDATA[Y]]></ISMANDATORY>
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Feb 13 17:23:11 2014 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Thu Jan 30 11:29:06 2014 +0530
@@ -24858,6 +24858,18 @@
 <!--F38A8843E6504699A91571A79C3AA3DF-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--F38A8843E6504699A91571A79C3AA3DF--></AD_MESSAGE>
 
+<!--F3D93965FE2A4900A9F4358458D5C065--><AD_MESSAGE>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <AD_MESSAGE_ID><![CDATA[F3D93965FE2A4900A9F4358458D5C065]]></AD_MESSAGE_ID>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <VALUE><![CDATA[ProductNullAndMovementQtyGreaterZero]]></VALUE>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <MSGTEXT><![CDATA[When Product is blank then Movement Quantity must be zero.]]></MSGTEXT>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--F3D93965FE2A4900A9F4358458D5C065-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--F3D93965FE2A4900A9F4358458D5C065--></AD_MESSAGE>
+
 <!--F4944007131447B6ADF3903564B478E6--><AD_MESSAGE>
 <!--F4944007131447B6ADF3903564B478E6-->  <AD_MESSAGE_ID><![CDATA[F4944007131447B6ADF3903564B478E6]]></AD_MESSAGE_ID>
 <!--F4944007131447B6ADF3903564B478E6-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src/org/openbravo/event/MInOutLineEventHandler.java	Thu Feb 13 17:23:11 2014 +0100
+++ b/src/org/openbravo/event/MInOutLineEventHandler.java	Thu Jan 30 11:29:06 2014 +0530
@@ -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) 2013 Openbravo SLU
+ * All portions are Copyright (C) 2013-2014 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  *************************************************************************
@@ -22,14 +22,18 @@
 
 import org.apache.log4j.Logger;
 import org.hibernate.criterion.Restrictions;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.client.kernel.event.EntityDeleteEvent;
+import org.openbravo.client.kernel.event.EntityNewEvent;
 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.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
 import org.openbravo.model.materialmgmt.transaction.ShipmentInOutLine;
 import org.openbravo.service.db.DalConnectionProvider;
@@ -44,6 +48,27 @@
     return entities;
   }
 
+  public void onSave(@Observes EntityNewEvent event) {
+    if (!isValidEvent(event)) {
+      return;
+    }
+    ShipmentInOutLine shipmentInOutLine = (ShipmentInOutLine) event.getTargetInstance();
+
+    if (shipmentInOutLine.getProduct() == null &&  (shipmentInOutLine.getMovementQuantity().doubleValue() != 0) ){
+          throw new OBException(OBMessageUtils.messageBD("ProductNullAndMovementQtyGreaterZero"));
+    }
+ }
+
+  public void onUpdate(@Observes EntityUpdateEvent event) {
+    if (!isValidEvent(event)) {
+      return;
+    }
+    ShipmentInOutLine shipmentInOutLine = (ShipmentInOutLine) event.getTargetInstance();
+
+    if (shipmentInOutLine.getProduct()== null && (shipmentInOutLine.getMovementQuantity().doubleValue() != 0)){
+        throw new OBException(OBMessageUtils.messageBD("ProductNullAndMovementQtyGreaterZero"));
+     }
+}
   public void onDelete(@Observes EntityDeleteEvent event) {
     if (!isValidEvent(event)) {
       return;