[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/office/skrooge
From:       Stephane Mankowski <stephane () mankowski ! fr>
Date:       2011-02-06 16:27:25
Message-ID: 20110206162725.3AB55AC8CE () svn ! kde ! org
[Download RAW message or body]

SVN commit 1219158 by smankowski:

Small correction in merge of accounts

 M  +1 -10     skgbankgui/skgobjectmodel.cpp  
 M  +40 -3     skgbankmodeler/skgaccountobject.cpp  
 M  +8 -0      skgbankmodeler/skgaccountobject.h  
 M  +3 -0      skgbankmodelertest/skgtestbankandaccount.cpp  


--- trunk/extragear/office/skrooge/skgbankgui/skgobjectmodel.cpp #1219157:1219158
@@ -844,18 +844,9 @@
 
                 SKGAccountObject child(getDocument(), o_id);
                 err = child.load();
-                SKGObjectBase::SKGListSKGObjectBase ops;
-                if(err.isSucceeded()) err = child.getOperations(ops);
-                int nb = ops.count();
-                for(int i = 0; err.isSucceeded() && i < nb; ++i) {
-                    SKGOperationObject op = ops.at(i);
-                    err = op.setParentAccount(parentAccount);
-                    if(err.isSucceeded()) err = op.save(true, false);
+                if(err.isSucceeded()) err = parentAccount.merge(child);
                 }
-
-                if(err.isSucceeded()) err = child.remove();
             }
-        }
     } else if(data->hasFormat("application/skg.unit.ids")) {
         QByteArray encodedData = data->data("application/skg.unit.ids");
         QDataStream stream(&encodedData, QIODevice::ReadOnly);
--- trunk/extragear/office/skrooge/skgbankmodeler/skgaccountobject.cpp \
#1219157:1219158 @@ -66,6 +66,8 @@
 SKGError SKGAccountObject::setInitialBalance(double iBalance, const SKGUnitObject& \
iUnit)  {
     SKGError err;
+    SKGTRACEINRC(10, "SKGAccountObject::setInitialBalance", err);
+
     //Delete previous initial balance for this account
     err = SKGServices::executeSqliteOrder(getDocument(), "DELETE FROM operation  \
WHERE d_date='0000-00-00' AND rd_account_id=" + SKGServices::intToString(getID()));  
@@ -89,6 +91,7 @@
 SKGError SKGAccountObject::getInitialBalance(double& oBalance, SKGUnitObject& oUnit)
 {
     SKGError err;
+    SKGTRACEINRC(10, "SKGAccountObject::getInitialBalance", err);
     //Initialisation
     oBalance = 0;
     oUnit = SKGUnitObject();
@@ -97,11 +100,9 @@
     //Get initial balance
     SKGStringListList listTmp;
     err = SKGServices::executeSelectSqliteOrder(getDocument(), "SELECT f_QUANTITY, \
t_UNIT FROM  v_operation_consolidated  WHERE d_date='0000-00-00' AND rd_account_id=" \
                + SKGServices::intToString(getID()), listTmp);
-    if(err.isSucceeded()) {
-        if(listTmp.count() > 1) {
+    if(err.isSucceeded() && listTmp.count() > 1) {
             oBalance = SKGServices::stringToDouble(listTmp.at(1).at(0));
             unitName = listTmp.at(1).at(1);
-        }
 
         oUnit = SKGUnitObject(getDocument());
         err = oUnit.setSymbol(unitName);
@@ -649,4 +650,40 @@
     return err;
 }
 
+SKGError SKGAccountObject::merge(const SKGAccountObject& iAccount)
+{
+    SKGError err;
+    SKGTRACEINRC(10, "SKGAccountObject::merge", err);
+
+    //Get initial balances
+    double balance1;
+    SKGUnitObject unit1;
+    err = getInitialBalance(balance1, unit1);
+
+    double balance2;
+    SKGUnitObject unit2;
+    if(err.isSucceeded()) err = \
const_cast<SKGAccountObject*>(&iAccount)->getInitialBalance(balance2, unit2); +
+    //Transfert operations
+    SKGObjectBase::SKGListSKGObjectBase ops;
+    if(err.isSucceeded()) err = iAccount.getOperations(ops);
+    int nb = ops.count();
+    for(int i = 0; err.isSucceeded() && i < nb; ++i) {
+        SKGOperationObject op = ops.at(i);
+        err = op.setParentAccount(*this);
+        if(err.isSucceeded()) err = op.save(true, false);
+    }
+
+    //Set initial balance
+    SKGUnitObject unit = unit1;
+    if(!unit1.exist()) unit = unit2;
+    if(unit.exist()) {
+        double balance = balance1 + SKGUnitObject::convert(balance2, unit2, unit);
+        if(err.isSucceeded()) err = setInitialBalance(balance, unit);
+    }
+    //Remove account
+    if(err.isSucceeded()) err = iAccount.remove();
+    return err;
+}
+
 #include "skgaccountobject.moc"
--- trunk/extragear/office/skrooge/skgbankmodeler/skgaccountobject.h #1219157:1219158
@@ -331,6 +331,14 @@
      *   @see SKGError
      */
     virtual SKGError autoReconcile(double iBalance);
+
+    /**
+     * Merge iAccount in current account
+     * @param iAccount the account. All operations will be transferred into this \
account. The account will be removed +     * @return an object managing the error
+     *   @see SKGError
+     */
+    virtual SKGError merge(const SKGAccountObject& iAccount);
 };
 /**
  * Declare the class
--- trunk/extragear/office/skrooge/skgbankmodelertest/skgtestbankandaccount.cpp \
#1219157:1219158 @@ -162,6 +162,9 @@
             SKGTESTERROR("ACCOUNT:save", account3.save(), true);
 
             SKGTESTERROR("DOC:dump", document1.dump(DUMPALL), true);
+
+            //Merge
+            SKGTESTERROR("ACCOUNT:merge", account2.merge(account3), true);
         }
     }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic