Fixes bug 22229
authorEduardo Argal Guibert <eduardo.argal@openbravo.com>
Wed, 07 Nov 2012 13:46:39 +0100
changeset 18498 69d9309e5550
parent 18497 22b019b64170
child 18499 5ad685bc6f06
child 18500 587215fcc82a
Fixes bug 22229
src-db/database/model/triggers/C_ELEMENTVALUE_TRG.xml
src/org/openbravo/erpCommon/businessUtility/COAUtility.java
--- a/src-db/database/model/triggers/C_ELEMENTVALUE_TRG.xml	Tue Nov 06 19:38:59 2012 +0100
+++ b/src-db/database/model/triggers/C_ELEMENTVALUE_TRG.xml	Wed Nov 07 13:46:39 2012 +0100
@@ -151,7 +151,7 @@
 		      SET Updated=now(), isactive = 'N' 		          
 		      WHERE Account_ID=:new.C_ElementValue_ID;
      END IF;         
-     IF(:old.elementlevel <> 'S' and :new.elementlevel = 'S') THEN
+     IF(:new.elementlevel = 'S') THEN
         SELECT COUNT(*)
         INTO v_Count
         FROM C_VALIDCOMBINATION
--- a/src/org/openbravo/erpCommon/businessUtility/COAUtility.java	Tue Nov 06 19:38:59 2012 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/COAUtility.java	Wed Nov 07 13:46:39 2012 +0100
@@ -76,6 +76,7 @@
   private StringBuffer strLog = new StringBuffer();
   private Calendar calendar;
   private Element element;
+  private AcctSchema acctSchema = null;
   private static final Logger log4j = Logger.getLogger(COAUtility.class);
 
   public COAUtility(Client clientProvided, Tree treeAccountProvided) {
@@ -151,6 +152,13 @@
       return obeResult;
     log4j.debug("createAccounting() - Element correctly inserted");
 
+    log4j.debug("createAccounting() - Inserting accounting schema (general ledger)");
+    obeResult = insertAccountingSchema(strGAAPProvided, strCostingMethodProvided, currency,
+        hasBPartner, hasProduct, hasProject, hasMCampaign, hasSRegion);
+    if (!obeResult.getType().equals(strMessageOk))
+      return obeResult;
+    log4j.debug("createAccounting() - Accounting schema (general ledger) correctly inserted");
+
     log4j.debug("createAccounting() - Inserting accounts from file");
     obeResult = insertElementValues(vars, fileCoA);
     if (!obeResult.getType().equals(strMessageOk))
@@ -159,9 +167,8 @@
     // Not meaningful message, but set to keep backwards compatibility
     logEvent("@C_ElementValue_ID@ #");
 
-    log4j.debug("createAccounting() - Inserting accounting schema (general ledger)");
-    obeResult = insertAccountingSchema(strGAAPProvided, strCostingMethodProvided, currency,
-        hasBPartner, hasProduct, hasProject, hasMCampaign, hasSRegion);
+    log4j.debug("createAccounting() - Inserting accounting schema (general ledger and defaults)");
+    obeResult = insertAccountingSchemaGLDefaults(acctSchema);
     if (!obeResult.getType().equals(strMessageOk))
       return obeResult;
     log4j.debug("createAccounting() - Accounting schema (general ledger) correctly inserted");
@@ -238,7 +245,6 @@
         + " " + strGAAP + "/" + strCostingMethod + "/" + currency.getDescription();
     log4j.debug("insertAccountingSchema() - Creating accounting schema (general ledger) "
         + strAcctSchemaName);
-    AcctSchema acctSchema = null;
     try {
       acctSchema = InitialSetupUtility.insertAcctSchema(client, organization, currency,
           strAcctSchemaName, strGAAP, strCostingMethod, true);
@@ -395,6 +401,14 @@
     }
     log4j.debug("insertAccountingSchema() - All acct.schema elements correctly inserted."
         + " Inserting acct.schema gl account combinations");
+
+    return obeResult;
+  }
+
+  private OBError insertAccountingSchemaGLDefaults(AcctSchema acctSchema) {
+    OBError obeResult = new OBError();
+    obeResult.setType(strMessageOk);
+
     AcctSchemaGL acctSchGL;
     try {
       acctSchGL = InitialSetupUtility.insertAcctSchemaGL(defaultElementValues, acctSchema);
@@ -443,6 +457,7 @@
       }
     }
     return obeResult;
+
   }
 
   private COAData[] parseCOA(VariablesBase vars, InputStream instFile) throws IOException {