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

List:       kde-commits
Subject:    [skrooge] /: Default categories for payees
From:       Stephane Mankowski <stephane () mankowski ! fr>
Date:       2015-09-30 20:35:55
Message-ID: E1ZhO6V-0002mm-Qj () scm ! kde ! org
[Download RAW message or body]

Git commit 2c54e79b95dad6693d963160619a25cb80844e83 by Stephane Mankowski.
Committed on 30/09/2015 at 20:35.
Pushed by smankowski into branch 'master'.

Default categories for payees
BUG:349976

M  +1    -0    CHANGELOG
M  +7    -0    plugins/import/skrooge_import_csv/skgimportplugincsv.cpp
M  +4    -0    plugins/skrooge/skrooge_operation/skgoperation_settings.kcfg
M  +8    -0    plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp
M  +1    -0    plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h
M  +13   -5    plugins/skrooge/skrooge_operation/skgoperationpluginwidget_pref.ui
M  +27   -0    skgbankmodeler/skgdocumentbank.cpp
M  +7    -0    skgbankmodeler/skgdocumentbank.h
M  +2    -0    tests/skgbankmodelertest/skgtestimportcsv.cpp

http://commits.kde.org/skrooge/2c54e79b95dad6693d963160619a25cb80844e83

diff --git a/CHANGELOG b/CHANGELOG
index a312f20..db5d40a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 skrooge (2.2.0)  
   *Correction bug 352674: SQLite version of the system not aligned with embedded in \
                Qt when using sqlcipher 
   *Correction bug 349961: Values in "Text" report are clickable to open \
corresponding operations +  *Correction bug 349976: Default categories for payees
   *Correction: Drag and drop file is now able to move a file
   *Correction: The WORD function of "Search & Replace" is no more sensible of \
useless space  
diff --git a/plugins/import/skrooge_import_csv/skgimportplugincsv.cpp \
b/plugins/import/skrooge_import_csv/skgimportplugincsv.cpp index 2226b3c..d4a55ee \
                100644
--- a/plugins/import/skrooge_import_csv/skgimportplugincsv.cpp
+++ b/plugins/import/skrooge_import_csv/skgimportplugincsv.cpp
@@ -612,6 +612,13 @@ SKGError SKGImportPluginCsv::importFile()
                                         SKGCategoryObject Category;
                                         err = \
                SKGCategoryObject::createPathCategory(m_importer->getDocument(), val, \
                Category);
                                         IFOKDO(err, \
currentSubOperation.setCategory(Category)) +
+                                        IFOK(err && getCSVMapping().indexOf("payee") \
== -1) { +                                            SKGPayeeObject payeeObj;
+                                            QString p = \
m_importer->getDocument()->getCategoryForPayee(val); +                                \
err = SKGPayeeObject::createPayee(m_importer->getDocument(), p, payeeObj); +          \
IFOKDO(err, currentOperation.setPayee(payeeObj)) +                                    \
}  }
                                 } else {
                                     // A property
diff --git a/plugins/skrooge/skrooge_operation/skgoperation_settings.kcfg \
b/plugins/skrooge/skrooge_operation/skgoperation_settings.kcfg index 483f0a3..fdf51b9 \
                100644
--- a/plugins/skrooge/skrooge_operation/skgoperation_settings.kcfg
+++ b/plugins/skrooge/skrooge_operation/skgoperation_settings.kcfg
@@ -25,6 +25,10 @@
 	    <label>Compute balances</label>
 	    <default>true</default>
     </entry>
+    <entry name="setCategoryForPayee" type="Bool">
+	    <label>Set the most used category when the payee is modified</label>
+	    <default>false</default>
+    </entry>    
     <entry name="automaticPointInReconciliation" type="Bool">
 	    <label>Automatic point operations created during reconciliation</label>
 	    <default>true</default>
diff --git a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp \
b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp index \
                bedba97..10d4c1c 100644
--- a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp
+++ b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.cpp
@@ -218,6 +218,7 @@ SKGOperationPluginWidget::SKGOperationPluginWidget(SKGDocumentBank* \
                iDocument)
     connect(ui.kTaxEdit, &SKGCalculatorEdit::textChanged, this, \
&SKGOperationPluginWidget::onOperationCreatorModified, Qt::QueuedConnection);  \
connect(ui.kAccountEdit, static_cast<void (SKGComboBox::*)(const \
QString&)>(&SKGComboBox::currentIndexChanged), this, \
                &SKGOperationPluginWidget::onOperationCreatorModified, \
                Qt::QueuedConnection);
     connect(ui.kOperationView->getShowWidget(), &SKGShow::stateChanged, this, \
&SKGOperationPluginWidget::onFilterChanged, Qt::QueuedConnection); +    \
connect(ui.kPayeeEdit->lineEdit(), &QLineEdit::returnPressed, this, \
&SKGOperationPluginWidget::onPayeeChanged, Qt::QueuedConnection);  
     dataModified("", 0);
     onOperationCreatorModified();
@@ -638,6 +639,13 @@ void SKGOperationPluginWidget::onOperationCreatorModified()
     }
 }
 
