From f7b53692f5df15d0811673854f17600bbc840274 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Tue, 22 Aug 2023 13:51:15 +0200 Subject: [PATCH] fix(server): Transaction type of credit note and vendor credit are not defined on account transactions --- packages/server/src/interfaces/Account.ts | 1 + .../server/src/models/AccountTransaction.ts | 38 ++----------------- .../server/src/models/InventoryTransaction.ts | 28 +++----------- .../Accounts/AccountTransactionTransformer.ts | 2 +- .../server/src/utils/transactions-types.ts | 5 +++ 5 files changed, 17 insertions(+), 57 deletions(-) create mode 100644 packages/server/src/utils/transactions-types.ts diff --git a/packages/server/src/interfaces/Account.ts b/packages/server/src/interfaces/Account.ts index de8a2332c..3d3ce47a7 100644 --- a/packages/server/src/interfaces/Account.ts +++ b/packages/server/src/interfaces/Account.ts @@ -58,6 +58,7 @@ export interface IAccountTransaction { date: string | Date; referenceType: string; + referenceTypeFormatted: string; referenceId: number; referenceNumber?: string; diff --git a/packages/server/src/models/AccountTransaction.ts b/packages/server/src/models/AccountTransaction.ts index 2aa70aa75..0c7a1ac56 100644 --- a/packages/server/src/models/AccountTransaction.ts +++ b/packages/server/src/models/AccountTransaction.ts @@ -2,8 +2,11 @@ import { Model, raw } from 'objection'; import moment from 'moment'; import { isEmpty, castArray } from 'lodash'; import TenantModel from 'models/TenantModel'; +import { getTransactionTypeLabel } from '@/utils/transactions-types'; export default class AccountTransaction extends TenantModel { + referenceType: string; + /** * Table name */ @@ -30,40 +33,7 @@ export default class AccountTransaction extends TenantModel { * @return {string} */ get referenceTypeFormatted() { - return AccountTransaction.getReferenceTypeFormatted(this.referenceType); - } - - /** - * Reference type formatted. - */ - static getReferenceTypeFormatted(referenceType) { - const mapped = { - SaleInvoice: 'Sale invoice', - SaleReceipt: 'Sale receipt', - PaymentReceive: 'Payment receive', - Bill: 'Bill', - BillPayment: 'Payment made', - VendorOpeningBalance: 'Vendor opening balance', - CustomerOpeningBalance: 'Customer opening balance', - InventoryAdjustment: 'Inventory adjustment', - ManualJournal: 'Manual journal', - Journal: 'Manual journal', - Expense: 'Expense', - OwnerContribution: 'Owner contribution', - TransferToAccount: 'Transfer to account', - TransferFromAccount: 'Transfer from account', - OtherIncome: 'Other income', - OtherExpense: 'Other expense', - OwnerDrawing: 'Owner drawing', - InvoiceWriteOff: 'Invoice write-off', - - CreditNote: 'transaction_type.credit_note', - VendorCredit: 'transaction_type.vendor_credit', - - RefundCreditNote: 'transaction_type.refund_credit_note', - RefundVendorCredit: 'transaction_type.refund_vendor_credit', - }; - return mapped[referenceType] || ''; + return getTransactionTypeLabel(this.referenceType); } /** diff --git a/packages/server/src/models/InventoryTransaction.ts b/packages/server/src/models/InventoryTransaction.ts index 16db33993..372cd7ca4 100644 --- a/packages/server/src/models/InventoryTransaction.ts +++ b/packages/server/src/models/InventoryTransaction.ts @@ -1,9 +1,13 @@ import { Model, raw } from 'objection'; -import { castArray, isEmpty } from 'lodash'; +import { castArray } from 'lodash'; import moment from 'moment'; import TenantModel from 'models/TenantModel'; +import { getTransactionTypeLabel } from '@/utils/transactions-types'; export default class InventoryTransaction extends TenantModel { + transactionId: number; + transactionType: string; + /** * Table name */ @@ -23,27 +27,7 @@ export default class InventoryTransaction extends TenantModel { * @return {string} */ get transcationTypeFormatted() { - return InventoryTransaction.getReferenceTypeFormatted(this.transactionType); - } - - /** - * Reference type formatted. - */ - static getReferenceTypeFormatted(referenceType) { - const mapped = { - SaleInvoice: 'Sale invoice', - SaleReceipt: 'Sale receipt', - PaymentReceive: 'Payment receive', - Bill: 'Bill', - BillPayment: 'Payment made', - VendorOpeningBalance: 'Vendor opening balance', - CustomerOpeningBalance: 'Customer opening balance', - InventoryAdjustment: 'Inventory adjustment', - ManualJournal: 'Manual journal', - Journal: 'Manual journal', - LandedCost: 'transaction_type.landed_cost', - }; - return mapped[referenceType] || ''; + return getTransactionTypeLabel(this.transactionType); } /** diff --git a/packages/server/src/services/Accounts/AccountTransactionTransformer.ts b/packages/server/src/services/Accounts/AccountTransactionTransformer.ts index e239b4da9..857fe5ccc 100644 --- a/packages/server/src/services/Accounts/AccountTransactionTransformer.ts +++ b/packages/server/src/services/Accounts/AccountTransactionTransformer.ts @@ -46,7 +46,7 @@ export default class AccountTransactionTransformer extends Transformer { * @returns {string} */ public transactionTypeFormatted(transaction: IAccountTransaction) { - return transaction.referenceTypeFormatted; + return this.context.i18n.__(transaction.referenceTypeFormatted); } /** diff --git a/packages/server/src/utils/transactions-types.ts b/packages/server/src/utils/transactions-types.ts new file mode 100644 index 000000000..ab5981115 --- /dev/null +++ b/packages/server/src/utils/transactions-types.ts @@ -0,0 +1,5 @@ +import { TransactionTypes } from '@/data/TransactionTypes'; + +export const getTransactionTypeLabel = (transactionType: string) => { + return TransactionTypes[transactionType]; +};