From a9a7cd8617f5756dd9cc352e198209cd8c1c7549 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Mon, 22 Dec 2025 22:49:58 +0200 Subject: [PATCH] fix: import bank transactions --- .../UncategorizedTransactionsImportable.ts | 6 +- .../BankingTransactions.module.ts | 2 +- .../UncategorizedBankTransaction.meta.ts | 72 +++++++++++++++++++ .../models/UncategorizedBankTransaction.ts | 3 + .../src/modules/Import/ImportFileCommon.ts | 2 +- .../src/modules/Import/ImportFileUpload.ts | 2 +- packages/webapp/src/constants/tables.tsx | 2 +- .../AccountTransactionsUncategorizedTable.tsx | 2 +- .../ImportUncategorizedTransactionsPage.tsx | 2 +- packages/webapp/src/hooks/query/import.ts | 2 +- 10 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.meta.ts diff --git a/packages/server/src/modules/BankingCategorize/commands/UncategorizedTransactionsImportable.ts b/packages/server/src/modules/BankingCategorize/commands/UncategorizedTransactionsImportable.ts index 0694dfe78..af4d85bd5 100644 --- a/packages/server/src/modules/BankingCategorize/commands/UncategorizedTransactionsImportable.ts +++ b/packages/server/src/modules/BankingCategorize/commands/UncategorizedTransactionsImportable.ts @@ -1,7 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Knex } from 'knex'; import * as yup from 'yup'; -import uniqid from 'uniqid'; +import * as uniqid from 'uniqid'; import { Importable } from '../../Import/Importable'; import { CreateUncategorizedTransactionService } from './CreateUncategorizedTransaction.service'; import { ImportableContext } from '../../Import/interfaces'; @@ -9,8 +9,10 @@ import { BankTransactionsSampleData } from '../../BankingTransactions/constants' import { Account } from '@/modules/Accounts/models/Account.model'; import { CreateUncategorizedTransactionDTO } from '../types/BankingCategorize.types'; import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel'; - +import { ImportableService } from '../../Import/decorators/Import.decorator'; +import { UncategorizedBankTransaction } from '../../BankingTransactions/models/UncategorizedBankTransaction'; @Injectable() +@ImportableService({ name: UncategorizedBankTransaction.name }) export class UncategorizedTransactionsImportable extends Importable { constructor( private readonly createUncategorizedTransaction: CreateUncategorizedTransactionService, diff --git a/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts b/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts index ee2969786..17521edff 100644 --- a/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts +++ b/packages/server/src/modules/BankingTransactions/BankingTransactions.module.ts @@ -83,4 +83,4 @@ const models = [ CreateBankTransactionService ], }) -export class BankingTransactionsModule {} +export class BankingTransactionsModule { } diff --git a/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.meta.ts b/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.meta.ts new file mode 100644 index 000000000..35e712c4b --- /dev/null +++ b/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.meta.ts @@ -0,0 +1,72 @@ +export const UncategorizedBankTransactionMeta = { + defaultFilterField: 'createdAt', + defaultSort: { + sortOrder: 'DESC', + sortField: 'created_at', + }, + importable: true, + fields: { + date: { + name: 'Date', + column: 'date', + fieldType: 'date', + }, + payee: { + name: 'Payee', + column: 'payee', + fieldType: 'text', + }, + description: { + name: 'Description', + column: 'description', + fieldType: 'text', + }, + referenceNo: { + name: 'Reference No.', + column: 'reference_no', + fieldType: 'text', + }, + amount: { + name: 'Amount', + column: 'Amount', + fieldType: 'numeric', + required: true, + }, + account: { + name: 'Account', + column: 'account_id', + fieldType: 'relation', + to: { model: 'Account', to: 'id' }, + }, + createdAt: { + name: 'Created At', + column: 'createdAt', + fieldType: 'date', + importable: false, + }, + }, + fields2: { + date: { + name: 'Date', + fieldType: 'date', + required: true, + }, + payee: { + name: 'Payee', + fieldType: 'text', + }, + description: { + name: 'Description', + fieldType: 'text', + }, + referenceNo: { + name: 'Reference No.', + fieldType: 'text', + }, + amount: { + name: 'Amount', + fieldType: 'number', + required: true, + }, + }, +}; \ No newline at end of file diff --git a/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.ts b/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.ts index 97f428a10..daee38503 100644 --- a/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.ts +++ b/packages/server/src/modules/BankingTransactions/models/UncategorizedBankTransaction.ts @@ -2,7 +2,10 @@ import * as moment from 'moment'; import { Model } from 'objection'; import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel'; +import { UncategorizedBankTransactionMeta } from './UncategorizedBankTransaction.meta'; +import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator'; +@InjectModelMeta(UncategorizedBankTransactionMeta) export class UncategorizedBankTransaction extends TenantBaseModel { readonly amount!: number; readonly date!: Date | string; diff --git a/packages/server/src/modules/Import/ImportFileCommon.ts b/packages/server/src/modules/Import/ImportFileCommon.ts index 345bfbb85..aa5aef661 100644 --- a/packages/server/src/modules/Import/ImportFileCommon.ts +++ b/packages/server/src/modules/Import/ImportFileCommon.ts @@ -22,7 +22,7 @@ export class ImportFileCommon { private readonly importFileValidator: ImportFileDataValidator, private readonly resource: ResourceService, private readonly importableRegistry: ImportableRegistry, - ) {} + ) { } /** * Imports the given parsed data to the resource storage through registered importable service. diff --git a/packages/server/src/modules/Import/ImportFileUpload.ts b/packages/server/src/modules/Import/ImportFileUpload.ts index 6392ffd33..c8c309282 100644 --- a/packages/server/src/modules/Import/ImportFileUpload.ts +++ b/packages/server/src/modules/Import/ImportFileUpload.ts @@ -84,7 +84,7 @@ export class ImportFileUploadService { } catch (error) { throw error; } - const _params = this.importFileCommon.transformParams(resource, params); + const _params = await this.importFileCommon.transformParams(resource, params); const paramsStringified = JSON.stringify(_params); const tenant = await this.tenancyContext.getTenant(); diff --git a/packages/webapp/src/constants/tables.tsx b/packages/webapp/src/constants/tables.tsx index c66849665..049dcdd6f 100644 --- a/packages/webapp/src/constants/tables.tsx +++ b/packages/webapp/src/constants/tables.tsx @@ -15,7 +15,7 @@ export const TABLES = { EXPENSES: 'expenses', CASHFLOW_ACCOUNTS: 'cashflow_accounts', CASHFLOW_Transactions: 'cashflow_transactions', - UNCATEGORIZED_CASHFLOW_TRANSACTION: 'UNCATEGORIZED_CASHFLOW_TRANSACTION', + UNCATEGORIZED_BANK_TRANSACTION: 'UNCATEGORIZED_BANK_TRANSACTION', CREDIT_NOTES: 'credit_notes', VENDOR_CREDITS: 'vendor_credits', WAREHOUSE_TRANSFERS: 'warehouse_transfers', diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/UncategorizedTransactions/AccountTransactionsUncategorizedTable.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/UncategorizedTransactions/AccountTransactionsUncategorizedTable.tsx index 336c689d9..8abc098b5 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/UncategorizedTransactions/AccountTransactionsUncategorizedTable.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/UncategorizedTransactions/AccountTransactionsUncategorizedTable.tsx @@ -60,7 +60,7 @@ function AccountTransactionsDataTable({ // Local storage memorizing columns widths. const [initialColumnsWidths, , handleColumnResizing] = - useMemorizedColumnsWidths(TABLES.UNCATEGORIZED_CASHFLOW_TRANSACTION); + useMemorizedColumnsWidths(TABLES.UNCATEGORIZED_BANK_TRANSACTION); // Handle cell click. const handleCellClick = (cell) => { diff --git a/packages/webapp/src/containers/CashFlow/ImportIUncategorizedTransactions/ImportUncategorizedTransactionsPage.tsx b/packages/webapp/src/containers/CashFlow/ImportIUncategorizedTransactions/ImportUncategorizedTransactionsPage.tsx index 81c042802..02c4acf66 100644 --- a/packages/webapp/src/containers/CashFlow/ImportIUncategorizedTransactions/ImportUncategorizedTransactionsPage.tsx +++ b/packages/webapp/src/containers/CashFlow/ImportIUncategorizedTransactions/ImportUncategorizedTransactionsPage.tsx @@ -21,7 +21,7 @@ export default function ImportUncategorizedTransactions() { return (