gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Thu Mar 10 09:19:34 EST 2016


Updated	 via  https://github.com/Gnucash/gnucash/commit/7003a561 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/18065151 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/712d340b (commit)
	from  https://github.com/Gnucash/gnucash/commit/b89723a5 (commit)



commit 7003a561712d104e6b72dc5be2c6bdaff0ff20a7
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Mar 10 12:08:40 2016 +0100

    Make gnucash 2.7+ rerun bayesian data conversion whenever needed
    
    Whenever recent 2.6.x versions of gnucash store bayesian data
    in the old format (full account name based), gnucash 2.7+
    should perform a conversion the the new format (guid based)
    on subsequent opening of the file.

diff --git a/src/import-export/import-match-map.c b/src/import-export/import-match-map.c
index 19b1222..4a66e96 100644
--- a/src/import-export/import-match-map.c
+++ b/src/import-export/import-match-map.c
@@ -558,8 +558,17 @@ void gnc_imap_add_account_bayes(GncImportMatchMap *imap, GList *tokens, Account
          * /imap->frame/IMAP_FRAME/token_string/account_fullname or guid
          */
         if (use_fullname == TRUE)
+        {
+            KvpFrame  *book_frame = qof_book_get_slots (imap->book);
+            const gchar *book_path = "changed-bayesian-to-guid";
+
             kvp_frame_set_slot_path(imap->frame, new_value, IMAP_FRAME_BAYES,
                                     (char*)current_token->data, account_fullname, NULL);
+
+            /* Reset the run once kvp flag for versions 2.7.0 and later */
+            if (kvp_frame_get_string(book_frame, book_path) != NULL)
+                kvp_frame_set_string(book_frame, book_path, "false");
+        }
         else
             kvp_frame_set_slot_path(imap->frame, new_value, IMAP_FRAME_BAYES,
                                     (char*)current_token->data, guid_string, NULL);

commit 18065151223a7a932b7e7831c6d7ab209b78dce7
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Feb 20 13:15:56 2016 +0000

    Allow matching accounts to be found also by their GUID
    which will be used in newer versions. The
    default behaviour is still to create new entries
    under the account fullname.

diff --git a/src/import-export/import-match-map.c b/src/import-export/import-match-map.c
index 558800d..19b1222 100644
--- a/src/import-export/import-match-map.c
+++ b/src/import-export/import-match-map.c
@@ -447,14 +447,31 @@ Account* gnc_imap_find_account_bayes(GncImportMatchMap *imap, GList *tokens)
     /* has this probability met our threshold? */
     if (account_i.probability >= threshold)
     {
-        PINFO("found match");
-        LEAVE(" ");
-        return gnc_account_lookup_by_full_name(gnc_book_get_root_account(imap->book),
+        Account *account = NULL;
+        PINFO("Probability has met threshold");
+
+        account = gnc_account_lookup_by_full_name(gnc_book_get_root_account(imap->book),
                                                account_i.account_name);
-    }
 
-    PINFO("no match");
-    LEAVE(" ");
+        if (account == NULL) // Possibly we have a Guid or account not found
+        {
+            GncGUID *guid = g_new (GncGUID, 1);
+
+            if (string_to_guid (account_i.account_name, guid))
+                account = xaccAccountLookup (guid, imap->book);
+
+            g_free (guid);
+        }
+
+        if (account != NULL)
+            LEAVE("Return account is '%s'", xaccAccountGetName (account));
+        else
+            LEAVE("Return NULL, account for string '%s' can not be found", account_i.account_name);
+
+        return account;
+    }
+    PINFO("Probability has not met threshold");
+    LEAVE("Return NULL");
 
     return NULL; /* we didn't meet our threshold, return NULL for an account */
 }