+void SKGOperationPluginWidget::onPayeeChanged()
+{
+    if (skgoperation_settings::setCategoryForPayee() && \
ui.kCategoryEdit->text().isEmpty()) { +        \
ui.kCategoryEdit->setText(static_cast<SKGDocumentBank*>(getDocument())->getCategoryForPayee(ui.kPayeeEdit->text()));
 +    }
+}
+
 void SKGOperationPluginWidget::onUpdateOperationClicked()
 {
     SKGError err;
diff --git a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h \
b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h index 134ce4a..cc4b9ae \
                100644
--- a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h
+++ b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget.h
@@ -115,6 +115,7 @@ protected:
 private Q_SLOTS:
     void dataModified(const QString& iTableName, int iIdTransaction, bool \
iLightTransaction = false);  void onOperationCreatorModified();
+    void onPayeeChanged();
     void onAddOperationClicked();
     void onUpdateOperationClicked();
     void onFilterChanged();
diff --git a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget_pref.ui \
b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget_pref.ui index \
                c43dc60..c94b4db 100644
--- a/plugins/skrooge/skrooge_operation/skgoperationpluginwidget_pref.ui
+++ b/plugins/skrooge/skrooge_operation/skgoperationpluginwidget_pref.ui
@@ -196,6 +196,13 @@
     </layout>
    </item>
    <item>
+    <widget class="QCheckBox" name="kcfg_setCategoryForPayee">
+     <property name="text">
+      <string>Set the most used category when the payee is modified</string>
+     </property>
+    </widget>
+   </item>
+   <item>
     <widget class="QCheckBox" name="kcfg_computeBalances">
      <property name="text">
       <string>Compute balances (uncheck to improve performances)</string>
@@ -425,11 +432,6 @@
  </widget>
  <customwidgets>
   <customwidget>
-   <class>SKGComboBox</class>
-   <extends>KComboBox</extends>
-   <header>skgcombobox.h</header>
-  </customwidget>
-  <customwidget>
    <class>KColorButton</class>
    <extends>QPushButton</extends>
    <header>kcolorbutton.h</header>
@@ -444,12 +446,18 @@
    <extends>QLineEdit</extends>
    <header>klineedit.h</header>
   </customwidget>
+  <customwidget>
+   <class>SKGComboBox</class>
+   <extends>KComboBox</extends>
+   <header>skgcombobox.h</header>
+  </customwidget>
  </customwidgets>
  <tabstops>
   <tabstop>kcfg_fontFutureColor</tabstop>
   <tabstop>kcfg_fontNotValidatedColor</tabstop>
   <tabstop>kcfg_fontSubOperationColor</tabstop>
   <tabstop>kcfg_fasteditmode</tabstop>
+  <tabstop>kcfg_setCategoryForPayee</tabstop>
   <tabstop>kcfg_computeBalances</tabstop>
   <tabstop>kcfg_automaticPointInReconciliation</tabstop>
   <tabstop>tabWidget</tabstop>
diff --git a/skgbankmodeler/skgdocumentbank.cpp b/skgbankmodeler/skgdocumentbank.cpp
index 3c417b7..2022a5e 100644
--- a/skgbankmodeler/skgdocumentbank.cpp
+++ b/skgbankmodeler/skgdocumentbank.cpp
@@ -2257,6 +2257,33 @@ SKGServices::SKGUnitInfo SKGDocumentBank::getSecondaryUnit()
     return output;
 }
 
