hotfix: editing sales and expense transactions don't reflect GL entries

This commit is contained in:
Ahmed Bouhuolia
2024-01-29 23:25:37 +02:00
parent 0414c090ea
commit ba387e81f7
13 changed files with 34 additions and 13 deletions

View File

@@ -80,7 +80,7 @@ export default class EditCreditNote extends BaseCreditNotes {
} as ICreditNoteEditingPayload);
// Saves the credit note graph to the storage.
const creditNote = await CreditNote.query(trx).upsertGraph({
const creditNote = await CreditNote.query(trx).upsertGraphAndFetch({
id: creditNoteId,
...creditNoteModel,
});

View File

@@ -136,7 +136,7 @@ export class EditExpense {
} as IExpenseEventEditingPayload);
// Upsert the expense object with expense entries.
const expense: IExpense = await Expense.query(trx).upsertGraph({
const expense: IExpense = await Expense.query(trx).upsertGraphAndFetch({
id: expenseId,
...expenseObj,
});

View File

@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import { Service, Inject } from 'typedi';
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Service, Inject } from 'typedi';
import { ExpenseGLEntries } from './ExpenseGLEntries';
@Service()

View File

@@ -70,10 +70,10 @@ export class ExpensesWriteGLSubscriber {
authorizedUser,
trx,
}: IExpenseEventEditPayload) => {
// In case expense published, write journal entries.
if (expense.publishedAt) return;
// Cannot continue if the expense is not published.
if (!expense.publishedAt) return;
await this.expenseGLEntries.writeExpenseGLEntries(
await this.expenseGLEntries.rewriteExpenseGLEntries(
tenantId,
expense.id,
trx

View File

@@ -9,6 +9,7 @@ import UnitOfWork from '@/services/UnitOfWork';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
import events from '@/subscribers/events';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service()
export default class EditVendorCredit extends BaseVendorCredit {
@@ -21,6 +22,9 @@ export default class EditVendorCredit extends BaseVendorCredit {
@Inject()
private itemsEntriesService: ItemsEntriesService;
@Inject()
private tenancy: HasTenancyService;
/**
* Deletes the given vendor credit.
* @param {number} tenantId - Tenant id.
@@ -31,7 +35,7 @@ export default class EditVendorCredit extends BaseVendorCredit {
vendorCreditId: number,
vendorCreditDTO: IVendorCreditEditDTO
) => {
const { VendorCredit } = this.tenancy.models(tenantId);
const { VendorCredit, Contact } = this.tenancy.models(tenantId);
// Retrieve the vendor credit or throw not found service error.
const oldVendorCredit = await this.getVendorCreditOrThrowError(

View File

@@ -32,7 +32,7 @@ export class SaleReceiptGLEntries {
): Promise<void> => {
const { SaleReceipt } = this.tenancy.models(tenantId);
const saleReceipt = await SaleReceipt.query()
const saleReceipt = await SaleReceipt.query(trx)
.findById(saleReceiptId)
.withGraphFetched('entries.item');