From 363c9e4afbe479c8029899bd96ba658a5a81be5f Mon Sep 17 00:00:00 2001
From: Matiss Janis Aboltins <matiss@mja.lv>
Date: Thu, 18 Jan 2024 08:23:29 +0000
Subject: [PATCH] :bug: (gocardless) fix sync when additionalInformation field
 is null (#2238)

---
 .../loot-core/src/server/accounts/sync.ts     | 34 ++++++++++---------
 upcoming-release-notes/2238.md                |  6 ++++
 2 files changed, 24 insertions(+), 16 deletions(-)
 create mode 100644 upcoming-release-notes/2238.md

diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index ae04efa67..fa6d31340 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -309,14 +309,15 @@ async function normalizeGoCardlessTransactions(transactions, acctId) {
     // that it matters whether the amount is a positive or negative zero.
     if (trans.amount > 0 || Object.is(Number(trans.amount), 0)) {
       const nameParts = [];
-      nameParts.push(
-        title(
-          trans.debtorName ||
-            trans.remittanceInformationUnstructured ||
-            (trans.remittanceInformationUnstructuredArray || []).join(', ') ||
-            trans.additionalInformation,
-        ),
-      );
+      const name =
+        trans.debtorName ||
+        trans.remittanceInformationUnstructured ||
+        (trans.remittanceInformationUnstructuredArray || []).join(', ') ||
+        trans.additionalInformation;
+
+      if (name) {
+        nameParts.push(title(name));
+      }
       if (trans.debtorAccount && trans.debtorAccount.iban) {
         nameParts.push(
           '(' +
@@ -329,14 +330,15 @@ async function normalizeGoCardlessTransactions(transactions, acctId) {
       payee_name = nameParts.join(' ');
     } else {
       const nameParts = [];
-      nameParts.push(
-        title(
-          trans.creditorName ||
-            trans.remittanceInformationUnstructured ||
-            (trans.remittanceInformationUnstructuredArray || []).join(', ') ||
-            trans.additionalInformation,
-        ),
-      );
+      const name =
+        trans.creditorName ||
+        trans.remittanceInformationUnstructured ||
+        (trans.remittanceInformationUnstructuredArray || []).join(', ') ||
+        trans.additionalInformation;
+
+      if (name) {
+        nameParts.push(title(name));
+      }
       if (trans.creditorAccount && trans.creditorAccount.iban) {
         nameParts.push(
           '(' +
diff --git a/upcoming-release-notes/2238.md b/upcoming-release-notes/2238.md
new file mode 100644
index 000000000..a38296a0b
--- /dev/null
+++ b/upcoming-release-notes/2238.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [MatissJanis]
+---
+
+GoCardless: fix sync not working if `additionalInformation` fallback field is null
-- 
GitLab