+QString SKGDocumentBank::getCategoryForPayee(const QString& iPayee)
+{
+    QString output;
+    QString key = "categoryForPayee-" + iPayee;
+
+    output = getCachedValue(key);
+    if (output.isEmpty()) {
+        QString sql = "SELECT COUNT(1), t_REALCATEGORY FROM (SELECT t_REALCATEGORY , \
d_date FROM v_suboperation_consolidated WHERE t_PAYEE='" % \
SKGServices::stringToSqlString(iPayee) % "' ORDER BY d_date DESC LIMIT 50) GROUP BY \
t_REALCATEGORY"; +
+        SKGStringListList result;
+        executeSelectSqliteOrder(sql, result);
+        int nb = result.count();
+        if (nb >= 2) {
+            int sum = 0;
+            for (int i = 1 ; i < nb; ++i) {
+                sum = SKGServices::stringToInt(result.at(i).at(0));
+            }
+            if (100 * SKGServices::stringToInt(result.at(1).at(0)) / sum > 90) {
+                output = result.at(1).at(1);
+                addValueInCache(key, output);
+            }
+        }
+    }
+
+    return output;
+}
+
 void SKGDocumentBank::refreshCache(const QString& iTable)
 {
     if (iTable == "unit" || iTable.isEmpty()) {
diff --git a/skgbankmodeler/skgdocumentbank.h b/skgbankmodeler/skgdocumentbank.h
index d8745da..400bbbb 100644
--- a/skgbankmodeler/skgdocumentbank.h
+++ b/skgbankmodeler/skgdocumentbank.h
@@ -106,6 +106,13 @@ public Q_SLOTS:
     virtual SKGServices::SKGUnitInfo getSecondaryUnit();
 
     /**
+    * Get the preferred category for a payee. WARNING: This value can be not \
uptodated in a transaction. +    * @param iPayee the payee
+    * @return The preferred category.
+    */
+    virtual QString getCategoryForPayee(const QString& iPayee);
+
+    /**
      * Refresh all views and indexes in the database
      * @param iForce force the refresh
      * @return an object managing the error.
diff --git a/tests/skgbankmodelertest/skgtestimportcsv.cpp \
b/tests/skgbankmodelertest/skgtestimportcsv.cpp index b060e9d..185ff98 100644
--- a/tests/skgbankmodelertest/skgtestimportcsv.cpp
+++ b/tests/skgbankmodelertest/skgtestimportcsv.cpp
@@ -61,6 +61,8 @@ int main(int argc, char** argv)
         SKGTESTERROR("ACCOUNT.getObjectByName", \
SKGNamedObject::getObjectByName(&document1, "v_account", "Courant steph", account), \
true);  SKGTESTERROR("ACCOUNT.load", account.load(), true);
         SKGTEST("ACCOUNT:getCurrentAmount", \
SKGServices::doubleToString(account.getCurrentAmount()), "-935"); +        \
SKGTEST("document1:getCategoryForPayee", document1.getCategoryForPayee("Anthony \
Hopkins"), "Entertain > Movie"); +        SKGTEST("document1:getCategoryForPayee", \
document1.getCategoryForPayee("NOT FOUND"), "");  }
 
     {


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

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