fix: delete inventory adjustment gl entries

This commit is contained in:
Ahmed Bouhuolia
2025-06-15 17:51:44 +02:00
parent bbf9ef9bc2
commit 88ef60ef28
8 changed files with 86 additions and 48 deletions

View File

@@ -39,6 +39,7 @@
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/schedule": "^4.1.2",
"@nestjs/serve-static": "^5.0.3",
"@nestjs/swagger": "^7.4.2",
"@nestjs/throttler": "^6.2.1",
"@supercharge/promise-pool": "^3.2.0",

View File

@@ -46,7 +46,7 @@ export class DeleteInventoryAdjustmentService {
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Triggers `onInventoryAdjustmentDeleting` event.
await this.eventEmitter.emitAsync(events.inventoryAdjustment.onDeleting, {
oldInventoryAdjustment,
inventoryAdjustment: oldInventoryAdjustment,
trx,
} as IInventoryAdjustmentDeletingPayload);

View File

@@ -31,7 +31,7 @@ export class InventoryAdjustmentsGLEntries {
const adjustment = await this.inventoryAdjustment()
.query(trx)
.findById(inventoryAdjustmentId)
.withGraphFetched('entries.item');
.withGraphFetched('entries.item.inventoryAccount');
const tenantMeta = await this.tenancyContext.getTenantMetadata();

View File

@@ -1,7 +1,10 @@
import { Injectable } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { InventoryAdjustmentsGLEntries } from '../commands/ledger/InventoryAdjustmentsGLEntries';
import { IInventoryAdjustmentEventDeletedPayload } from '../types/InventoryAdjustments.types';
import {
IInventoryAdjustmentDeletingPayload,
IInventoryAdjustmentEventPublishedPayload,
} from '../types/InventoryAdjustments.types';
import { IInventoryAdjustmentEventCreatedPayload } from '../types/InventoryAdjustments.types';
import { events } from '@/common/events/events';
@@ -13,10 +16,11 @@ export class InventoryAdjustmentsGLSubscriber {
/**
* Handles writing increment inventory adjustment GL entries.
* @param {IInventoryAdjustmentEventCreatedPayload} payload -
*/
@OnEvent(events.inventoryAdjustment.onQuickCreated)
@OnEvent(events.inventoryAdjustment.onPublished)
public async handleGLEntriesOnceIncrementAdjustmentCreated({
async handleGLEntriesOnceIncrementAdjustmentCreated({
inventoryAdjustmentId,
inventoryAdjustment,
trx,
@@ -37,19 +41,20 @@ export class InventoryAdjustmentsGLSubscriber {
/**
* Reverts the inventory adjustment GL entries once the transaction deleted.
* @param {IInventoryAdjustmentEventDeletedPayload} payload -
* @param {IInventoryAdjustmentDeletingPayload} payload -
*/
@OnEvent(events.inventoryAdjustment.onDeleted)
public async revertAdjustmentGLEntriesOnceDeleted({
inventoryAdjustmentId,
oldInventoryAdjustment,
}: IInventoryAdjustmentEventDeletedPayload) {
@OnEvent(events.inventoryAdjustment.onDeleting)
async revertAdjustmentGLEntriesOnceDeleted({
inventoryAdjustment,
trx,
}: IInventoryAdjustmentDeletingPayload) {
// Can't continue if the inventory adjustment is not published.
if (!oldInventoryAdjustment.isPublished) {
if (!inventoryAdjustment.isPublished) {
return;
}
await this.inventoryAdjustmentGL.revertAdjustmentGLEntries(
inventoryAdjustmentId,
inventoryAdjustment.id,
trx,
);
}
@@ -58,39 +63,16 @@ export class InventoryAdjustmentsGLSubscriber {
* @param {IInventoryAdjustmentEventPublishedPayload} payload
* @param {IInventoryAdjustmentEventCreatedPayload} payload -
*/
// private handleWriteInventoryTransactionsOncePublished = async ({
// inventoryAdjustment,
// trx,
// }:
// | IInventoryAdjustmentEventPublishedPayload
// | IInventoryAdjustmentEventCreatedPayload) => {
// await this.inventoryAdjustment.writeInventoryTransactions(
// tenantId,
// inventoryAdjustment,
// false,
// trx
// );
// };
/**
* Handles reverting invetory transactions once the inventory adjustment deleted.
* @param {IInventoryAdjustmentEventDeletedPayload} payload -
*/
// private handleRevertInventoryTransactionsOnceDeleted = async ({
// tenantId,
// inventoryAdjustmentId,
// oldInventoryAdjustment,
// trx,
// }: IInventoryAdjustmentEventDeletedPayload) => {
// // Can't continue if the inventory adjustment is not published.
// if (!oldInventoryAdjustment.isPublished) {
// return;
// }
// // Reverts the inventory transactions of adjustment transaction.
// await this.inventoryAdjustment.revertInventoryTransactions(
// tenantId,
// inventoryAdjustmentId,
// trx
// );
// };
@OnEvent(events.inventoryAdjustment.onPublished)
async handleWriteInventoryTransactionsOncePublished({
inventoryAdjustmentId,
trx,
}:
| IInventoryAdjustmentEventPublishedPayload
| IInventoryAdjustmentEventCreatedPayload) {
await this.inventoryAdjustmentGL.writeAdjustmentGLEntries(
inventoryAdjustmentId,
trx,
);
}
}

View File

@@ -51,7 +51,7 @@ export interface IInventoryAdjustmentEventDeletedPayload {
}
export interface IInventoryAdjustmentDeletingPayload {
oldInventoryAdjustment: InventoryAdjustment;
inventoryAdjustment: InventoryAdjustment;
trx: Knex.Transaction;
}

View File

@@ -0,0 +1,26 @@
block head
style
include ./financial-sheet.css
style.
!{customCSS}
block content
.sheet
.sheet__header
.sheet__company-name=organizationName
.sheet__sheet-type=sheetName
.sheet__sheet-date=sheetDate
table.sheet__table
thead
tr
each column in table.columns
th(style=column.style class='column--' + column.key)= column.label
tbody
each row in table.rows
tr(class=row.classNames)
each cell in row.cells
td(class='cell--' + cell.key)
span!= cell.value

29
pnpm-lock.yaml generated
View File

@@ -96,6 +96,9 @@ importers:
'@nestjs/schedule':
specifier: ^4.1.2
version: 4.1.2(@nestjs/common@10.4.7)(@nestjs/core@10.4.7)
'@nestjs/serve-static':
specifier: ^5.0.3
version: 5.0.3(@nestjs/common@10.4.7)(@nestjs/core@10.4.7)
'@nestjs/swagger':
specifier: ^7.4.2
version: 7.4.2(@nestjs/common@10.4.7)(@nestjs/core@10.4.7)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)
@@ -7114,6 +7117,27 @@ packages:
- chokidar
dev: true
/@nestjs/serve-static@5.0.3(@nestjs/common@10.4.7)(@nestjs/core@10.4.7):
resolution: {integrity: sha512-0jFjTlSVSLrI+mot8lfm+h2laXtKzCvgsVStv9T1ZBZTDwS26gM5czIhIESmWAod0PfrbCDFiu9C1MglObL8VA==}
peerDependencies:
'@fastify/static': ^8.0.4
'@nestjs/common': ^11.0.2
'@nestjs/core': ^11.0.2
express: ^5.0.1
fastify: ^5.2.1
peerDependenciesMeta:
'@fastify/static':
optional: true
express:
optional: true
fastify:
optional: true
dependencies:
'@nestjs/common': 10.4.7(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2)(rxjs@7.8.1)
'@nestjs/core': 10.4.7(@nestjs/common@10.4.7)(@nestjs/platform-express@10.4.7)(reflect-metadata@0.2.2)(rxjs@7.8.1)
path-to-regexp: 8.2.0
dev: false
/@nestjs/swagger@7.4.2(@nestjs/common@10.4.7)(@nestjs/core@10.4.7)(class-transformer@0.5.1)(class-validator@0.14.1)(reflect-metadata@0.2.2):
resolution: {integrity: sha512-Mu6TEn1M/owIvAx2B4DUQObQXqo2028R2s9rSZ/hJEgBK95+doTwS0DjmVA2wTeZTyVtXOoN7CsoM5pONBzvKQ==}
peerDependencies:
@@ -23424,6 +23448,11 @@ packages:
/path-to-regexp@3.3.0:
resolution: {integrity: sha512-qyCH421YQPS2WFDxDjftfc1ZR5WKQzVzqsp4n9M2kQhVOo/ByahFoUNJfl58kOcEGfQ//7weFTDhm+ss8Ecxgw==}
/path-to-regexp@8.2.0:
resolution: {integrity: sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ==}
engines: {node: '>=16'}
dev: false
/path-type@3.0.0:
resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==}
engines: {node: '>=4'}