[calendar] Merge from pi
authorDavid Baz Fayos <david.baz@openbravo.com>
Tue, 29 Jan 2013 19:27:44 +0100
changeset 19521 d0a11fe5293e
parent 19520 7c03514582ee (current diff)
parent 19503 af634aae179d (diff)
child 19522 d0dbfd0f4d02
[calendar] Merge from pi
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Jan 29 19:27:44 2013 +0100
@@ -540,6 +540,17 @@
 <!--8E01FDCFBE034863898A47F1AE37BB15-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--8E01FDCFBE034863898A47F1AE37BB15--></AD_MESSAGE>
 
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F--><AD_MESSAGE>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <AD_MESSAGE_ID><![CDATA[8EF25E4AD4EF46E4BCE4E0FACAFC717F]]></AD_MESSAGE_ID>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <VALUE><![CDATA[APRM_BankStatementLineWrongDateWarning]]></VALUE>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <MSGTEXT><![CDATA[Bank statement line with wrong date. Cannot process lines previous to ]]></MSGTEXT>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <MSGTYPE><![CDATA[W]]></MSGTYPE>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--8EF25E4AD4EF46E4BCE4E0FACAFC717F--></AD_MESSAGE>
+
 <!--92EC1935A8B947BA83EF82DBD169CA8B--><AD_MESSAGE>
 <!--92EC1935A8B947BA83EF82DBD169CA8B-->  <AD_MESSAGE_ID><![CDATA[92EC1935A8B947BA83EF82DBD169CA8B]]></AD_MESSAGE_ID>
 <!--92EC1935A8B947BA83EF82DBD169CA8B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -804,6 +815,17 @@
 <!--C5133F7FD55D4AF6B8B7FB527BFB9920-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
 <!--C5133F7FD55D4AF6B8B7FB527BFB9920--></AD_MESSAGE>
 
+<!--CAB70EC8598D40E0BFFD7F0FB8538080--><AD_MESSAGE>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <AD_MESSAGE_ID><![CDATA[CAB70EC8598D40E0BFFD7F0FB8538080]]></AD_MESSAGE_ID>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <VALUE><![CDATA[APRM_BankStatementLineWrongDateWarning2]]></VALUE>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <MSGTEXT><![CDATA[Check the lines with Line No.:]]></MSGTEXT>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <MSGTYPE><![CDATA[W]]></MSGTYPE>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--CAB70EC8598D40E0BFFD7F0FB8538080--></AD_MESSAGE>
+
 <!--CCA38D3048F04C1FA6F05AD56CF81B5D--><AD_MESSAGE>
 <!--CCA38D3048F04C1FA6F05AD56CF81B5D-->  <AD_MESSAGE_ID><![CDATA[CCA38D3048F04C1FA6F05AD56CF81B5D]]></AD_MESSAGE_ID>
 <!--CCA38D3048F04C1FA6F05AD56CF81B5D-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_BankStatementProcess.java	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_BankStatementProcess.java	Tue Jan 29 19:27:44 2013 +0100
@@ -54,22 +54,30 @@
         if (maxBSLDate != null) {
           for (FIN_BankStatementLine bsl : bankStatement.getFINBankStatementLineList()) {
             if (bsl.getTransactionDate().compareTo(maxBSLDate) <= 0) {
-              msg.setType("Error");
-              msg.setTitle(FIN_Utility.messageBD("Error"));
-              String pattern = OBPropertiesProvider.getInstance().getOpenbravoProperties()
-                  .getProperty("dateFormat.java");
-              msg.setMessage(FIN_Utility.messageBD("APRM_BankStatementLineWrongDate")
-                  + Utility.formatDate(maxBSLDate, pattern));
-              bundle.setResult(msg);
-              return;
+              if (!msg.getMessage().equals("")) {
+                msg.setMessage(msg.getMessage() + ", " + bsl.getLineNo());
+              } else {
+                msg.setType("Warning");
+                msg.setTitle(FIN_Utility.messageBD("Warning"));
+                String pattern = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+                    .getProperty("dateFormat.java");
+                msg.setMessage(msg.getMessage()
+                    + FIN_Utility.messageBD("APRM_BankStatementLineWrongDateWarning")
+                    + Utility.formatDate(maxBSLDate, pattern) + ". "
+                    + FIN_Utility.messageBD("APRM_BankStatementLineWrongDateWarning2") + " "
+                    + bsl.getLineNo());
+              }
             }
           }
         }
 
-        bankStatement.setProcessed(true);
-        bankStatement.setAPRMProcessBankStatement("R");
-        OBDal.getInstance().save(bankStatement);
-        OBDal.getInstance().flush();
+        if (msg.getType() != null && !msg.getType().toLowerCase().equals("warning")) {
+          // Success
+          bankStatement.setProcessed(true);
+          bankStatement.setAPRMProcessBankStatement("R");
+          OBDal.getInstance().save(bankStatement);
+          OBDal.getInstance().flush();
+        }
       } else if (strAction.equals("R")) {
         // *************************
         // Reactivate Bank Statement
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_BankStatementImport.java	Tue Jan 29 19:27:44 2013 +0100
@@ -175,7 +175,8 @@
       OBDal.getInstance().rollbackAndClose();
       return getMyError();
     }
