Skip to content

Commit e5dedee

Browse files
refactor(OUT-3617): remove undepositedFundsAccountRef column and caching
Undeposited Funds is a QBO system account that always exists and cannot be deleted. Caching its ID in qb_portal_connections was unnecessary. - Add getUndepositedFundsAccountId() on IntuitAPI (live lookup by subtype) - Call it directly in invoice.service.ts instead of checkAndUpdateAccountStatus - Remove undepositedFundsAccountRef from schema, type, and all plumbing - Remove UndepositedFunds from AccountTypeObj, updateAccountMapping, restoreAccountRef - Reuse single IntuitAPI instance in webhookInvoicePaid - Update migration: drop undeposited_funds_account_ref column addition Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 01c0dd8 commit e5dedee

14 files changed

Lines changed: 33 additions & 67 deletions

src/action/quickbooks.action.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export async function checkForNonUsCompany(portalId: string) {
6565
assetAccountRef: portalConnection.assetAccountRef,
6666
serviceItemRef: portalConnection.serviceItemRef,
6767
clientFeeRef: portalConnection.clientFeeRef,
68-
undepositedFundsAccountRef: portalConnection.undepositedFundsAccountRef,
6968
bankAccountRef: portalConnection.bankAccountRef,
7069
}
7170

src/app/api/quickbooks/auth/auth.service.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ export class AuthService extends BaseService {
139139
assetAccountRef: insertPayload.assetAccountRef,
140140
serviceItemRef: existingToken?.serviceItemRef || null,
141141
clientFeeRef: existingToken?.clientFeeRef || null,
142-
undepositedFundsAccountRef:
143-
existingToken?.undepositedFundsAccountRef || null,
144142
bankAccountRef: existingToken?.bankAccountRef || null,
145143
})
146144
// handle accounts
@@ -241,7 +239,6 @@ export class AuthService extends BaseService {
241239
setting,
242240
serviceItemRef,
243241
clientFeeRef,
244-
undepositedFundsAccountRef,
245242
bankAccountRef,
246243
isSuspended,
247244
} = portalQBToken
@@ -265,7 +262,6 @@ export class AuthService extends BaseService {
265262
assetAccountRef: '',
266263
serviceItemRef: '',
267264
clientFeeRef: '',
268-
undepositedFundsAccountRef: null,
269265
bankAccountRef: null,
270266
}
271267

@@ -288,7 +284,6 @@ export class AuthService extends BaseService {
288284
assetAccountRef,
289285
serviceItemRef,
290286
clientFeeRef,
291-
undepositedFundsAccountRef,
292287
bankAccountRef,
293288
}
294289

src/app/api/quickbooks/invoice/invoice.service.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -900,16 +900,11 @@ export class InvoiceService extends BaseService {
900900
setting?.bankDepositFeeFlag &&
901901
isPortalInBankDepositABTest(this.user.workspaceId)
902902

903+
const intuitApi = new IntuitAPI(qbTokenInfo)
904+
903905
let depositToAccountRef: { value: string } | undefined
904906
if (useBankDepositFlow) {
905-
const tokenService = new TokenService(this.user)
906-
const undepositedFundsRef =
907-
await tokenService.checkAndUpdateAccountStatus(
908-
AccountTypeObj.UndepositedFunds,
909-
qbTokenInfo.intuitRealmId,
910-
new IntuitAPI(qbTokenInfo),
911-
qbTokenInfo.undepositedFundsAccountRef ?? undefined,
912-
)
907+
const undepositedFundsRef = await intuitApi.getUndepositedFundsAccountId()
913908
depositToAccountRef = { value: undepositedFundsRef }
914909
}
915910

@@ -933,7 +928,6 @@ export class InvoiceService extends BaseService {
933928
},
934929
],
935930
}
936-
const intuitApi = new IntuitAPI(qbTokenInfo)
937931
const paymentService = new PaymentService(this.user)
938932

939933
const customerDisplayName =

