Skip to content

A local-first personal finance app

Revert "[AI] fix: preserve explicit category on imported transactions" (#7388)

youngcw475272adcea0
diff --git a/packages/loot-core/src/server/accounts/sync.test.ts b/packages/loot-core/src/server/accounts/sync.test.ts
index 9bace99f2e..4787f50e6f 100644
--- a/packages/loot-core/src/server/accounts/sync.test.ts
+++ b/packages/loot-core/src/server/accounts/sync.test.ts
@@ -477,46 +477,6 @@ describe('Account sync', () => {
]);
});
- test('addTransactions does not override explicitly provided category', async () => {
- const { id: acctId } = await prepareDatabase();
-
- await db.insertCategoryGroup({
- id: 'group2',
- name: 'group2',
- });
- const explicitCategoryId = await db.insertCategory({
- id: 'api-cat',
- name: 'API Category',
- cat_group: 'group2',
- });
- const ruleCategoryId = await db.insertCategory({
- id: 'rule-cat',
- name: 'Rule Category',
- cat_group: 'group2',
- });
-
- const payeeId = await db.insertPayee({ name: 'P' });
- await insertRule({
- stage: null,
- conditionsOp: 'and',
- conditions: [{ op: 'is', field: 'payee', value: payeeId }],
- actions: [{ op: 'set', field: 'category', value: ruleCategoryId }],
- });
-
- await addTransactions(acctId, [
- {
- date: '2017-10-21',
- payee_name: 'P',
- amount: -2947,
- category: explicitCategoryId,
- },
- ]);
-
- const [addedTransaction] = await getAllTransactions();
- expect(addedTransaction.category).toBe(explicitCategoryId);
- expect(addedTransaction.category).not.toBe(ruleCategoryId);
- });
-
test("reconcile does not merge transactions with different 'imported_id' values", async () => {
const { id } = await prepareDatabase();
diff --git a/packages/loot-core/src/server/accounts/sync.ts b/packages/loot-core/src/server/accounts/sync.ts
index 2a1b54c66b..3f4d3a79ad 100644
--- a/packages/loot-core/src/server/accounts/sync.ts
+++ b/packages/loot-core/src/server/accounts/sync.ts
@@ -350,9 +350,6 @@ async function normalizeTransactions(
// Strip off the irregular properties
const { payee_name: originalPayeeName, subtransactions, ...rest } = trans;
trans = rest;
- const explicitFields = Object.entries(rest)
- .filter(([, value]) => value != null)
- .map(([field]) => field);
let payee_name = originalPayeeName;
if (payee_name) {
@@ -379,7 +376,6 @@ async function normalizeTransactions(
normalized.push({
payee_name,
- explicitFields,
subtransactions: subtransactions
? subtransactions.map(t => ({ ...t, account: acctId }))
: null,
@@ -880,28 +876,15 @@ export async function addTransactions(
const accounts: db.DbAccount[] = await db.getAccounts();
const accountsMap = new Map(accounts.map(account => [account.id, account]));
- for (const {
- trans: originalTrans,
- subtransactions,
- explicitFields,
- } of normalized) {
+ for (const { trans: originalTrans, subtransactions } of normalized) {
// Run the rules
const trans = await runRules(originalTrans, accountsMap);
- // Rules should enrich missing fields but not override explicit values provided by API clients.
- const transWithExplicitFields = { ...trans };
- for (const field of explicitFields) {
- transWithExplicitFields[field] = originalTrans[field];
- }
-
const finalTransaction = {
id: uuidv4(),
- ...transWithExplicitFields,
+ ...trans,
account: acctId,
- cleared:
- transWithExplicitFields.cleared != null
- ? transWithExplicitFields.cleared
- : true,
+ cleared: trans.cleared != null ? trans.cleared : true,
};
// Add split transactions if they are given
diff --git a/upcoming-release-notes/7185.md b/upcoming-release-notes/7185.md
deleted file mode 100644
index 906c40ea4b..0000000000
--- a/upcoming-release-notes/7185.md
+++ /dev/null
@@ -1,6 +0,0 @@
----
-category: Bugfixes
-authors: [api2062]
----
-
-Preserve explicitly provided transaction category when importing transactions with matching payee rules.