Skip to content

Commit 2e97209

Browse files
authored
fix: do not match archived accounts (#1131)
1 parent 3bb89b0 commit 2e97209

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

internal/controllers/v4/import.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ func ImportYnabImportPreview(c *gin.Context) {
289289
return
290290
}
291291

292-
// Get all match rules for the budget that the import target account is part of
292+
// Get all match rules for the budget for which the account is not archived
293293
var matchRules []models.MatchRule
294294
err = models.DB.
295-
Joins("JOIN accounts ON accounts.budget_id = ?", account.BudgetID).
295+
Joins("JOIN accounts ON accounts.budget_id = ? AND NOT accounts.archived", account.BudgetID).
296296
Joins("JOIN match_rules rr ON rr.account_id = accounts.id").
297297
Order("rr.priority asc").
298298
Find(&matchRules).Error

internal/controllers/v4/import_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,26 @@ func (suite *TestSuiteStandard) TestImportYnabImportPreviewFindAccounts() {
293293
}
294294
}
295295

296+
// TestImportMatchingNoArchivedAccounts verifies that during an import, match rules for archived accounts
297+
// are not used
298+
func (suite *TestSuiteStandard) TestImportMatchingNoArchivedAccounts() {
299+
// Create a budget and two existing accounts to use
300+
budget := createTestBudget(suite.T(), v4.BudgetEditable{})
301+
302+
// Account we import to
303+
internalAccount := createTestAccount(suite.T(), v4.AccountEditable{BudgetID: budget.Data.ID, Name: "Envelope Zero Account"})
304+
305+
edeka := createTestAccount(suite.T(), v4.AccountEditable{BudgetID: budget.Data.ID, Name: "Edeka", External: true, Archived: true})
306+
_ = createTestMatchRule(suite.T(), v4.MatchRuleEditable{
307+
Match: "Supermarket*",
308+
AccountID: edeka.Data.ID,
309+
})
310+
311+
preview := suite.parseCSV(suite.T(), internalAccount.Data.ID, "match-rule-archived-account.csv")
312+
313+
assert.Equal(suite.T(), uuid.Nil, preview.Data[0].Transaction.DestinationAccountID)
314+
}
315+
296316
func (suite *TestSuiteStandard) TestImportYnabImportPreviewMatch() {
297317
// Create a budget and two existing accounts to use
298318
budget := createTestBudget(suite.T(), v4.BudgetEditable{})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Date,Payee,Memo,Outflow,Inflow
2+
04/01/2019,Supermarket,,59.97,

0 commit comments

Comments
 (0)