mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
hotfix: editing sales and expense transactions don't reflect GL entries
This commit is contained in:
@@ -320,20 +320,19 @@ export default class VendorCreditController extends BaseController {
|
||||
res: Response,
|
||||
next: NextFunction
|
||||
) => {
|
||||
const { id: billId } = req.params;
|
||||
const { id: vendorCreditId } = req.params;
|
||||
const { tenantId, user } = req;
|
||||
const vendorCreditEditDTO: IVendorCreditEditDTO = this.matchedBodyData(req);
|
||||
|
||||
try {
|
||||
await this.editVendorCreditService.editVendorCredit(
|
||||
tenantId,
|
||||
billId,
|
||||
vendorCreditEditDTO,
|
||||
user
|
||||
vendorCreditId,
|
||||
vendorCreditEditDTO
|
||||
);
|
||||
|
||||
return res.status(200).send({
|
||||
id: billId,
|
||||
id: vendorCreditId,
|
||||
message: 'The vendor credit has been edited successfully.',
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate the transactions by reference.
|
||||
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||
|
||||
// Invalidate items associated bills transactions.
|
||||
queryClient.invalidateQueries(t.ITEMS_ASSOCIATED_WITH_BILLS);
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate transactions by reference.
|
||||
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||
|
||||
// Invalidate mutate base currency abilities.
|
||||
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
|
||||
};
|
||||
|
||||
@@ -24,6 +24,9 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate transactions by reference.
|
||||
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||
|
||||
// Invalidate accounts.
|
||||
queryClient.invalidateQueries(t.ACCOUNTS);
|
||||
|
||||
@@ -24,6 +24,9 @@ const commonInvalidateQueries = (client) => {
|
||||
// Invalidate financial reports.
|
||||
client.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate transactions by reference.
|
||||
client.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||
|
||||
// Invalidate customers.
|
||||
client.invalidateQueries(t.CUSTOMERS);
|
||||
client.invalidateQueries(t.CUSTOMER);
|
||||
|
||||
@@ -21,6 +21,9 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate the transactions by reference.
|
||||
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||
|
||||
// Invalidate the cashflow transactions.
|
||||
queryClient.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
queryClient.invalidateQueries(t.CASHFLOW_ACCOUNT_TRANSACTIONS_INFINITY);
|
||||
|
||||
@@ -43,6 +43,9 @@ const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate financial reports.
|
||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||
|
||||
// Invalidate the transactions by reference.
|
||||
queryClient.invalidateQueries(t.TRANSACTIONS_BY_REFERENCE);
|
||||
|
||||
// Invalidate mutate base currency abilities.
|
||||
queryClient.invalidateQueries(t.ORGANIZATION_MUTATE_BASE_CURRENCY_ABILITIES);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user