-    if (getMyError() != null && !getMyError().getType().toLowerCase().equals("success")) {
+    if (getMyError() != null && !getMyError().getType().toLowerCase().equals("success")
+        && !getMyError().getType().toLowerCase().equals("warning")) {
       OBDal.getInstance().rollbackAndClose();
       return getMyError();
     } else if (getMyError() != null && getMyError().getType().toLowerCase().equals("success")) {
@@ -190,6 +191,8 @@
         setMyError(msg);
       }
       return getMyError();
+    } else if (getMyError() != null && getMyError().getType().toLowerCase().equals("warning")) {
+      return getMyError();
     } else {
       return getOBError(conn, vars, "@APRM_BankStatementNo@ " + bankStatement.getDocumentNo()
           + "<br/>" + numberOfLines + " " + "@RowsInserted@", "Success", "Success");
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js	Tue Jan 29 19:27:44 2013 +0100
@@ -52,7 +52,7 @@
   gridFields: [{
     name: 'alertRule',
     title: OB.I18N.getLabel('OBUIAPP_AlertGrid_AlertRule'),
-    displayField: 'alertRule' + OB.Constants.FIELDSEPARATOR + OB.Constants.IDENTIFIER,
+    displayField: OB.Constants.IDENTIFIER,
     canFilter: true,
     canEdit: false,
     filterOnKeypress: true,
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-parameter-window-view.js	Tue Jan 29 19:27:44 2013 +0100
@@ -374,14 +374,14 @@
       allProperties._allRows = [];
 
       for (i = 0; i < len; i++) {
-        tmp = isc.addProperties({}, selection[i], grid.getEditedRecord(i));
+        tmp = isc.addProperties({}, selection[i], grid.getEditedRecord(grid.getRecordIndex(selection[i])));
         allProperties._selection.push(tmp);
       }
 
       len = (allRows && allRows.length) || 0;
 
       for (i = 0; i < len; i++) {
-        tmp = isc.addProperties({}, allRows[i], grid.getEditedRecord(i));
+        tmp = isc.addProperties({}, allRows[i], grid.getEditedRecord(grid.getRecordIndex(allRows[i])));
         allProperties._allRows.push(tmp);
       }
     }
--- a/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.financial.paymentreport/src/org/openbravo/financial/paymentreport/erpCommon/ad_reports/PaymentReportDao.java	Tue Jan 29 19:27:44 2013 +0100
@@ -636,14 +636,16 @@
               .getPaymentDetails().getFinPayment().getPaymentMethod().getIdentifier());
 
           // payment
-          FieldProviderFactory.setField(
-              data[i],
-              "PAYMENT",
-              dateFormat.format(FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
-                  .getPaymentDate())
-                  + " - "
-                  + FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
-                      .getDocumentNo());
+          FieldProviderFactory
+              .setField(
+                  data[i],
+                  "PAYMENT",
+                  ((FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
+                      .getPaymentDate() != null) ? dateFormat.format(FIN_PaymentScheduleDetail[i]
+                      .getPaymentDetails().getFinPayment().getPaymentDate()) : "Null")
+                      + " - "
+                      + FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
+                          .getDocumentNo());
           // payment description
           FieldProviderFactory.setField(data[i], "PAYMENT_DESC", FIN_PaymentScheduleDetail[i]
               .getPaymentDetails().getFinPayment().getDescription());
@@ -651,11 +653,13 @@
           FieldProviderFactory.setField(data[i], "PAYMENT_ID", FIN_PaymentScheduleDetail[i]
               .getPaymentDetails().getFinPayment().getId().toString());
           // payment_date
-          FieldProviderFactory.setField(
-              data[i],
-              "PAYMENT_DATE",
-              dateFormat.format(FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
-                  .getPaymentDate()));
+          FieldProviderFactory
+              .setField(
+                  data[i],
+                  "PAYMENT_DATE",
+                  (FIN_PaymentScheduleDetail[i].getPaymentDetails().getFinPayment()
+                      .getPaymentDate() != null) ? dateFormat.format(FIN_PaymentScheduleDetail[i]
+                      .getPaymentDetails().getFinPayment().getPaymentDate()) : "Null");
           // payment_docNo
           FieldProviderFactory.setField(data[i], "PAYMENT_DOCNO", FIN_PaymentScheduleDetail[i]
               .getPaymentDetails().getFinPayment().getDocumentNo());
@@ -1843,8 +1847,9 @@
     FieldProviderFactory.setField(data, "PLANNED_DSO", String.valueOf(plannedDSO));
     // currentDSO
     if (fIN_PaymentScheduleDetail.getPaymentDetails() != null) {
-      currentDSO = (fIN_PaymentScheduleDetail.getPaymentDetails().getFinPayment().getPaymentDate()
-          .getTime() - invoicedDate.getTime())
+      currentDSO = (((fIN_PaymentScheduleDetail.getPaymentDetails().getFinPayment()
+          .getPaymentDate() != null) ? fIN_PaymentScheduleDetail.getPaymentDetails()
+          .getFinPayment().getPaymentDate().getTime() : 0) - invoicedDate.getTime())
           / milisecDayConv;
     } else {
       currentTime = System.currentTimeMillis();
--- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorComponentProvider.java	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorComponentProvider.java	Tue Jan 29 19:27:44 2013 +0100
@@ -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) 2009-2012 Openbravo SLU 
+ * All portions are Copyright (C) 2009-2013 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -73,6 +73,10 @@
         "web/org.openbravo.userinterface.smartclient/openbravo/skins/"
             + KernelConstants.SKIN_PARAMETER
             + "/org.openbravo.userinterface.selector/ob-selector-item-styles.js", false, true));
