Fixes Issue 24999, Fixes Issue 25528: Wrong error message
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Mon, 27 Jan 2014 12:34:47 +0530
changeset 21870 a990b760487b
parent 21869 8555c81d021d
child 21871 fcc10a50bab6
Fixes Issue 24999, Fixes Issue 25528: Wrong error message
When posting and unposting an inventory with a line with Qty Count = Book Qty, wrong error message is displayed
src/org/openbravo/erpCommon/ad_forms/DocInventory.java
src/org/openbravo/erpCommon/ad_forms/DocLineInventory_data.xsql
src/org/openbravo/financial/ResetAccounting.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocInventory.java	Fri Jan 24 12:30:01 2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInventory.java	Mon Jan 27 12:34:47 2014 +0530
@@ -11,7 +11,7 @@
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
  * Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2012 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U.
  ******************************************************************************
  */
 package org.openbravo.erpCommon.ad_forms;
@@ -174,6 +174,9 @@
     FactLine dr = null;
     FactLine cr = null;
     log4jDocInventory.debug("CreateFact - before loop");
+    if (p_lines.length == 0) {
+      setStatus(STATUS_DocumentDisabled);
+    }
     for (int i = 0; i < p_lines.length; i++) {
       DocLine_Material line = (DocLine_Material) p_lines[i];
 
--- a/src/org/openbravo/erpCommon/ad_forms/DocLineInventory_data.xsql	Fri Jan 24 12:30:01 2014 +0530
+++ b/src/org/openbravo/erpCommon/ad_forms/DocLineInventory_data.xsql	Mon Jan 27 12:34:47 2014 +0530
@@ -12,7 +12,7 @@
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
  * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
  * Contributor(s): Openbravo SLU
- * Contributions are Copyright (C) 2001-2010 Openbravo S.L.U.
+ * Contributions are Copyright (C) 2001-2014 Openbravo S.L.U.
  ******************************************************************************
 -->
 
@@ -28,7 +28,10 @@
       <![CDATA[
 	  SELECT IL.AD_ORG_ID, IL.M_PRODUCT_ID, IL.LINE, IL.DESCRIPTION,
 	  IL.C_UOM_ID, IL.M_INVENTORYLINE_ID, IL.QTYBOOK, IL.QTYCOUNT,
-	  IL.M_LOCATOR_ID FROM M_InventoryLine IL WHERE M_Inventory_ID=? ORDER BY Line
+	  IL.M_LOCATOR_ID FROM M_InventoryLine IL 
+	  WHERE M_Inventory_ID=?
+	  AND IL.QTYBOOK<>IL.QTYCOUNT
+	  ORDER BY Line
      ]]>
      </Sql>
      <Parameter name="M_Inventory_ID"/>
--- a/src/org/openbravo/financial/ResetAccounting.java	Fri Jan 24 12:30:01 2014 +0530
+++ b/src/org/openbravo/financial/ResetAccounting.java	Mon Jan 27 12:34:47 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):  ______________________________________.
  *************************************************************************
@@ -174,6 +174,30 @@
     results.put("updated", updated);
     log4j.debug("total totalProcess (milies): " + (System.currentTimeMillis() - totalProcess));
     if (recordId != null && !"".equals(recordId) && deleted == 0 && updated == 0) {
+      if (recordId != null && !"".equals(recordId) && adTableId != null && !"".equals(adTableId)) {
+        // If record exists but there is no entry in fact table then unpost record
+        try {
+          OBContext.setAdminMode(false);
+          Table table = OBDal.getInstance().get(Table.class, adTableId);
+          OBCriteria<AccountingFact> obc = OBDal.getInstance().createCriteria(AccountingFact.class);
+          obc.setFilterOnReadableClients(false);
+          obc.setFilterOnReadableOrganization(false);
+          obc.setFilterOnActive(false);
+          obc.add(Restrictions.eq(AccountingFact.PROPERTY_RECORDID, recordId));
+          obc.add(Restrictions.eq(AccountingFact.PROPERTY_TABLE, table));
+          if (obc.list().size() == 0) {
+            String strUpdate = "update "
+                + table.getName()
+                + " set posted='N', processNow=false where (posted<>'N' or posted is null or processNow = false) and id = :recordID ";
+            final Query update = OBDal.getInstance().getSession().createQuery(strUpdate);
+            update.setParameter("recordID", recordId);
+            updated = update.executeUpdate();
+            return results;
+          }
+        } finally {
+          OBContext.restorePreviousMode();
+        }
+      }
       throw new OBException("@PeriodClosedForUnPosting@");
     }
     return results;