Merge pull request #225 from bigcapitalhq/abouhuolia/big-59-transaction-type-of-credit-note-and-vendor-credit-are-not

fix(server): Transaction type of credit note and vendor credit are not defined on account transactions
This commit is contained in:
Ahmed Bouhuolia
2023-08-22 13:54:08 +02:00
committed by GitHub
5 changed files with 17 additions and 57 deletions

View File

@@ -58,6 +58,7 @@ export interface IAccountTransaction {
date: string | Date; date: string | Date;
referenceType: string; referenceType: string;
referenceTypeFormatted: string;
referenceId: number; referenceId: number;
referenceNumber?: string; referenceNumber?: string;

View File

@@ -2,8 +2,11 @@ import { Model, raw } from 'objection';
import moment from 'moment'; import moment from 'moment';
import { isEmpty, castArray } from 'lodash'; import { isEmpty, castArray } from 'lodash';
import TenantModel from 'models/TenantModel'; import TenantModel from 'models/TenantModel';
import { getTransactionTypeLabel } from '@/utils/transactions-types';
export default class AccountTransaction extends TenantModel { export default class AccountTransaction extends TenantModel {
referenceType: string;
/** /**
* Table name * Table name
*/ */
@@ -30,40 +33,7 @@ export default class AccountTransaction extends TenantModel {
* @return {string} * @return {string}
*/ */
get referenceTypeFormatted() { get referenceTypeFormatted() {
return AccountTransaction.getReferenceTypeFormatted(this.referenceType); return getTransactionTypeLabel(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] || '';
} }
/** /**

View File

@@ -1,9 +1,13 @@
import { Model, raw } from 'objection'; import { Model, raw } from 'objection';
import { castArray, isEmpty } from 'lodash'; import { castArray } from 'lodash';
import moment from 'moment'; import moment from 'moment';
import TenantModel from 'models/TenantModel'; import TenantModel from 'models/TenantModel';
import { getTransactionTypeLabel } from '@/utils/transactions-types';
export default class InventoryTransaction extends TenantModel { export default class InventoryTransaction extends TenantModel {
transactionId: number;
transactionType: string;
/** /**
* Table name * Table name
*/ */
@@ -23,27 +27,7 @@ export default class InventoryTransaction extends TenantModel {
* @return {string} * @return {string}
*/ */
get transcationTypeFormatted() { get transcationTypeFormatted() {
return InventoryTransaction.getReferenceTypeFormatted(this.transactionType); return getTransactionTypeLabel(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] || '';
} }
/** /**

View File

@@ -46,7 +46,7 @@ export default class AccountTransactionTransformer extends Transformer {
* @returns {string} * @returns {string}
*/ */
public transactionTypeFormatted(transaction: IAccountTransaction) { public transactionTypeFormatted(transaction: IAccountTransaction) {
return transaction.referenceTypeFormatted; return this.context.i18n.__(transaction.referenceTypeFormatted);
} }
/** /**

View File

@@ -0,0 +1,5 @@
import { TransactionTypes } from '@/data/TransactionTypes';
export const getTransactionTypeLabel = (transactionType: string) => {
return TransactionTypes[transactionType];
};