details:   https://code.openbravo.com/erp/devel/pi/rev/77543bb2027b
changeset: 18989:77543bb2027b
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Mon Dec 10 11:56:58 2012 +0100
summary:   Fixes bug 22474

details:   https://code.openbravo.com/erp/devel/pi/rev/33e9b9c8f291
changeset: 18990:33e9b9c8f291
user:      Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date:      Mon Dec 10 12:42:38 2012 +0100
summary:   Fixes db consistency - Build #3560

diffstat:

 src-db/database/model/tables/AD_DIMENSION_MAPPING.xml                |   2 +-
 src-db/database/model/tables/C_ORDERLINE_ACCTDIMENSION.xml           |   2 +-
 src-db/database/model/tables/M_INOUTLINE_ACCTDIMENSION.xml           |   2 +-
 src/org/openbravo/erpCommon/businessUtility/COAUtility.java          |   4 +-
 src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java |  41 
++++++---
 5 files changed, 34 insertions(+), 17 deletions(-)

diffs (115 lines):

diff -r 0f099069d5ea -r 33e9b9c8f291 
src-db/database/model/tables/AD_DIMENSION_MAPPING.xml
--- a/src-db/database/model/tables/AD_DIMENSION_MAPPING.xml     Mon Dec 10 
10:54:54 2012 +0100
+++ b/src-db/database/model/tables/AD_DIMENSION_MAPPING.xml     Mon Dec 10 
12:42:38 2012 +0100
@@ -69,11 +69,11 @@
       <foreign-key foreignTable="AD_MODULE" name="AD_DIMENSION_MAPPING_MODULE">
         <reference local="AD_MODULE_ID" foreign="AD_MODULE_ID"/>
       </foreign-key>
-      <check name="AD_DIM_MAP_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 
'N')]]></check>
       <unique name="AD_DIMENSION_MAPPING_UNIQUE">
         <unique-column name="DIMENSION"/>
         <unique-column name="DOCBASETYPE"/>
         <unique-column name="AD_TABLE_ID"/>
       </unique>
+      <check name="AD_DIM_MAP_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 
'N')]]></check>
     </table>
   </database>
diff -r 0f099069d5ea -r 33e9b9c8f291 
src-db/database/model/tables/C_ORDERLINE_ACCTDIMENSION.xml
--- a/src-db/database/model/tables/C_ORDERLINE_ACCTDIMENSION.xml        Mon Dec 
10 10:54:54 2012 +0100
+++ b/src-db/database/model/tables/C_ORDERLINE_ACCTDIMENSION.xml        Mon Dec 
10 12:42:38 2012 +0100
@@ -113,9 +113,9 @@
       <foreign-key foreignTable="AD_CLIENT" 
name="C_ORDERLINE_ACCTDIMENSION_AD">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
-      <check name="C_ORDLINE_ACCT_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 
'N')]]></check>
       <index name="C_ORDLINE_ACCTDIM_ORDLINE" unique="false">
         <index-column name="C_ORDERLINE_ID"/>
       </index>
+      <check name="C_ORDLINE_ACCT_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 
'N')]]></check>
     </table>
   </database>
diff -r 0f099069d5ea -r 33e9b9c8f291 
src-db/database/model/tables/M_INOUTLINE_ACCTDIMENSION.xml
--- a/src-db/database/model/tables/M_INOUTLINE_ACCTDIMENSION.xml        Mon Dec 
10 10:54:54 2012 +0100
+++ b/src-db/database/model/tables/M_INOUTLINE_ACCTDIMENSION.xml        Mon Dec 
10 12:42:38 2012 +0100
@@ -113,9 +113,9 @@
       <foreign-key foreignTable="AD_CLIENT" 
name="M_INOUTLINE_ACCTDIMENSION_AD">
         <reference local="AD_CLIENT_ID" foreign="AD_CLIENT_ID"/>
       </foreign-key>
-      <check name="M_IOLINE_ACC_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 
'N')]]></check>
       <index name="M_IOLINE_ACCTDIM_IOLINE" unique="false">
         <index-column name="M_INOUTLINE_ID"/>
       </index>
+      <check name="M_IOLINE_ACC_ISACTIVE_CHECK"><![CDATA[ISACTIVE IN ('Y', 
'N')]]></check>
     </table>
   </database>
diff -r 0f099069d5ea -r 33e9b9c8f291 
src/org/openbravo/erpCommon/businessUtility/COAUtility.java
--- a/src/org/openbravo/erpCommon/businessUtility/COAUtility.java       Mon Dec 
10 10:54:54 2012 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/COAUtility.java       Mon Dec 
10 12:42:38 2012 +0100
@@ -215,8 +215,10 @@
     if (coa != null && coa.length != 0) {
       try {
         obeResult = insertElementValuesInDB(coa);
-        if (!obeResult.getType().equals(strMessageOk))
+        if (!obeResult.getType().equals(strMessageOk)) {
+          OBDal.getInstance().flush();
           return obeResult;
+        }
       } catch (Exception e) {
         return logError(
             "@CreateAccountingFailed@",
diff -r 0f099069d5ea -r 33e9b9c8f291 
src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java
--- a/src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java      
Mon Dec 10 10:54:54 2012 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/InitialSetupUtility.java      
Mon Dec 10 12:42:38 2012 +0100
@@ -1472,24 +1472,39 @@
       ElementValue elementValue, AcctSchema acctSchema, Boolean 
isFullyQualified) {
     Organization organization;
     if (orgProvided == null) {
-      if ((organization = getZeroOrg()) == null)
+      if ((organization = getZeroOrg()) == null) {
         return null;
-    } else
+      }
+    } else {
       organization = orgProvided;
+    }
+    OBContext.setAdminMode(false);
+    try {
+      OBCriteria<AccountingCombination> obc = 
OBDal.getInstance().createCriteria(
+          AccountingCombination.class);
+      obc.add(Restrictions.eq(AccountingCombination.PROPERTY_ACCOUNT, 
elementValue));
+      List<AccountingCombination> combinations = obc.list();
 
-    final AccountingCombination newAcctComb = OBProvider.getInstance().get(
-        AccountingCombination.class);
+      if (combinations.size() == 0) {
+        final AccountingCombination newAcctComb = OBProvider.getInstance().get(
+            AccountingCombination.class);
 
-    newAcctComb.setClient(client);
-    newAcctComb.setOrganization(organization);
-    newAcctComb.setAccount(elementValue);
-    newAcctComb.setAccountingSchema(acctSchema);
-    newAcctComb.setOrganization(elementValue.getOrganization());
-    newAcctComb.setFullyQualified(isFullyQualified);
+        newAcctComb.setClient(client);
+        newAcctComb.setOrganization(organization);
+        newAcctComb.setAccount(elementValue);
+        newAcctComb.setAccountingSchema(acctSchema);
+        newAcctComb.setOrganization(elementValue.getOrganization());
+        newAcctComb.setFullyQualified(isFullyQualified);
 
-    OBDal.getInstance().save(newAcctComb);
-    OBDal.getInstance().flush();
-    return newAcctComb;
+        OBDal.getInstance().save(newAcctComb);
+        OBDal.getInstance().flush();
+        return newAcctComb;
+      } else {
+        return combinations.get(0);
+      }
+    } finally {
+      OBContext.restorePreviousMode();
+    }
   }
 
   /**

------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to