+    resources.add(createStyleSheetResource(
+        "web/org.openbravo.userinterface.smartclient/openbravo/skins/"
+            + KernelConstants.SKIN_PARAMETER
+            + "/org.openbravo.userinterface.selector/ob-selector-item-styles.css", false, true));
 
     resources.add(createStyleSheetResource(
         "web/org.openbravo.userinterface.smartclient/openbravo/skins/"
--- a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-multi-selector-item.js	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.selector/js/ob-multi-selector-item.js	Tue Jan 29 19:27:44 2013 +0100
@@ -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) 2012 Openbravo SLU
+ * All portions are Copyright (C) 2012-2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -198,9 +198,9 @@
     this.storeValue(currentValue);
 
     // display it in the layout
-    selectedElement = isc.Label.create({
+    selectedElement = isc.OBMultiSelectorItemLabel.create({
       contents: record[OB.Constants.IDENTIFIER],
-      icon: OB.Styles.skinsPath + 'Default/org.openbravo.client.application/images/form/clearField.png',
+      icon: me.buttonDefaults.icon,
       height: 1,
       width: '90%',
       // Setting width to reserve some space for vertical scrollbar
@@ -259,6 +259,11 @@
 });
 
 
+// = OBMultiSelectorItemLabel =
+// OBMultiSelectorItemLabel is used for selected element label
+isc.ClassFactory.defineClass('OBMultiSelectorItemLabel', isc.Label);
+
+
 // = OBMultiSelectorSelectorLayout =
 // Utility layout to display selected records in a OBMultiSelectorItem
 isc.ClassFactory.defineClass('OBMultiSelectorSelectorLayout', isc.VStack);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.userinterface.selector/ob-selector-item-styles.css	Tue Jan 29 19:27:44 2013 +0100
@@ -0,0 +1,30 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * 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 Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+*/
+
+.OBMultiSelectorItemLabel,
+.OBMultiSelectorItemLabelDisabled {
+  font-family: arial, sans-serif;
+  font-size: 12px;
+  padding: 2px 2px 0px 2px;
+}
+
+.OBMultiSelectorItemLabel img,
+.OBMultiSelectorItemLabelDisabled img {
+  cursor: pointer;
+}
\ No newline at end of file
--- a/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.userinterface.selector/ob-selector-item-styles.js	Tue Jan 29 12:09:42 2013 +0100
+++ b/modules/org.openbravo.userinterface.selector/web/org.openbravo.userinterface.smartclient/openbravo/skins/Default/org.openbravo.userinterface.selector/ob-selector-item-styles.js	Tue Jan 29 19:27:44 2013 +0100
@@ -109,6 +109,10 @@
   }
 });
 
+isc.OBMultiSelectorItemLabel.addProperties({
+  styleName: 'OBMultiSelectorItemLabel'
+});
+
 isc.OBMultiSelectorSelectorLayout.addProperties({
   styleName: 'OBFormFieldInput'
 });
\ No newline at end of file
--- a/src-db/database/model/functions/C_INVOICE_POST.xml	Tue Jan 29 12:09:42 2013 +0100
+++ b/src-db/database/model/functions/C_INVOICE_POST.xml	Tue Jan 29 19:27:44 2013 +0100
@@ -1359,7 +1359,7 @@
            CHARGEAMT, C_UOM_ID, C_TAX_ID, S_RESOURCEASSIGNMENT_ID,
            TAXAMT, M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION,
            QUANTITYORDER, M_PRODUCT_UOM_ID, PRICESTD,
-           GROSS_UNIT_PRICE, LINE_GROSS_AMOUNT,
+           GROSS_UNIT_PRICE, TAXBASEAMT, LINE_GROSS_AMOUNT,
            ISDEFERRED, DEFPLANTYPE, PERIODNUMBER, C_PERIOD_ID
           )
           VALUES
@@ -1372,7 +1372,7 @@
            0, Cur_CInvoiceDiscount.C_UOM_ID, Cur_TaxDiscount.C_TAX_ID, NULL,
            NULL, NULL, 'N' ,
            NULL, NULL, v_Discount,
-           ROUND(v_gross_unit_price, v_precision), ROUND(v_line_gross_amount, v_precision),
+           ROUND(v_gross_unit_price, v_precision), v_Discount  ,ROUND(v_line_gross_amount, v_precision),
            v_isdeferred_inv, v_defplantype_inv, v_periodnumber_inv, v_period_inv
           );
         --v_InvoiceDiscount:=Ad_Sequence_Nextno('C_InvoiceLine');
--- a/src-db/database/model/functions/M_INOUT_CREATE.xml	Tue Jan 29 12:09:42 2013 +0100
+++ b/src-db/database/model/functions/M_INOUT_CREATE.xml	Tue Jan 29 19:27:44 2013 +0100
@@ -66,6 +66,7 @@
   v_MessageBPB VARCHAR2(2000):='';
   result_String VARCHAR2(2000):='';
   v_ResultLinesStr VARCHAR2(2000):='';