@@ -468,6 +485,8 @@ void gnc_imap_add_account_bayes(GncImportMatchMap *imap, GList *tokens, Account
     gint64 token_count;
     char* account_fullname;
     kvp_value *new_value; /* the value that will be added back into the kvp tree */
+    const gchar *guid_string;
+    gboolean use_fullname = TRUE;
 
     ENTER(" ");
 
@@ -484,6 +503,8 @@ void gnc_imap_add_account_bayes(GncImportMatchMap *imap, GList *tokens, Account
 
     PINFO("account name: '%s'\n", account_fullname);
 
+    guid_string = guid_to_string (xaccAccountGetGUID (acc));
+
     /* process each token in the list */
     for (current_token = g_list_first(tokens); current_token;
             current_token = current_token->next)
@@ -500,11 +521,20 @@ void gnc_imap_add_account_bayes(GncImportMatchMap *imap, GList *tokens, Account
 
         PINFO("adding token '%s'\n", (char*)current_token->data);
 
-        /* is this token/account_name already in the kvp tree? */
+        /* is this token/account_name already in the kvp tree under fullname? */
         value = kvp_frame_get_slot_path(imap->frame, IMAP_FRAME_BAYES,
                                         (char*)current_token->data, account_fullname,
                                         NULL);
 
+        if (!value) // we have not found entry under the fullname, maybe guid
+        {
+            value = kvp_frame_get_slot_path(imap->frame, IMAP_FRAME_BAYES,
+                                            (char*)current_token->data, guid_string,
+                                            NULL);
+            if (value)
+                use_fullname = FALSE;
+        }
+
         /* if the token/account is already in the tree, read the current
          * value from the tree and use this for the basis of the value we
          * are putting back
@@ -525,10 +555,14 @@ void gnc_imap_add_account_bayes(GncImportMatchMap *imap, GList *tokens, Account
         new_value = kvp_value_new_gint64(token_count);
 
         /* insert the value into the kvp tree at
-         * /imap->frame/IMAP_FRAME/token_string/account_name_string
+         * /imap->frame/IMAP_FRAME/token_string/account_fullname or guid
          */
-        kvp_frame_set_slot_path(imap->frame, new_value, IMAP_FRAME_BAYES,
-                                (char*)current_token->data, account_fullname, NULL);
+        if (use_fullname == TRUE)
+            kvp_frame_set_slot_path(imap->frame, new_value, IMAP_FRAME_BAYES,
+                                    (char*)current_token->data, account_fullname, NULL);
+        else
+            kvp_frame_set_slot_path(imap->frame, new_value, IMAP_FRAME_BAYES,
+                                    (char*)current_token->data, guid_string, NULL);
         /* kvp_frame_set_slot_path() copied the value so we
          * need to delete this one ;-) */
         kvp_value_delete(new_value);

commit 712d340bf4d7898605e6fb8e6a4a9b52c0372410
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Mar 10 12:05:16 2016 +0100

    Introduce GUID_BAYES feature flag
    
    This will be set by future versions of gnucash (2.7+) when
    they save bayesian data using GUID's instead of full
    account names. The flag will prevent older versions
    (2.6.11 and older) from opening data files with such data.

diff --git a/src/core-utils/gnc-features.c b/src/core-utils/gnc-features.c
index 0336fe2..feb7758 100644
--- a/src/core-utils/gnc-features.c
+++ b/src/core-utils/gnc-features.c
@@ -44,6 +44,7 @@ static gncFeature known_features[] =
     { GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
     { GNC_FEATURE_NUM_FIELD_SOURCE, "User specifies source of 'num' field'; either transaction number or split action (requires at least GnuCash 2.5.0)" },
     { GNC_FEATURE_KVP_EXTRA_DATA, "Extra data for addresses, jobs or invoice entries (requires at least GnuCash 2.6.4)" },
+    { GNC_FEATURE_CHANGE_BAYESIAN, "Change the way Bayesian data is saved to use the Account Guid (requires at least GnuCash 2.7.0)" },
     { NULL },
 };
 
diff --git a/src/core-utils/gnc-features.h b/src/core-utils/gnc-features.h
index 7b64ca6..8212544 100644
--- a/src/core-utils/gnc-features.h
+++ b/src/core-utils/gnc-features.h
@@ -44,6 +44,7 @@
 #define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
 #define GNC_FEATURE_NUM_FIELD_SOURCE "Number Field Source"
 #define GNC_FEATURE_KVP_EXTRA_DATA "Extra data in addresses, jobs or invoice entries"
+#define GNC_FEATURE_CHANGE_BAYESIAN "Change the way Bayesian data is saved to use Guid"
 
 /** @} */
 



Summary of changes:
 src/core-utils/gnc-features.c        |  1 +
 src/core-utils/gnc-features.h        |  1 +
 src/import-export/import-match-map.c | 63 ++++++++++++++++++++++++++++++------
 3 files changed, 55 insertions(+), 10 deletions(-)



More information about the gnucash-changes mailing list