gnucash maint: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Apr 29 19:53:58 EDT 2022
Updated via https://github.com/Gnucash/gnucash/commit/7e4fcc7a (commit)
via https://github.com/Gnucash/gnucash/commit/d62c6d96 (commit)
via https://github.com/Gnucash/gnucash/commit/4d6dc384 (commit)
from https://github.com/Gnucash/gnucash/commit/396c59e3 (commit)
commit 7e4fcc7afbcde367ba37a5170fb25532053b7b23
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Apr 29 16:51:48 2022 -0700
https://bugs.gnucash.org/show_bug.cgi?id=798491
Prefer the entry date to the value date if present in the import.
The invalid date part of the bug was fixed in 7b1c050.
diff --git a/gnucash/import-export/aqb/gnc-ab-utils.c b/gnucash/import-export/aqb/gnc-ab-utils.c
index 9707746b9..e8809eed2 100644
--- a/gnucash/import-export/aqb/gnc-ab-utils.c
+++ b/gnucash/import-export/aqb/gnc-ab-utils.c
@@ -580,8 +580,8 @@ gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc)
QofBook *book;
Transaction *gnc_trans;
const gchar *fitid;
- const GNC_GWEN_DATE *valuta_date;
- time64 current_time;
+ const GNC_GWEN_DATE *value_date, *post_date;
+ time64 current_time, post_time;
const char *custref;
gchar *description;
Split *split;
@@ -595,22 +595,28 @@ gnc_ab_trans_to_gnc(const AB_TRANSACTION *ab_trans, Account *gnc_acc)
xaccTransBeginEdit(gnc_trans);
/* Date / Time */
- valuta_date = AB_Transaction_GetValutaDate(ab_trans);
- if (!valuta_date)
- {
- const GNC_GWEN_DATE *normal_date = AB_Transaction_GetDate(ab_trans);
- if (normal_date)
- valuta_date = normal_date;
- }
- if (valuta_date)
- {
- time64 secs = gnc_gwen_date_to_time64(valuta_date);
- xaccTransSetDatePostedSecsNormalized(gnc_trans, secs);
- }
+ /* SWIFT import formats (in particular MT940) provide for two
+ * dates, the entry date and the value date (valuta is value in
+ * German). The value date is the effective date for financial
+ * calculation purposes and is mandatory, the entry date is the
+ * date that the financial institution posted the
+ * transaction. Since the entry date is normally closer to the
+ * date that the customer's book should recognize the transaction
+ * we prefer that date if present.
+ */
+ post_date = AB_Transaction_GetDate(ab_trans);
+ value_date = AB_Transaction_GetValutaDate(ab_trans);
+ if (post_date)
+ post_time = gnc_gwen_date_to_time64(post_date);
+ else if (value_date)
+ post_time = gnc_gwen_date_to_time64(value_date);
else
{
- g_warning("transaction_cb: Oops, date 'valuta_date' was NULL");
+ g_warning("transaction_cb: Import had no transaction date");
+ post_time = gnc_time (NULL);
}
+ xaccTransSetDatePostedSecsNormalized(gnc_trans, post_time);
+
xaccTransSetDateEnteredSecs(gnc_trans, gnc_time (NULL));
/* Currency. We take simply the default currency of the gnucash account */
commit d62c6d96e31ea5bdfa7c8f159b67cbfefef3cf43
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Apr 29 15:50:41 2022 -0700
[import matcher] Only append description if there's something to append to.
Otherwise just set the new string.
diff --git a/gnucash/import-export/import-backend.c b/gnucash/import-export/import-backend.c
index 60a79077e..8b796ab94 100644
--- a/gnucash/import-export/import-backend.c
+++ b/gnucash/import-export/import-backend.c
@@ -841,25 +841,21 @@ void split_find_match (GNCImportTransInfo * trans_info,
/* append the imported transaction description to the matched transaction description */
static void
-desc_append (Transaction* selected_match_trans, Transaction* imp_trans)
+desc_append (Transaction* selected_match_trans, gchar *new_desc)
{
- gchar* tmp = g_strconcat( xaccTransGetDescription (selected_match_trans),
- "|",
- xaccTransGetDescription (imp_trans),
- NULL);
+ const gchar* curr_desc = xaccTransGetDescription (selected_match_trans);
+ gchar* tmp = g_strconcat(curr_desc, "|", new_desc, NULL);
xaccTransSetDescription (selected_match_trans, tmp);
g_free (tmp);
}
/* append the imported transaction notes to the matched transaction notes */
static void
-notes_append (Transaction* selected_match_trans, Transaction* imp_trans)
+notes_append (Transaction* selected_match_trans, gchar* new_notes)
{
- gchar* tmp = g_strconcat (xaccTransGetNotes (selected_match_trans),
- "|",
- xaccTransGetNotes (imp_trans),
- NULL);
- xaccTransSetNotes (selected_match_trans, tmp);
+ const gchar* curr_notes = xaccTransGetNotes (selected_match_trans);
+ gchar* tmp = g_strconcat (curr_notes, "|", new_notes, NULL);
+ xaccTransSetNotes (selected_match_trans, tmp );
g_free (tmp);
}
@@ -887,7 +883,7 @@ update_desc_and_notes (const GNCImportTransInfo* trans_info)
note_imported =
raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
raw_str = xaccTransGetNotes (selected_match->trans);
- note_matched =
+ note_matched =
raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
// Append if desc_imported not already in desc_matched
@@ -895,14 +891,24 @@ update_desc_and_notes (const GNCImportTransInfo* trans_info)
(!desc_matched ||
g_utf8_strlen (desc_imported, -1) > g_utf8_strlen (desc_matched, -1) ||
!strstr (desc_matched, desc_imported)))
- desc_append (selected_match->trans, imp_trans);
+ {
+ if (desc_matched && *desc_matched)
+ desc_append (selected_match->trans, desc_imported);
+ else
+ xaccTransSetDescription (selected_match->trans, desc_imported);
+ }
// Append if note_imported not already in note_matched
if (note_imported &&
(!note_matched ||
g_utf8_strlen (note_imported, -1) > g_utf8_strlen (note_matched, -1) ||
!strstr (note_matched, note_imported)))
- notes_append (selected_match->trans, imp_trans);
+ {
+ if (note_matched && *note_matched)
+ notes_append (selected_match->trans, note_imported);
+ else
+ xaccTransSetNotes (selected_match->trans, note_imported);
+ }
g_free(desc_imported);
g_free(desc_matched);
commit 4d6dc384ee0f49d8c35e17c116c98647298d9529
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Apr 29 15:41:45 2022 -0700
[import matcher] NULL protect g_utf8_normalize
It crashes if fed a NULL string.
May fix https://bugs.gnucash.org/show_bug.cgi?id=798483.
diff --git a/gnucash/import-export/import-backend.c b/gnucash/import-export/import-backend.c
index a993c3229..60a79077e 100644
--- a/gnucash/import-export/import-backend.c
+++ b/gnucash/import-export/import-backend.c
@@ -875,23 +875,33 @@ update_desc_and_notes (const GNCImportTransInfo* trans_info)
if (trans_info->append_text)
{
- gchar* desc_imported = g_utf8_normalize (xaccTransGetDescription (
- imp_trans), -1, G_NORMALIZE_ALL);
- gchar* desc_matched = g_utf8_normalize (xaccTransGetDescription (
- selected_match->trans), -1, G_NORMALIZE_ALL);
- gchar* note_imported = g_utf8_normalize (xaccTransGetNotes (
- imp_trans), -1, G_NORMALIZE_ALL);
- gchar* note_matched = g_utf8_normalize (xaccTransGetNotes (
- selected_match->trans), -1, G_NORMALIZE_ALL);
+ gchar *desc_imported, *desc_matched, *note_imported, *note_matched;
+ const gchar* raw_str = xaccTransGetDescription (imp_trans);
+
+ desc_imported =
+ raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
+ raw_str = xaccTransGetDescription (selected_match->trans);
+ desc_matched =
+ raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
+ raw_str = xaccTransGetNotes (imp_trans);
+ note_imported =
+ raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
+ raw_str = xaccTransGetNotes (selected_match->trans);
+ note_matched =
+ raw_str ? g_utf8_normalize (raw_str, -1, G_NORMALIZE_ALL) : NULL;
// Append if desc_imported not already in desc_matched
- if (g_utf8_strlen (desc_imported, -1) > g_utf8_strlen (desc_matched, -1) ||
- !strstr (desc_matched, desc_imported))
+ if (desc_imported &&
+ (!desc_matched ||
+ g_utf8_strlen (desc_imported, -1) > g_utf8_strlen (desc_matched, -1) ||
+ !strstr (desc_matched, desc_imported)))
desc_append (selected_match->trans, imp_trans);
// Append if note_imported not already in note_matched
- if (g_utf8_strlen (note_imported, -1) > g_utf8_strlen (note_matched, -1) ||
- !strstr (note_matched, note_imported))
+ if (note_imported &&
+ (!note_matched ||
+ g_utf8_strlen (note_imported, -1) > g_utf8_strlen (note_matched, -1) ||
+ !strstr (note_matched, note_imported)))
notes_append (selected_match->trans, imp_trans);
g_free(desc_imported);
Summary of changes:
gnucash/import-export/aqb/gnc-ab-utils.c | 36 +++++++++--------
gnucash/import-export/import-backend.c | 66 ++++++++++++++++++++------------
2 files changed, 62 insertions(+), 40 deletions(-)
More information about the gnucash-changes
mailing list