src/app/api/quickbooks/token/token.service.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ export class TokenService extends BaseService {
156156
case AccountTypeObj.Asset:
157157
payload = { assetAccountRef: accountRef }
158158
break
159-
case AccountTypeObj.UndepositedFunds:
160-
payload = { undepositedFundsAccountRef: accountRef }
161-
break
162159
default:
163160
throw new APIError(
164161
httpStatus.BAD_REQUEST,
@@ -269,29 +266,6 @@ export class TokenService extends BaseService {
269266
return assetAccRef.Id
270267
}
271268

272-
private async getUndepositedFundsAccRef(
273-
intuitApi: IntuitAPI,
274-
): Promise<string> {
275-
// QBO enforces exactly one UndepositedFunds account per company — cannot create a second.
276-
// Look up by subtype first (most reliable, works even if user renamed the account).
277-
const query = `SELECT Id FROM Account WHERE AccountSubType = 'UndepositedFunds' AND Active = true maxresults 1`
278-
const result = await intuitApi.customQuery(query)
279-
if (result?.Account?.[0]?.Id) {
280-
return result.Account[0].Id
281-
}
282-
283-
// Fallback: try by default name
284-
const byName = await intuitApi.getAnAccount('Undeposited Funds')
285-
if (byName?.Id) {
286-
return byName.Id
287-
}
288-
289-
throw new APIError(
290-
httpStatus.INTERNAL_SERVER_ERROR,
291-
'TokenService#getUndepositedFundsAccRef | Undeposited Funds account not found in QuickBooks',
292-
)
293-
}
294-
295269
private async restoreAccountRef(
296270
accountType: AccountType,
297271
intuitApi: IntuitAPI,
@@ -303,8 +277,6 @@ export class TokenService extends BaseService {
303277
return this.getOrCreateExpenseAccountRef(intuitApi)
304278
case AccountTypeObj.Asset:
305279
return this.getOrCreateAssetAccountRef(intuitApi)
306-
case AccountTypeObj.UndepositedFunds:
307-
return this.getUndepositedFundsAccRef(intuitApi)
308280
default:
309281
throw new APIError(
310282
httpStatus.BAD_REQUEST,

src/cmd/renameQbAccount/renameQbAccount.service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ export class RenameQbAccountService extends BaseService {
161161
assetAccountRef: portal.assetAccountRef,
162162
serviceItemRef: portal.serviceItemRef,
163163
clientFeeRef: portal.clientFeeRef,
164-
undepositedFundsAccountRef: portal.undepositedFundsAccountRef,
165164
bankAccountRef: portal.bankAccountRef,
166165
}
167166
}

src/constant/qbConnection.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ export const AccountTypeObj = {
22
Income: 'income',
33
Expense: 'expense',
44
Asset: 'asset',
5-
UndepositedFunds: 'undepositedFunds',
65
} as const

src/db/migrations/20260417071636_add_bank_deposite_fee_column.sql

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE "qb_portal_connections" ADD COLUMN "bank_account_ref" varchar(100);--> statement-breakpoint
2+
ALTER TABLE "qb_settings" ADD COLUMN "bank_deposit_fee_flag" boolean DEFAULT false NOT NULL;

src/db/migrations/meta/20260417071636_snapshot.json renamed to src/db/migrations/meta/20260420090412_snapshot.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "dbeaa706-8b28-4714-9dca-aab6516ff0d5",
2+
"id": "9eb854f3-0544-46b9-8b4f-6ad7457aaac9",
33
"prevId": "1c9fbc27-72b3-4a6e-860c-6e3f247135d5",
44
"version": "7",
55
"dialect": "postgresql",
@@ -468,12 +468,6 @@
468468
"primaryKey": false,
469469
"notNull": false
470470
},
471-
"undeposited_funds_account_ref": {
472-
"name": "undeposited_funds_account_ref",
473-
"type": "varchar(100)",
474-
"primaryKey": false,
475-
"notNull": false
476-
},
477471
"bank_account_ref": {
478472
"name": "bank_account_ref",
479473
"type": "varchar(100)",
@@ -966,8 +960,7 @@
966960
"deleted",
967961
"succeeded",
968962
"mapped",
969-
"unmapped",
970-
"deposited"
963+
"unmapped"
971964
]
972965
},
973966
"public.failed_record_category_types": {

src/db/migrations/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
{
118118
"idx": 16,
119119
"version": "7",
120-
"when": 1776410196223,
121-
"tag": "20260417071636_add_bank_deposite_fee_column",
120+
"when": 1776675852536,
121+
"tag": "20260420090412_add_bank_deposit_fee_column",
122122
"breakpoints": true
123123
}
124124
]

0 commit comments

Comments
 (0)