+  v_stdPrecision NUMBER:=2;
   -- Parameter
   TYPE RECORD IS REF CURSOR;
     Cur_Parameter RECORD;
@@ -397,14 +398,15 @@
             --MODIFIED BY F.IRIAZABAL
             v_QtyOrder:=0;
             IF (ol.M_Product_UOM_ID IS NOT NULL) THEN
-              SELECT M_PRODUCT_UOM.C_UOM_ID INTO v_ProductUOM
+              SELECT M_PRODUCT_UOM.C_UOM_ID, C_UOM.stdprecision
+              INTO v_ProductUOM, v_stdPrecision
               FROM M_PRODUCT_UOM, C_UOM
               WHERE M_PRODUCT_UOM.C_UOM_ID=C_UOM.C_UOM_ID
                 AND M_Product_UOM_ID=ol.M_Product_UOM_ID;
               IF (ol.QtyDelivered = 0) THEN
                 v_QtyOrder:=ol.QuantityOrder;
               ELSIF (v_ProductUOM IS NOT NULL) THEN
-                v_QtyOrder:=ol.QuantityOrder*v_Qty/ol.QtyOrdered;
+                v_QtyOrder:=ROUND(ol.QuantityOrder*v_Qty/ol.QtyOrdered,v_stdPrecision);
                 --v_QtyOrder:=C_Uom_Convert(v_Qty, ol.C_UOM_ID, v_ProductUOM, 'Y') ;
               ELSE
                 v_QtyOrder:=NULL;
--- a/src-db/database/model/functions/M_MOVEMENT_POST.xml	Tue Jan 29 12:09:42 2013 +0100
+++ b/src-db/database/model/functions/M_MOVEMENT_POST.xml	Tue Jan 29 19:27:44 2013 +0100
@@ -160,8 +160,7 @@
           RAISE_APPLICATION_ERROR(-20000, '@PeriodNotAvailable@');
         END IF;
       END IF;
-          
-      
+
       v_ResultStr:='LockingMovement';
       UPDATE M_Movement  SET Processing='Y',Updated=now(),UpdatedBy=v_p_User  WHERE M_Movement_ID=v_Record_ID;
       -- Commented by cromero 19102006 COMMIT;
@@ -177,7 +176,12 @@
         LOOP
           v_ResultStr:='Transaction for line' || Cur_MoveLine.Line;
           -- FROM
-          AD_Sequence_Next('M_Transaction', v_Client_ID, NextNo) ;
+          AD_Sequence_Next('M_Transaction', v_Client_ID, NextNo);
+
+          IF (Cur_MoveLine.MovementQty = 0) THEN
+             RAISE_APPLICATION_ERROR(-20000,'@GoodsMovementsWithZeroQty@' || ' @Inline@ ' || Cur_MoveLine.line) ;
+          END IF;
+
           INSERT
           INTO M_Transaction
             (
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Jan 29 12:09:42 2013 +0100
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Tue Jan 29 19:27:44 2013 +0100
@@ -15411,6 +15411,17 @@
 <!--1E0F1799B5F144778669B2D23FD9BA9E-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--1E0F1799B5F144778669B2D23FD9BA9E--></AD_MESSAGE>
 
+<!--1E33F2F8858B48D79F845F72CD828861--><AD_MESSAGE>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <AD_MESSAGE_ID><![CDATA[1E33F2F8858B48D79F845F72CD828861]]></AD_MESSAGE_ID>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <VALUE><![CDATA[GoodsMovementsWithZeroQty]]></VALUE>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <MSGTEXT><![CDATA[Is is not possible to process because one line has value zero in movement quantity. Please insert a different value from zero.]]></MSGTEXT>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--1E33F2F8858B48D79F845F72CD828861-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--1E33F2F8858B48D79F845F72CD828861--></AD_MESSAGE>
+
 <!--1E4DFEDC675F4BD8AFA6A8D707D77FFF--><AD_MESSAGE>
 <!--1E4DFEDC675F4BD8AFA6A8D707D77FFF-->  <AD_MESSAGE_ID><![CDATA[1E4DFEDC675F4BD8AFA6A8D707D77FFF]]></AD_MESSAGE_ID>
 <!--1E4DFEDC675F4BD8AFA6A8D707D77FFF-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_TAB.xml	Tue Jan 29 12:09:42 2013 +0100
+++ b/src-db/database/sourcedata/AD_TAB.xml	Tue Jan 29 19:27:44 2013 +0100
@@ -12143,7 +12143,7 @@
 <!--1B49A74CF8314D02B7F41B6595A169D4-->  <SEQNO><![CDATA[40]]></SEQNO>
 <!--1B49A74CF8314D02B7F41B6595A169D4-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--1B49A74CF8314D02B7F41B6595A169D4-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--1B49A74CF8314D02B7F41B6595A169D4-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--1B49A74CF8314D02B7F41B6595A169D4-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--1B49A74CF8314D02B7F41B6595A169D4-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--1B49A74CF8314D02B7F41B6595A169D4-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--1B49A74CF8314D02B7F41B6595A169D4-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -12201,7 +12201,7 @@
 <!--21587C5E538E48758ED0C59B621DA91B-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--21587C5E538E48758ED0C59B621DA91B-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--21587C5E538E48758ED0C59B621DA91B-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--21587C5E538E48758ED0C59B621DA91B-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--21587C5E538E48758ED0C59B621DA91B-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--21587C5E538E48758ED0C59B621DA91B-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--21587C5E538E48758ED0C59B621DA91B-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--21587C5E538E48758ED0C59B621DA91B-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -12610,7 +12610,7 @@
 <!--38A56E62067242B39D3815E434D5BC48-->  <SEQNO><![CDATA[60]]></SEQNO>
 <!--38A56E62067242B39D3815E434D5BC48-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--38A56E62067242B39D3815E434D5BC48-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--38A56E62067242B39D3815E434D5BC48-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--38A56E62067242B39D3815E434D5BC48-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--38A56E62067242B39D3815E434D5BC48-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--38A56E62067242B39D3815E434D5BC48-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--38A56E62067242B39D3815E434D5BC48-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -13552,7 +13552,7 @@
 <!--6EE02C9681A74406A129F1D96D022BA4-->  <SEQNO><![CDATA[45]]></SEQNO>
 <!--6EE02C9681A74406A129F1D96D022BA4-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--6EE02C9681A74406A129F1D96D022BA4-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--6EE02C9681A74406A129F1D96D022BA4-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--6EE02C9681A74406A129F1D96D022BA4-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--6EE02C9681A74406A129F1D96D022BA4-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--6EE02C9681A74406A129F1D96D022BA4-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--6EE02C9681A74406A129F1D96D022BA4-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -13642,7 +13642,7 @@
 <!--7309F57E84264F6BB8F2A5E4A976ED93-->  <SEQNO><![CDATA[60]]></SEQNO>
 <!--7309F57E84264F6BB8F2A5E4A976ED93-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--7309F57E84264F6BB8F2A5E4A976ED93-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--7309F57E84264F6BB8F2A5E4A976ED93-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--7309F57E84264F6BB8F2A5E4A976ED93-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--7309F57E84264F6BB8F2A5E4A976ED93-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--7309F57E84264F6BB8F2A5E4A976ED93-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--7309F57E84264F6BB8F2A5E4A976ED93-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -14084,7 +14084,7 @@
 <!--89F074E609E841A7ACD0D4A19B6AF476-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--89F074E609E841A7ACD0D4A19B6AF476-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--89F074E609E841A7ACD0D4A19B6AF476-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--89F074E609E841A7ACD0D4A19B6AF476-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--89F074E609E841A7ACD0D4A19B6AF476-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--89F074E609E841A7ACD0D4A19B6AF476-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--89F074E609E841A7ACD0D4A19B6AF476-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--89F074E609E841A7ACD0D4A19B6AF476-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -14232,7 +14232,7 @@
 <!--93787F9E92BD433EA7FD0E61227BC126-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--93787F9E92BD433EA7FD0E61227BC126-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--93787F9E92BD433EA7FD0E61227BC126-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--93787F9E92BD433EA7FD0E61227BC126-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--93787F9E92BD433EA7FD0E61227BC126-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--93787F9E92BD433EA7FD0E61227BC126-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--93787F9E92BD433EA7FD0E61227BC126-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--93787F9E92BD433EA7FD0E61227BC126-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -14369,7 +14369,7 @@
 <!--A399D7976DD74832A0D56586E46D149A-->  <SEQNO><![CDATA[70]]></SEQNO>
 <!--A399D7976DD74832A0D56586E46D149A-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--A399D7976DD74832A0D56586E46D149A-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--A399D7976DD74832A0D56586E46D149A-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--A399D7976DD74832A0D56586E46D149A-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--A399D7976DD74832A0D56586E46D149A-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--A399D7976DD74832A0D56586E46D149A-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--A399D7976DD74832A0D56586E46D149A-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -14897,7 +14897,7 @@
 <!--B67386FF3EA94579BA9BA22353B5B897-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--B67386FF3EA94579BA9BA22353B5B897-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--B67386FF3EA94579BA9BA22353B5B897-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--B67386FF3EA94579BA9BA22353B5B897-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--B67386FF3EA94579BA9BA22353B5B897-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--B67386FF3EA94579BA9BA22353B5B897-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--B67386FF3EA94579BA9BA22353B5B897-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--B67386FF3EA94579BA9BA22353B5B897-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -15103,7 +15103,7 @@
 <!--C68533256F40484C89006BF00F669CD5-->  <SEQNO><![CDATA[30]]></SEQNO>
 <!--C68533256F40484C89006BF00F669CD5-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--C68533256F40484C89006BF00F669CD5-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--C68533256F40484C89006BF00F669CD5-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--C68533256F40484C89006BF00F669CD5-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--C68533256F40484C89006BF00F669CD5-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--C68533256F40484C89006BF00F669CD5-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--C68533256F40484C89006BF00F669CD5-->  <HASTREE><![CDATA[N]]></HASTREE>
@@ -15422,7 +15422,7 @@
 <!--D7B93F8414E643DD8C1103D6FEF0B568-->  <SEQNO><![CDATA[40]]></SEQNO>
 <!--D7B93F8414E643DD8C1103D6FEF0B568-->  <TABLEVEL><![CDATA[1]]></TABLEVEL>
 <!--D7B93F8414E643DD8C1103D6FEF0B568-->  <ISSINGLEROW><![CDATA[N]]></ISSINGLEROW>
-<!--D7B93F8414E643DD8C1103D6FEF0B568-->  <ISINFOTAB><![CDATA[N]]></ISINFOTAB>
+<!--D7B93F8414E643DD8C1103D6FEF0B568-->  <ISINFOTAB><![CDATA[Y]]></ISINFOTAB>
 <!--D7B93F8414E643DD8C1103D6FEF0B568-->  <ISTRANSLATIONTAB><![CDATA[N]]></ISTRANSLATIONTAB>
 <!--D7B93F8414E643DD8C1103D6FEF0B568-->  <ISREADONLY><![CDATA[N]]></ISREADONLY>
 <!--D7B93F8414E643DD8C1103D6FEF0B568-->  <HASTREE><![CDATA[N]]></HASTREE>
--- a/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Tue Jan 29 12:09:42 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_actionButton/CreateFrom_Invoice_data.xsql	Tue Jan 29 19:27:44 2013 +0100
@@ -404,15 +404,8 @@
       <![CDATA[
         SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME,
         s.DocumentNo AS NAMESHIPMENT,
-        (l.MovementQty - COALESCE((select sum(COALESCE(il.qtyinvoiced, 0))
-                         from m_inoutline iol
-                           left join c_invoiceline il on iol.m_inoutline_id = il.m_inoutline_id
-                           left join c_invoice i on il.c_invoice_id = i.c_invoice_id 
-                         where iol.m_inoutline_id = l.m_inoutline_id
-                           and i.docstatus = 'CO'
-                         group by iol.m_inoutline_id, iol.movementqty
-                         having (iol.movementqty >= 0 AND iol.movementqty > SUM(COALESCE(il.qtyinvoiced, 0)))
-                                 OR (iol.movementqty < 0 AND iol.movementqty < SUM(COALESCE(il.qtyinvoiced, 0))) ), 0)) AS QTY, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?))||' '||(CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('') END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line,
+        (l.MovementQty - sum(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) AS QTY, l.C_UOM_ID,uom.UOMSymbol,
+        l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?))||' '||(CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('') END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line,
         l.M_InOutLine_ID as C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
@@ -421,7 +414,9 @@
                 left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
                 left join c_orderline ol on l.c_orderline_id = ol.c_orderline_id
                 left join c_order o on ol.c_order_id = o.c_order_id
-                left join m_pricelist pl on pl.m_pricelist_id = o.m_pricelist_id,
+                left join m_pricelist pl on pl.m_pricelist_id = o.m_pricelist_id
+                left join c_invoiceline il on l.m_inoutline_id = il.m_inoutline_id
+                left join c_invoice i on il.c_invoice_id = i.c_invoice_id,
         M_INOUT s, C_UOM uom, M_PRODUCT p 
         WHERE s.M_INOUT_ID = l.M_INOUT_ID
         AND s.IsSOTrx='Y' 
@@ -430,20 +425,14 @@
         AND s.AD_Org_ID IN ('1') 
         AND l.C_UOM_ID=uom.C_UOM_ID 
         AND l.M_Product_ID=p.M_Product_ID 
-        AND EXISTS (select 1
-                    from m_inoutline iol
-                      left join c_invoiceline il on iol.m_inoutline_id = il.m_inoutline_id
-                      left join c_invoice i on il.c_invoice_id = i.c_invoice_id 
-                    where iol.m_inoutline_id = l.m_inoutline_id
-                    group by iol.m_inoutline_id, iol.movementqty
-                    having (iol.movementqty >= 0 AND iol.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
-                            OR (iol.movementqty < 0 AND iol.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) )
         AND l.M_InOut_ID=?
         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,
         l.M_Product_ID,p.NAME, ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
         COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID)
+        HAVING (l.movementqty >= 0 AND l.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
+           OR (l.movementqty < 0 AND l.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
         ORDER BY NAME, l.Line
       ]]>
     </Sql>
@@ -454,7 +443,7 @@
     <Parameter name="adOrgClient" type="replace" optional="true" after="s.AD_Org_ID IN (" text="'1'"/>
     <Parameter name="mInoutId"/>
     <Parameter name="isTaxIncluded"/>
-  </SqlMethod>  
+  </SqlMethod>
   <SqlMethod name="selectFromShipmentSOTrxCombo" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
     <Sql>
@@ -471,17 +460,14 @@
                            left join c_orderline ol on l.c_orderline_id = ol.c_orderline_id
                            left join c_order o on ol.c_order_id = o.c_order_id
                            left join m_pricelist pl on pl.m_pricelist_id = o.m_pricelist_id
+                           left join c_invoiceline il on l.m_inoutline_id = il.m_inoutline_id
+                           left join c_invoice i on il.c_invoice_id = i.c_invoice_id
                     WHERE l.M_INOUT_ID = s.M_INOUT_ID
                     AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
-                    AND EXISTS (SELECT 1
-                                FROM m_inoutline iol
-                                  left join c_invoiceline il ON iol.m_inoutline_id = il.m_inoutline_id
-                                  left join c_invoice i ON il.c_invoice_id = i.c_invoice_id
-                                WHERE  iol.m_inoutline_id = l.m_inoutline_id 
-                                GROUP  BY iol.m_inoutline_id, iol.movementqty
-                                HAVING (iol.movementqty >= 0 AND iol.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
-                                        OR (iol.movementqty < 0 AND iol.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) )
-                        )
+                    GROUP BY l.m_inoutline_id, l.movementqty
+                    HAVING ( l.movementqty >= 0 AND l.movementqty > Sum(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)) )
+                      OR ( l.movementqty < 0 AND l.movementqty < Sum(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)) )
+                    )
         AND NOT EXISTS (SELECT 1 FROM C_INVOICE_CANDIDATE_V ic, C_ORDER o 
         WHERE o.C_ORDER_ID = s.C_ORDER_ID
         AND o.C_ORDER_ID = ic.C_ORDER_ID
@@ -501,7 +487,6 @@
     <Parameter name="cBpartnerId"/>
     <Parameter name="isTaxIncluded"/>
   </SqlMethod>
-  
   <SqlMethod name="selectFromShipmentTrl" type="preparedStatement" return="multiple">
     <SqlMethodComment></SqlMethodComment>
     <Sql>
@@ -554,15 +539,7 @@
       <![CDATA[
         SELECT s.M_InOut_ID AS ID, Ad_Column_Identifier(to_char('M_InOut'), to_char(s.M_InOut_ID), to_char(?)) AS NAME,
         s.DocumentNo AS NAMESHIPMENT,
-        (l.MovementQty - COALESCE((SELECT SUM(COALESCE(il.qtyinvoiced, 0))
-                                  FROM m_inoutline iol
-                                    LEFT JOIN c_invoiceline il ON iol.m_inoutline_id = il.m_inoutline_id
-                                    LEFT JOIN c_invoice i ON il.c_invoice_id = i.c_invoice_id 
-                                  WHERE iol.m_inoutline_id = l.m_inoutline_id
-                                    AND i.docstatus = 'CO'
-                                  GROUP BY iol.m_inoutline_id, iol.movementqty
-                                  HAVING (iol.movementqty >= 0 AND iol.movementqty > SUM(COALESCE(il.qtyinvoiced, 0)))
-                                          OR (iol.movementqty < 0 AND iol.movementqty < SUM(COALESCE(il.qtyinvoiced, 0))) ), 0)) AS QTY, l.C_UOM_ID,COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
+        (l.MovementQty - SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) AS QTY, l.C_UOM_ID,COALESCE(uomt.UOMSymbol, uom.UOMSymbol) AS UOMSymbol, 
         l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?))||' '|| (CASE WHEN ma.serno IS NOT NULL THEN TO_CHAR('('||' '||ma.serno||' '||')') ELSE TO_CHAR('')  END) AS RELATION_NAME, l.M_InOutLine_ID,l.Line, l.M_InOutLine_ID as C_OrderLine_ID, 
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
@@ -571,7 +548,9 @@
               left join M_ATTRIBUTESETINSTANCE ma on l.M_ATTRIBUTESETINSTANCE_ID = ma.M_ATTRIBUTESETINSTANCE_ID
               left join c_orderline ol on l.c_orderline_id = ol.c_orderline_id
               left join c_order o on ol.c_order_id = o.c_order_id
-              left join m_pricelist pl on pl.m_pricelist_id = o.m_pricelist_id,
+              left join m_pricelist pl on pl.m_pricelist_id = o.m_pricelist_id
+              left join c_invoiceline il on l.m_inoutline_id = il.m_inoutline_id
+              left join c_invoice i on il.c_invoice_id = i.c_invoice_id,
              C_UOM uom     left join C_UOM_TRL uomt            on uom.C_UOM_ID = uomt.C_UOM_ID
                                                               and uomt.AD_Language = ? ,
         M_INOUT s,    M_PRODUCT p 
@@ -582,20 +561,14 @@
         AND s.AD_Org_ID IN ('1') 
         AND l.C_UOM_ID=uom.C_UOM_ID 
         AND l.M_Product_ID=p.M_Product_ID 
-        AND EXISTS (SELECT 1
-                    FROM m_inoutline iol
-                      LEFT JOIN c_invoiceline il ON iol.m_inoutline_id = il.m_inoutline_id
-                      LEFT JOIN c_invoice i ON il.c_invoice_id = i.c_invoice_id 
-                    WHERE iol.m_inoutline_id = l.m_inoutline_id
-                    GROUP BY iol.m_inoutline_id, iol.movementqty
-                    HAVING (iol.movementqty >= 0 AND iol.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
-                            OR (iol.movementqty < 0 AND iol.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) )
         AND l.M_InOut_ID=? 
         AND (l.c_orderline_id is null OR pl.istaxincluded = ?)
         GROUP BY s.M_InOut_ID, s.DocumentNo, s.MovementDate, l.MovementQty,l.C_UOM_ID,uom.UOMSymbol, uomt.UOMSymbol,
         l.M_Product_ID,p.NAME,ma.serno, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
         COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID)
+        HAVING (l.movementqty >= 0 AND l.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
+          OR (l.movementqty < 0 AND l.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
         ORDER BY NAME, l.Line
       ]]>
     </Sql>
@@ -608,7 +581,6 @@
     <Parameter name="mInoutId"/>
     <Parameter name="isTaxIncluded"/>
   </SqlMethod>
-  
   <SqlMethod name="selectFromShipmentUpdate" type="preparedStatement" connection="true" return="multiple">
     <SqlMethodComment></SqlMethodComment>
     <Sql>
@@ -638,35 +610,25 @@
     <SqlMethodComment></SqlMethodComment>
     <Sql>
       <![CDATA[
-        SELECT (l.MovementQty - COALESCE((select sum(COALESCE(il.qtyinvoiced, 0))
-                                           from m_inoutline iol
-                                             left join c_invoiceline il on iol.m_inoutline_id = il.m_inoutline_id
-                                             left join c_invoice i on il.c_invoice_id = i.c_invoice_id 
-                                           where iol.m_inoutline_id = l.m_inoutline_id
-                                             and i.docstatus = 'CO'
-                                           group by iol.m_inoutline_id, iol.movementqty
-                                           having (iol.movementqty >= 0 AND (iol.movementqty > SUM(COALESCE(il.qtyinvoiced, 0)))
-                                                   OR (iol.movementqty < SUM(COALESCE(il.qtyinvoiced, 0))) )), 0)) AS ID, l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, l.M_InOutLine_ID,l.Line,
+        SELECT (l.MovementQty - sum(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) AS ID,
+        l.C_UOM_ID,uom.UOMSymbol, l.M_Product_ID,Ad_Column_Identifier(to_char('M_Product'), to_char(l.m_product_id), to_char(?)) AS NAME, l.M_InOutLine_ID,l.Line,
         l.C_OrderLine_ID, max(uom.STDPRECISION) as stdprecision, l.Description,l.quantityOrder, l.M_Product_UOM_ID,
         l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID) AS A_Asset_ID, COALESCE(l.C_Project_ID, s.C_Project_ID) AS C_Project_ID, 
         COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID) AS C_Costcenter_ID,
         COALESCE(l.User1_ID, s.User1_ID) AS User1_ID, COALESCE(l.User2_ID, s.User2_ID) AS User2_ID
-        FROM C_UOM uom, M_INOUTLINE l, M_PRODUCT p , M_InOut s
+        FROM C_UOM uom, M_INOUTLINE l
+          left join c_invoiceline il on l.m_inoutline_id = il.m_inoutline_id
+          left join c_invoice i on il.c_invoice_id = i.c_invoice_id 
+        , M_PRODUCT p , M_InOut s
         WHERE l.M_InOut_ID = s.M_InOut_ID
         AND l.C_UOM_ID=uom.C_UOM_ID
         AND l.M_Product_ID=p.M_Product_ID 
-        AND EXISTS (select 1
-                      from m_inoutline iol
-                        left join c_invoiceline il on iol.m_inoutline_id = il.m_inoutline_id
-                        left join c_invoice i on il.c_invoice_id = i.c_invoice_id 
-                      where iol.m_inoutline_id = l.m_inoutline_id
-                      group by iol.m_inoutline_id, iol.movementqty
-                      having (iol.movementqty >= 0 AND iol.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
-                              OR (iol.movementqty < 0 AND iol.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0))) )
         GROUP BY l.MovementQty,l.C_UOM_ID,uom.UOMSymbol,l.M_Product_ID,p.NAME, l.M_InOutLine_ID,l.Line,l.C_OrderLine_ID, l.Description, l.quantityOrder, l.M_Product_UOM_ID, l.M_ATTRIBUTESETINSTANCE_ID, l.ad_org_id, l.m_inout_id,
         COALESCE(l.A_Asset_ID, s.A_Asset_ID), COALESCE(l.C_Project_ID, s.C_Project_ID), COALESCE(l.C_Costcenter_ID, s.C_Costcenter_ID),
         COALESCE(l.User1_ID, s.User1_ID), COALESCE(l.User2_ID, s.User2_ID)
+        HAVING (l.movementqty >= 0 AND l.movementqty > SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
+          OR (l.movementqty < 0 AND l.movementqty < SUM(COALESCE(CASE WHEN i.docstatus = 'CO' THEN il.qtyinvoiced ELSE 0 END, 0)))
         ORDER BY l.Line
       ]]>
     </Sql>
--- a/src/org/openbravo/erpCommon/ad_forms/DocMovement.java	Tue Jan 29 12:09:42 2013 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocMovement.java	Tue Jan 29 19:27:44 2013 +0100
@@ -195,13 +195,17 @@
           nextSeqNo(SeqNo), DocumentType, conn); // from
       // (-)
       // CR
-      dr.setM_Locator_ID(line.m_M_Locator_ID);
+      if (dr != null) {
+        dr.setM_Locator_ID(line.m_M_Locator_ID);
+      }
       // InventoryTo DR CR
       cr = fact.createLine(line, line.getAccount(ProductInfo.ACCTTYPE_P_Asset, as, conn),
           costCurrency.getId(), costs, Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn); // to
       // (+)
       // DR
-      cr.setM_Locator_ID(line.m_M_LocatorTo_ID);
+      if (cr != null) {
+        cr.setM_Locator_ID(line.m_M_LocatorTo_ID);
+      }
     }
     log4jDocMovement.debug("DocMovement - After the loop");
     SeqNo = "0";